Ejemplo n.º 1
0
        public void AppendAsyncMoreThanPageSizeEventsStoresOldestEventsInPreviousPage(
            [Frozen(As = typeof(IAtomEventStorage))] AtomEventsInMemory storage,
            AtomFeedParser <XmlContentSerializer> parser,
            AtomEventStream <XmlAttributedTestEventX> sut,
            Generator <XmlAttributedTestEventX> eventGenerator)
        {
            var before = DateTimeOffset.Now;
            var events = eventGenerator.Take(sut.PageSize + 1).ToList();

            events.ForEach(e => sut.AppendAsync(e).Wait());

            var writtenIndex = storage.Feeds
                               .Select(parser.Parse)
                               .Single(f => f.Id == sut.Id);
            UuidIri previousPageId =
                Guid.Parse(
                    writtenIndex.Links
                    .Single(AtomEventStream.IsPreviousFeedLink)
                    .Href.ToString());
            var actualPreviousPage = storage.Feeds
                                     .Select(parser.Parse)
                                     .Single(f => f.Id == previousPageId);
            var expectedPreviousPage = new AtomFeedLikeness(
                before,
                previousPageId,
                events.AsEnumerable().Reverse().Skip(1).ToArray());

            Assert.True(
                expectedPreviousPage.Equals(actualPreviousPage),
                "Expected feed must match actual feed.");
        }
Ejemplo n.º 2
0
        public void AppendAsyncTwicePageSizeEventDoesNotAddPreviousLinkToPreviousPage(
            [Frozen(As = typeof(IAtomEventStorage))] AtomEventsInMemory storage,
            AtomFeedParser <XmlContentSerializer> parser,
            AtomEventStream <XmlAttributedTestEventX> sut,
            Generator <XmlAttributedTestEventX> eventGenerator)
        {
            var before = DateTimeOffset.Now;
            var events = eventGenerator.Take(sut.PageSize * 2).ToList();

            events.ForEach(e => sut.AppendAsync(e).Wait());

            var writtenIndex = storage.Feeds
                               .Select(parser.Parse)
                               .Single(f => f.Id == sut.Id);
            UuidIri previousPageId =
                Guid.Parse(
                    writtenIndex.Links
                    .Single(AtomEventStream.IsPreviousFeedLink)
                    .Href.ToString());
            var previousPage = storage.Feeds
                               .Select(parser.Parse)
                               .Single(f => f.Id == previousPageId);

            Assert.Equal(
                0,
                previousPage.Links.Count(AtomEventStream.IsPreviousFeedLink));
        }
Ejemplo n.º 3
0
        public void AppendAsyncMoreThanPageSizeEventsStoresPreviousPage(
            [Frozen(As = typeof(IAtomEventStorage))] AtomEventsInMemory storage,
            AtomFeedParser <XmlContentSerializer> parser,
            AtomEventStream <XmlAttributedTestEventX> sut,
            Generator <XmlAttributedTestEventX> eventGenerator)
        {
            var before = DateTimeOffset.Now;
            var events = eventGenerator.Take(sut.PageSize + 1).ToList();

            events.ForEach(e => sut.AppendAsync(e).Wait());

            var writtenIndex = storage.Feeds
                               .Select(parser.Parse)
                               .Single(f => f.Id == sut.Id);
            UuidIri previousPageId =
                Guid.Parse(
                    writtenIndex.Links
                    .Single(AtomEventStream.IsPreviousFeedLink)
                    .Href.ToString());

            Assert.True(
                storage.Feeds
                .Select(parser.Parse)
                .Any(f => f.Id == previousPageId),
                "The previous feed should have been stored.");
        }
Ejemplo n.º 4
0
        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.");
        }
Ejemplo n.º 5
0
        public void AppendAsyncMoreThanPageSizeEventsAddsLinkToPreviousPageToIndex(
            [Frozen(As = typeof(IAtomEventStorage))] AtomEventsInMemory storage,
            AtomFeedParser <XmlContentSerializer> parser,
            AtomEventStream <XmlAttributedTestEventX> sut,
            Generator <XmlAttributedTestEventX> eventGenerator)
        {
            var before = DateTimeOffset.Now;
            var events = eventGenerator.Take(sut.PageSize + 1).ToList();

            events.ForEach(e => sut.AppendAsync(e).Wait());

            var writtenIndex = storage.Feeds
                               .Select(parser.Parse)
                               .Single(f => f.Id == sut.Id);

            Assert.Equal(
                1,
                writtenIndex.Links.Count(AtomEventStream.IsPreviousFeedLink));
        }
Ejemplo n.º 6
0
        public void AppendAsyncPageSizeEventsSavesAllEntriesInIndex(
            [Frozen(As = typeof(IAtomEventStorage))] AtomEventsInMemory storage,
            AtomFeedParser <XmlContentSerializer> parser,
            AtomEventStream <XmlAttributedTestEventX> sut,
            Generator <XmlAttributedTestEventX> eventGenerator)
        {
            var before = DateTimeOffset.Now;
            var events = eventGenerator.Take(sut.PageSize).ToList();

            events.ForEach(e => sut.AppendAsync(e).Wait());

            var writtenFeed  = storage.Feeds.Select(parser.Parse).Single();
            var expectedFeed = new AtomFeedLikeness(
                before,
                sut.Id,
                events.AsEnumerable().Reverse().ToArray());

            Assert.True(
                expectedFeed.Equals(writtenFeed),
                "Expected feed must match actual feed.");
        }
Ejemplo n.º 7
0
        public void AppendAsyncMoreThanPageSizeEventsOnlyStoresOverflowingEvent(
            [Frozen(As = typeof(IAtomEventStorage))] AtomEventsInMemory storage,
            AtomFeedParser <XmlContentSerializer> parser,
            AtomEventStream <XmlAttributedTestEventX> sut,
            Generator <XmlAttributedTestEventX> eventGenerator)
        {
            var before = DateTimeOffset.Now;
            var events = eventGenerator.Take(sut.PageSize + 1).ToList();

            events.ForEach(e => sut.AppendAsync(e).Wait());

            var writtenIndex = storage.Feeds
                               .Select(parser.Parse)
                               .Single(f => f.Id == sut.Id);
            var expectedIndex = new AtomFeedLikeness(
                before,
                sut.Id,
                events.AsEnumerable().Reverse().First());

            Assert.True(
                expectedIndex.Equals(writtenIndex),
                "Expected feed must match actual feed.");
        }