public void WriteXmlLoginTest() { SdkConfig config = new SdkConfig() { CompanyId = "testcompany", UserId = "testuser", UserPassword = "******", }; Content contentBlock = new Content(); ApiSessionCreate func = new ApiSessionCreate() { ControlId = "unittest", }; contentBlock.Add(func); string expected = @"<?xml version=""1.0"" encoding=""utf-8""?> <operation transaction=""false""> <authentication> <login> <userid>testuser</userid> <companyid>testcompany</companyid> <password>testpass</password> </login> </authentication> <content> <function controlid=""unittest""> <getAPISession /> </function> </content> </operation>"; Stream stream = new MemoryStream(); XmlWriterSettings xmlSettings = new XmlWriterSettings(); xmlSettings.Encoding = Encoding.UTF8; xmlSettings.Indent = true; xmlSettings.IndentChars = " "; IaXmlWriter xml = new IaXmlWriter(stream, xmlSettings); OperationBlock operationBlock = new OperationBlock(config, contentBlock); operationBlock.WriteXml(ref xml); xml.Flush(); stream.Position = 0; StreamReader reader = new StreamReader(stream); Diff xmlDiff = DiffBuilder.Compare(expected).WithTest(reader.ReadToEnd()) .WithDifferenceEvaluator(DifferenceEvaluators.Default) .Build(); Assert.IsFalse(xmlDiff.HasDifferences(), xmlDiff.ToString()); }
/// <summary> /// Returns a Stream of the XML request /// </summary> public Stream WriteXml() { Stream stream = new MemoryStream(); XmlWriterSettings xmlSettings = new XmlWriterSettings(); xmlSettings.Encoding = encoding; IaXmlWriter xml = new IaXmlWriter(stream, xmlSettings); xml.WriteStartElement("request"); control.WriteXml(ref xml); // Create control block operation.WriteXml(ref xml); // Create operation block xml.WriteEndElement(); // request xml.Flush(); return(stream); }