public void NestedAttributedObjectCanRoundTrip( XmlContentSerializer sut, XmlAttributedChangeset changeset, XmlAttributedTestEventX tex, XmlAttributedTestEventY tey) { changeset.Items = new object[] { tex, tey }; using (var ms = new MemoryStream()) using (var w = XmlWriter.Create(ms)) { sut.Serialize(w, changeset); w.Flush(); ms.Position = 0; using (var r = XmlReader.Create(ms)) { var content = sut.Deserialize(r); var actual = Assert.IsAssignableFrom <XmlAttributedChangeset>(content.Item); Assert.Equal(changeset.Id, actual.Id); var actualTex = Assert.IsAssignableFrom <XmlAttributedTestEventX>(actual.Items[0]); Assert.Equal(tex.Number, actualTex.Number); Assert.Equal(tex.Text, actualTex.Text); var actualTey = Assert.IsAssignableFrom <XmlAttributedTestEventY>(actual.Items[1]); Assert.Equal(tey.Number, actualTey.Number); Assert.Equal(tey.Flag, actualTey.Flag); } } }
public void WriteFirstEventFailsIfWritingIndexFails( AtomEventWriteUsage usage, [Frozen(As = typeof(ITypeResolver))] TestEventTypeResolver dummyResolver, [Frozen(As = typeof(IContentSerializer))] XmlContentSerializer dummySerializer, [Frozen] Mock <IAtomEventStorage> storeStub, AtomEventsInMemory innerStorage, AtomEventWriterFactory <XmlAttributedTestEventX> writerFactory, AtomEventObserver <XmlAttributedTestEventX> sut, XmlAttributedTestEventX @event) { storeStub .Setup(s => s.CreateFeedReaderFor(It.IsAny <Uri>())) .Returns((Uri u) => innerStorage.CreateFeedReaderFor(u)); storeStub .Setup(s => s.CreateFeedWriterFor( It.Is <AtomFeed>(f => f.Id != sut.Id))) .Returns((AtomFeed f) => innerStorage.CreateFeedWriterFor(f)); var expected = new Exception("On-purpose write failure."); storeStub .Setup(s => s.CreateFeedWriterFor( It.Is <AtomFeed>(f => f.Id == sut.Id))) .Throws(expected); var ae = Assert.Throws <AggregateException>(() => writerFactory.Create(usage).WriteTo(sut, @event)); Assert.True( ae.InnerExceptions.Any(expected.Equals), "Expected exception not thrown."); }
public void WriteToXmlWriterWritesCorrectXml( XmlContentSerializer serializer, XmlAtomContent content, AtomEntry entry, XmlAttributedTestEventX tex) { // Fixture setup var sb = new StringBuilder(); using (var w = XmlWriter.Create(sb)) { var sut = content.WithItem(tex); // Exercise system sut.WriteTo(w, serializer); // Verify outcome w.Flush(); var expected = XDocument.Parse( "<content type=\"application/xml\" xmlns=\"http://www.w3.org/2005/Atom\">" + " <test-event-x xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://grean:rocks\">" + " <number>" + tex.Number + "</number>" + " <text>" + tex.Text + "</text>" + " </test-event-x>" + "</content>"); var actual = XDocument.Parse(sb.ToString()); Assert.Equal(expected, actual, new XNodeEqualityComparer()); // Teardown } }
public void NestedAttributedObjectIsCorrectlySerialized( XmlContentSerializer sut, XmlAttributedChangeset changeset, XmlAttributedTestEventX tex, XmlAttributedTestEventY tey) { changeset.Items = new object[] { tex, tey }; var sb = new StringBuilder(); using (var w = XmlWriter.Create(sb)) { sut.Serialize(w, changeset); w.Flush(); var actual = sb.ToString(); var expected = XDocument.Parse( "<changeset xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://grean:rocks\">" + " <id>" + changeset.Id + "</id>" + " <items>" + " <test-event-x>" + " <number>" + tex.Number + "</number>" + " <text>" + tex.Text + "</text>" + " </test-event-x>" + " <test-event-y>" + " <number>" + tey.Number + "</number>" + " <flag>" + tey.Flag.ToString().ToLowerInvariant() + "</flag>" + " </test-event-y>" + " </items>" + "</changeset>"); Assert.Equal(expected, XDocument.Parse(actual), new XNodeEqualityComparer()); } }
public void OnNextAppendsItem( [Frozen(As = typeof(IAtomEventStorage))] AtomEventsInMemory dummyInjectedIntoSut, AtomEventStream <XmlAttributedTestEventX> sut, XmlAttributedTestEventX tex) { sut.OnNext(tex); Assert.Equal(tex, sut.SingleOrDefault()); }
public void SutCanRoundTripToString( XmlContentSerializer serializer, XmlAtomContent seed, XmlAttributedTestEventX tex) { var expected = seed.WithItem(tex); var xml = expected.ToXmlString(serializer); XmlAtomContent actual = XmlAtomContent.Parse(xml, serializer); Assert.Equal(expected, actual); }
public void ReadFromReturnsCorrectResult( XmlContentSerializer serializer, XmlAtomContent seed, XmlAttributedTestEventX tex) { var expected = seed.WithItem(tex); using (var sr = new StringReader(expected.ToXmlString(serializer))) using (var r = XmlReader.Create(sr)) { XmlAtomContent actual = XmlAtomContent.ReadFrom(r, serializer); Assert.Equal(expected, actual); } }
public void SutCanAppendAndYieldPolymorphicEvents( [Frozen(As = typeof(IAtomEventStorage))] AtomEventsInMemory dummyInjectedIntoSut, AtomEventStream <IXmlAttributedTestEvent> sut, XmlAttributedTestEventX tex, XmlAttributedTestEventY tey) { sut.AppendAsync(tex).Wait(); sut.AppendAsync(tey).Wait(); var expected = new IXmlAttributedTestEvent[] { tey, tex }; Assert.True(expected.SequenceEqual(sut)); }
public void ScanCanRoundTripAttributedClassInstance( XmlAttributedTestEventX @event) { var actual = XmlContentSerializer.Scan(@event.GetType().Assembly); var expected = Assert.IsAssignableFrom <XmlAttributedTestEventX>( @event.RoundTrip(actual)); Assert.Equal(expected.Number, @event.Number); Assert.Equal(expected.Text, @event.Text); }
public void ReadFromReturnsCorrectResult( AtomEntry seed, XmlAttributedTestEventX tex, XmlContentSerializer serializer) { var expected = seed.WithContent(seed.Content.WithItem(tex)); using (var sr = new StringReader(expected.ToXmlString(serializer))) using (var r = XmlReader.Create(sr)) { AtomEntry actual = AtomEntry.ReadFrom(r, serializer); Assert.Equal(expected, actual, new AtomEntryComparer()); } }
public void WriteFirstEventWritesPageBeforeIndex( AtomEventWriteUsage usage, [Frozen(As = typeof(ITypeResolver))] TestEventTypeResolver dummyResolver, [Frozen(As = typeof(IContentSerializer))] XmlContentSerializer dummySerializer, [Frozen(As = typeof(IAtomEventStorage))] SpyAtomEventStore spyStore, AtomEventWriterFactory <XmlAttributedTestEventX> writerFactory, AtomEventObserver <XmlAttributedTestEventX> sut, XmlAttributedTestEventX @event) { writerFactory.Create(usage).WriteTo(sut, @event); var feed = Assert.IsAssignableFrom <AtomFeed>( spyStore.ObservedArguments.Last()); Assert.Equal(sut.Id, feed.Id); }
public void ScanCorrectlySerializesAttributedClassInstance( XmlAttributedTestEventX @event) { var actual = XmlContentSerializer.Scan(@event.GetType().Assembly); var expected = XDocument.Parse( "<test-event-x xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://*****:*****@event.Number + "</number>" + " <text>" + @event.Text + "</text>" + "</test-event-x>"); Assert.Equal( expected, XDocument.Parse(@event.AsSerializedString(actual)), new XNodeEqualityComparer()); }
public void AppendAsyncCorrectlyStoresFeed( [Frozen(As = typeof(IAtomEventStorage))] AtomEventsInMemory storage, AtomFeedParser <XmlContentSerializer> parser, AtomEventStream <XmlAttributedTestEventX> sut, XmlAttributedTestEventX expectedEvent) { var before = DateTimeOffset.Now; sut.AppendAsync(expectedEvent).Wait(); var writtenFeed = storage.Feeds.Select(parser.Parse).Single(); var expectedFeed = new AtomFeedLikeness(before, sut.Id, expectedEvent); Assert.True( expectedFeed.Equals(writtenFeed), "Expected feed must match actual feed."); }
public void SutCanAppendAndYieldPolymorphicEvents( [Frozen(As = typeof(ITypeResolver))] TestEventTypeResolver dummyResolver, [Frozen(As = typeof(IContentSerializer))] XmlContentSerializer dummySerializer, [Frozen(As = typeof(IAtomEventStorage))] AtomEventsInMemory dummyInjectedIntoSut, [Frozen] UuidIri dummyId, AtomEventObserver <IXmlAttributedTestEvent> writer, LifoEvents <IXmlAttributedTestEvent> sut, XmlAttributedTestEventX tex, XmlAttributedTestEventY tey) { writer.AppendAsync(tex).Wait(); writer.AppendAsync(tey).Wait(); var expected = new IXmlAttributedTestEvent[] { tey, tex }; Assert.True(expected.SequenceEqual(sut)); }
public void SutCanRoundTripAttributedClassInstance( XmlContentSerializer sut, XmlAttributedTestEventX xatex) { using (var ms = new MemoryStream()) using (var w = XmlWriter.Create(ms)) { sut.Serialize(w, xatex); w.Flush(); ms.Position = 0; using (var r = XmlReader.Create(ms)) { var content = sut.Deserialize(r); var actual = Assert.IsAssignableFrom <XmlAttributedTestEventX>(content.Item); Assert.Equal(xatex.Number, actual.Number); Assert.Equal(xatex.Text, actual.Text); } } }
public void SerializeCorrectlySerializesAttributedClassInstance( XmlContentSerializer sut, XmlAttributedTestEventX xate) { var sb = new StringBuilder(); using (var w = XmlWriter.Create(sb)) { sut.Serialize(w, xate); w.Flush(); var actual = sb.ToString(); var expected = XDocument.Parse( "<test-event-x xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://grean:rocks\">" + " <number>" + xate.Number + "</number>" + " <text>" + xate.Text + "</text>" + "</test-event-x>"); Assert.Equal(expected, XDocument.Parse(actual), new XNodeEqualityComparer()); } }
public void WriteCorrectlyStoresFeed( AtomEventWriteUsage usage, [Frozen(As = typeof(ITypeResolver))] TestEventTypeResolver dummyResolver, [Frozen(As = typeof(IContentSerializer))] XmlContentSerializer dummySerializer, [Frozen(As = typeof(IAtomEventStorage))] AtomEventsInMemory storage, AtomEventWriterFactory <XmlAttributedTestEventX> writerFactory, AtomEventObserver <XmlAttributedTestEventX> sut, XmlAttributedTestEventX expectedEvent) { var before = DateTimeOffset.Now; writerFactory.Create(usage).WriteTo(sut, expectedEvent); var writtenFeeds = storage.Feeds.Select(ParseAtomFeed); var actual = FindFirstPage(writtenFeeds, sut.Id); var expectedFeed = new AtomFeedLikeness(before, actual.Id, expectedEvent); Assert.True( expectedFeed.Equals(actual), "Expected feed must match actual feed."); }
public void WriteCorrectlyStoresLastLinkOnIndex( AtomEventWriteUsage usage, [Frozen(As = typeof(ITypeResolver))] TestEventTypeResolver dummyResolver, [Frozen(As = typeof(IContentSerializer))] XmlContentSerializer dummySerializer, [Frozen(As = typeof(IAtomEventStorage))] AtomEventsInMemory storage, AtomEventWriterFactory <XmlAttributedTestEventX> writerFactory, AtomEventObserver <XmlAttributedTestEventX> sut, XmlAttributedTestEventX expectedEvent) { var before = DateTimeOffset.Now; writerFactory.Create(usage).WriteTo(sut, expectedEvent); var writtenFeeds = storage.Feeds.Select(ParseAtomFeed); var index = FindIndex(writtenFeeds, sut.Id); var firstLink = index.Links.SingleOrDefault(l => l.IsFirstLink); Assert.NotNull(firstLink); var lastLink = index.Links.SingleOrDefault(l => l.IsLastLink); Assert.NotNull(lastLink); Assert.Equal(firstLink.Href, lastLink.Href); }