using Microsoft.VisualStudio.TestTools.UnitTesting; using Neo.LegitimateLicences.Data.Models; using System; using System.Data; using System.Data.SqlClient; using System.IO; using System.Text; using System.Xml; namespace Neo.LegitimateLicences.Api.Test { [TestClass] public class GetVerifiedLicenceToUseXmlTest { [TestMethod] public void GetVerifiedLicenceToUseXml() { var olNumber = "TODO3202000001/1"; var db = new LegitimateDatabase(); XmlDocument xmlDoc = new XmlDocument(); XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement); XmlElement rootNode = xmlDoc.CreateElement("response"); bool found = false; olNumber = !String.IsNullOrEmpty(olNumber) ? olNumber : ""; using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) { using (SqlCommand command = connection.CreateCommand()) { command.CommandType = CommandType.StoredProcedure; command.CommandText = "Verified.Pr_VerifiedLicenceToUseGet"; command.Parameters.Add(new SqlParameter("OperatingLicenceNumber", olNumber)); StringBuilder sb = new StringBuilder(); using (StringWriter stringWriter = new StringWriter(sb)) { connection.Open(); XmlReader reader = command.ExecuteXmlReader(); XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter); while (reader.MoveToContent() != XmlNodeType.None) { xmlWriter.WriteNode(reader, false); } reader.Close(); connection.Close(); xmlWriter.Flush(); xmlWriter.Close(); } found = sb.Length > 0; if (found) { rootNode.InnerXml = sb.ToString(); } } } XmlAttribute foundAttr = xmlDoc.CreateAttribute("found"); foundAttr.Value = found.ToString().ToLower(); rootNode.Attributes.Append(foundAttr); xmlDoc.AppendChild(rootNode); var result = xmlDoc; } } }