public void CompleteXml_ValidEventsCalled() { using (ShimsContext.Create()) { // arrange string markup = @"<Root xmlns=""defaultns"" xmlns:ns=""Random"" ns:Key=""55""> <ns:Child ns:Key=""01""> <GrandChild><![CDATA[ccc]]></GrandChild> </ns:Child> <ds:Child xmlns:ds=""Random"" ds:Key=""02""> <ds:GrandChild>bbb</ds:GrandChild> </ds:Child> <Child Key=""03""></Child> </Root>"; // use object to preserve reference // ref/out parameters doesn't play well with lamba/anon functions var parsingStates = new XmlParsingStates(); var reader = arrangeXmppReader(parsingStates); var stream = arrangeMarkupStream(markup); // act actConnectSleepDisconnect(reader, stream, parsingStates.WaitHandle); // assert Assert.IsTrue(parsingStates.StartCalled, "document start not called"); Assert.IsTrue(parsingStates.EndCalled, "document end not called"); Assert.AreEqual(6, parsingStates.ElementCount, "element count is not the same"); } }
public void MultipleRootXml_ValidEventsCalled() { using (ShimsContext.Create()) { // arrange string markup = @"<Root1> </Root1> <Root2> </Root2>"; // use object to preserve reference // ref/out parameters doesn't play well with lamba/anon functions var parsingStates = new XmlParsingStates(); var reader = arrangeXmppReader(parsingStates); var stream = arrangeMarkupStream(markup); // act actConnectSleepDisconnect(reader, stream, parsingStates.WaitHandle); // assert Assert.IsFalse(parsingStates.XmlExceptionRaised, "xml exception not raised"); Assert.IsTrue(parsingStates.EndCalled, "document end is not called"); } }
private AsyncXmppReader arrangeXmppReader(XmlParsingStates parseStates) { var reader = new AsyncXmppReader(new XmlDocument()); // set wait handle when any of these has run reader.OnXmlDocumentStart += (node) => { parseStates.WaitHandle.Set(); parseStates.StartCalled = true; }; reader.OnXmlElementComplete += (node) => { parseStates.WaitHandle.Set(); parseStates.ElementCount++; }; reader.OnXmlDocumentEnd += (node) => { parseStates.WaitHandle.Set(); parseStates.EndCalled = true; }; reader.OnXmlException += (exception) => { parseStates.WaitHandle.Set(); parseStates.XmlExceptionRaised = exception != null; parseStates.XmlExceptionMessage = exception != null ? exception.Message : ""; }; return(reader); }
public void InvalidXml_ValidEventsCalled() { using (ShimsContext.Create()) { // arrange string markup = @"<Root ns:Key=""55""> <Child xmlns:ns=""Random"" Key=""01""> <GrandChild><![CDATA[ccc]]></GrandChild> </Child> <Child Key=""02""> <GrandChild>bbb</GrandChild> </Child> <Child Key=""03""></Child> </Root>"; // use object to preserve reference // ref/out parameters doesn't play well with lamba/anon functions var parsingStates = new XmlParsingStates(); var reader = arrangeXmppReader(parsingStates); var stream = arrangeMarkupStream(markup); // act actConnectSleepDisconnect(reader, stream, parsingStates.WaitHandle); // assert Assert.IsTrue(parsingStates.XmlExceptionRaised, "xml exception not raised"); Assert.IsFalse(parsingStates.EndCalled, "document end is called"); } }
public void CompleteXml_DerivedXmppElements() { using (ShimsContext.Create()) { // arrange string markup = @"<str:features xmlns:str=""http://etherx.jabber.org/streams""> <mechanisms xmlns=""urn:ietf:params:xml:ns:xmpp-sasl""> <mechanism>X-OAUTH2</mechanism> <mechanism>X-GOOGLE-TOKEN</mechanism> <mechanism>PLAIN</mechanism> </mechanisms> </str:features>"; // use object to preserve reference // ref/out parameters doesn't play well with lamba/anon functions var parsingStates = new XmlParsingStates(); var reader = arrangeXmppReader(parsingStates); var stream = arrangeMarkupStream(markup); var featuresConstructorCalled = false; var mechanismsConstructorCalled = false; var mechanismConstructorCalledTimes = 0; reader.OnXmlElementComplete += (node) => { if (node is Features) { featuresConstructorCalled = true; } else if (node is Mechanisms) { mechanismsConstructorCalled = true; } else if (node is Mechanism) { mechanismConstructorCalledTimes++; } }; // act actConnectSleepDisconnect(reader, stream, parsingStates.WaitHandle); // assert Assert.IsTrue(parsingStates.StartCalled, "document start not called"); Assert.IsTrue(parsingStates.EndCalled, "document end not called"); Assert.AreEqual(5, parsingStates.ElementCount, "element count is not the same"); Assert.IsTrue(featuresConstructorCalled, "features constructor not called"); Assert.IsTrue(mechanismsConstructorCalled, "mechanisms constructor not called"); Assert.AreEqual(3, mechanismConstructorCalledTimes, "mechanism constructor not called 3 times"); } }