示例#1
0
        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());
            }
        }
示例#2
0
        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 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));
        }
示例#4
0
        public void ReadFromXmlWithTestEventYReturnsCorrectResult(
            AtomEntry seed,
            XmlAttributedTestEventY tey,
            XmlContentSerializer serializer)
        {
            var expected = seed.WithContent(seed.Content.WithItem(tey));

            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());
                }
        }
示例#5
0
        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 ReadFromXmlWithTestEventYReturnsCorrectResult(
     AtomEntry seed,
     XmlAttributedTestEventY tey,
     XmlContentSerializer serializer)
 {
     var expected = seed.WithContent(seed.Content.WithItem(tey));
     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());
     }
 }