public void WhenMultipleAttributesAreDifferentComparerFails() { string xmlA = @" <root> <parents> <parent id='1' name='John'> <child></child> </parent> <parent id='2' name='Mary'> <child></child> <child></child> </parent> </parents> </root>" ; string xmlB = @" <root> <parents> <parent id='1' name='Jake'> <child></child> </parent> <parent id='2' name='Jane'> <child></child> <child></child> </parent> </parents> </root>" ; XmlComparer comparer = new XmlComparer(); comparer.AreEqual(xmlA, xmlB); Assert.IsFalse(comparer.Results.IsSuccessful); }
public void WhenXmlIsNotEqualComparerFails() { XmlComparer comparer = new XmlComparer(); XmlDocument[] xmlDocs = new XmlDocument[2]; xmlDocs[0] = new XmlDocument(); xmlDocs[0].LoadXml(@"<root><child><grandchild>hello</grandchild></child></root>"); xmlDocs[1] = new XmlDocument(); xmlDocs[1].LoadXml(@"<root><child>hello</child></root>"); Assert.IsFalse(comparer.AreEqual(xmlDocs[0], xmlDocs[1])); }
public void WhenAttributesAreDifferentComparerFails() { XmlComparer comparer = new XmlComparer(); XmlDocument[] xmlDocs = new XmlDocument[2]; xmlDocs[0] = new XmlDocument(); xmlDocs[0].LoadXml(@"<root><child test='2'><grandchild>hello</grandchild></child></root>"); xmlDocs[1] = new XmlDocument(); xmlDocs[1].LoadXml(@"<root><child test='1'><grandchild>hello</grandchild></child></root>"); Assert.IsFalse(comparer.AreEqual(xmlDocs[0], xmlDocs[1])); }
public void WhenXmlHasGroupsAndAreTheSameComparerSucceeds() { XmlComparer comparer = new XmlComparer(); XmlDocument[] xmlDocs = new XmlDocument[2]; xmlDocs[0] = new XmlDocument(); xmlDocs[0].LoadXml(@"<root><child><grandchild>hello</grandchild></child><child></child></root>"); xmlDocs[1] = new XmlDocument(); xmlDocs[1].LoadXml(@"<root><child><grandchild>hello</grandchild></child><child></child></root>"); Assert.IsTrue(comparer.AreEqual(xmlDocs[0], xmlDocs[1])); }
public void CheckWsdlImpl() { string goldWsdl; try { Assembly _assembly = Assembly.GetExecutingAssembly(); StreamReader _stream = new StreamReader(_assembly.GetManifestResourceStream("MonoTests.System.ServiceModel.Test.FeatureBased.Features.Contracts." + typeof(TServer).Name + ".xml")); goldWsdl = _stream.ReadToEnd(); } catch { Console.WriteLine("Couldn't test WSDL of server " + typeof(TServer).Name + " because gold wsdl is not embedded in test !"); return; } string currentWsdl = ""; HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(getMexEndpoint() + "?wsdl"); // Obtain a 'Stream' object associated with the response object. WebResponse response = myReq.GetResponse(); Stream ReceiveStream = response.GetResponseStream(); Encoding encode = global::System.Text.Encoding.GetEncoding("utf-8"); // Pipe the stream to a higher level stream reader with the required encoding format. StreamReader readStream = new StreamReader(ReceiveStream, encode); Console.WriteLine("\nResponse stream received"); int maxLen = 10 * 1024; Char [] read = new Char [maxLen]; // Read 256 charcters at a time. int count = readStream.Read(read, 0, maxLen); while (count > 0) { currentWsdl = currentWsdl + new String(read, 0, count); count = readStream.Read(read, 0, 256); } readStream.Close(); response.Close(); XmlComparer comparer = new XmlComparer(XmlComparer.Flags.IgnoreAttribOrder, true); Assert.IsTrue(comparer.AreEqual(goldWsdl, currentWsdl), "Service WSDL does not match gold WSDL"); }
public void Read_SingleChunkMessage_Succeeds() { ITokenReader tokenReader = new XmlTokenReader(); ITokenReaderState tokenReaderState = new XmlTokenReaderState(); String expectedMessage = StockLocationInfoResponseEnvelopeDataContractTests.Response.Xml; ReadOnlySequence <byte> buffer = new ReadOnlySequence <byte>(XmlSerializationSettings.Encoding.GetBytes(expectedMessage)); bool readResult = tokenReader.Read(ref tokenReaderState, ref buffer, out ReadOnlySequence <byte> token, out _); Assert.IsTrue(readResult); String actualMessage = XmlSerializationSettings.Encoding.GetString(token.ToArray()); Assert.IsTrue(XmlComparer.AreEqual(expectedMessage, actualMessage)); }
public void TestSubscriptionOfSingleObserver() { using (ITokenizer tokenizer = new XmlTokenizer(this.BaseStream)) { Mock <IObserver <ReadOnlySequence <byte> > > observerMock = new Mock <IObserver <ReadOnlySequence <byte> > >(); List <String> actualMessages = new List <String>(); using (ManualResetEventSlim sync = new ManualResetEventSlim()) { observerMock.Setup(x => x.OnNext(It.IsAny <ReadOnlySequence <byte> >())).Callback((ReadOnlySequence <byte> token) => { String message = XmlSerializationSettings.Encoding.GetString(token.ToArray()); actualMessages.Add(message); }); observerMock.Setup(x => x.OnCompleted()).Callback(() => { sync.Set(); }); using (IDisposable subscription = tokenizer.Subscribe(observerMock.Object)) { sync.Wait(); // Number of calls depends on buffer size. observerMock.Verify(x => x.OnNext(It.IsAny <ReadOnlySequence <byte> >()), Times.Exactly(this.Messages.Count)); Assert.AreEqual(actualMessages.Count, this.Messages.Count); for (int i = 0; i < actualMessages.Count; i++) { String expected = this.Messages[i]; String actual = actualMessages[i]; XmlComparer.AreEqual(expected, actual); } Assert.IsNotNull(subscription); } } } }
public void ComparisonResultsAreCorrect() { string xmlA = @" <root> <parents> <parent id='1' name='John'> <child></child> </parent> <parent id='2' name='Mary'> <child></child> <child></child> </parent> </parents> </root>" ; string xmlB = @" <root> <parents> <parent id='1' name='Jake'> <child></child> </parent> <parent id='2' name='Jane'> <child></child> <child></child> </parent> </parents> </root>" ; XmlComparer comparer = new XmlComparer(); comparer.AreEqual(xmlA, xmlB); AssertResults( "child:Truechild:Truechild:Trueparent:Falseparent:Falseparents:Trueroot:True", comparer.Results ); }
public void Read_MultipleChunkMessage_Succeeds() { ITokenReader tokenReader = new XmlTokenReader(); ITokenReaderState tokenReaderState = new XmlTokenReaderState(); String expectedMessage = StockLocationInfoResponseEnvelopeDataContractTests.Response.Xml; (String Left, String Right)messageBlocks = expectedMessage.Divide(); ReadOnlySequence <byte> firstChunk = new ReadOnlySequence <byte>(XmlSerializationSettings.Encoding.GetBytes(messageBlocks.Left)); ReadOnlySequence <byte> secondChunk = new ReadOnlySequence <byte>(XmlSerializationSettings.Encoding.GetBytes(messageBlocks.Left + messageBlocks.Right)); bool firstReadResult = tokenReader.Read(ref tokenReaderState, ref firstChunk, out _, out _); Assert.IsFalse(firstReadResult); bool secondReadResult = tokenReader.Read(ref tokenReaderState, ref secondChunk, out ReadOnlySequence <byte> token, out _); Assert.IsTrue(secondReadResult); String actualMessage = XmlSerializationSettings.Encoding.GetString(token.ToArray()); Assert.IsTrue(XmlComparer.AreEqual(expectedMessage, actualMessage)); }