public void ShouldCreateXmlReader()
 {
     FileName fileName = new FileName("current.atom");
     using (XmlReader reader = fileName.CreateXmlReader(@"..\..\Data\productcatalog\", new XmlReaderSettings { CloseInput = true }))
     {
         Assert.IsNotNull(reader);
     }
 }
        public void ShouldBeAbleToCloneSelf()
        {
            FileName fileName = new FileName("A");
            FileName clone = fileName.Clone();

            Assert.AreEqual(fileName, clone);
            Assert.False(ReferenceEquals(fileName, clone));
        }
 public void ShouldCreateXmlWriter()
 {
     FileName fileName = new FileName("temp");
     using (XmlWriter writer = fileName.CreateXmlWriter(@"..\..\Data\", new XmlWriterSettings{CloseOutput = true}))
     {
         Assert.IsNotNull(writer);
     }
     File.Delete(Path.Combine(@"..\..\Data\", fileName.GetValue()));
 }
 public ArchiveFeed LoadArchiveFeed(IFileSystem fileSystem, FileName fileName)
 {
     using (XmlReader reader = fileSystem.ArchiveDirectory.GetXmlReader(fileName))
     {
         SyndicationFeed feed = SyndicationFeed.Load(reader);
         Id id = SampleLinks.Instance.GetIdFromFeedUri(feed.GetSelfLink().GetAbsoluteUri());
         return new ArchiveFeed(feed, new FeedMapping(id));
     }
 }
        public void ShouldExhibitValueTypeEquality()
        {
            FileName fileName1 = new FileName("A");
            FileName fileName2 = new FileName("A");
            FileName fileName3 = new FileName("B");

            Assert.True(fileName1.Equals(fileName2));
            Assert.False(fileName1.Equals(fileName3));
            Assert.True(fileName1.Equals(fileName1));
            Assert.False(fileName1.Equals(new object()));
            Assert.False(fileName1.Equals(null));

            Assert.True(fileName1.GetHashCode().Equals(fileName2.GetHashCode()));
            Assert.False(fileName1.GetHashCode().Equals(fileName3.GetHashCode()));
            Assert.True(fileName1.GetHashCode().Equals(fileName1.GetHashCode()));
            Assert.False(fileName1.GetHashCode().Equals(new object().GetHashCode()));
        }
        public void IfFeedFillsExactlyToQuotaShouldNotBeArchived()
        {
            FileName tempFileName = null;
            FeedBuilder feedBuilder = new FeedBuilder(SampleLinks.Instance);

            InMemoryFileSystem fileSystem = new InMemoryFileSystem();
            EventBuffer buffer = new EventBuffer();

            Repeat.Times(3).Action(() => buffer.Add(new EventBuilder().Build()));

            FakeTimer timer = new FakeTimer();
            FeedWriter feedWriter = new FeedWriter(timer, buffer, fileSystem, new FeedBuilder(SampleLinks.Instance));
            feedWriter.FeedMappingsChanged += ((o, args) => tempFileName = new FileName(args.RecentEventsFeedStoreId));

            timer.Fire();

            Assert.AreEqual(1, fileSystem.FileCount(fileSystem.CurrentDirectory));
            Assert.AreEqual(0, fileSystem.FileCount(fileSystem.ArchiveDirectory));

            RecentEventsFeed rehydratedFeed = feedBuilder.LoadRecentEventsFeed(fileSystem, tempFileName);
            Assert.AreEqual(3, rehydratedFeed.GetSyndicationFeed().Items.Count());
        }
        public void WhenTriggeredShouldAddBatchOfEventsToCurrentFeed()
        {
            FileName tempFileName = null;

            InMemoryFileSystem fileSystem = new InMemoryFileSystem();
            EventBuffer buffer = new EventBuffer();

            EventBuilder eventBuilder = new EventBuilder();
            Repeat.Times(2).Action(() => buffer.Add(eventBuilder.Build()));

            FakeTimer timer = new FakeTimer();
            FeedWriter feedWriter = new FeedWriter(timer, buffer, fileSystem, new FeedBuilder(SampleLinks.Instance));
            feedWriter.FeedMappingsChanged += ((o, args) => tempFileName = new FileName(args.RecentEventsFeedStoreId));

            timer.Fire();

            Assert.AreEqual(1, fileSystem.FileCount(fileSystem.CurrentDirectory));

            RecentEventsFeed rehydratedFeed = new FeedBuilder(SampleLinks.Instance).LoadRecentEventsFeed(fileSystem, tempFileName);
            Assert.AreEqual(2, rehydratedFeed.GetNumberOfEntries());
        }
        public void WhenTriggeredRepeatedlyShouldContinueToAddEventsToExistingFeed()
        {
            FileName tempFileName = null;
            FeedBuilder feedBuilder = new FeedBuilder(SampleLinks.Instance);

            InMemoryFileSystem fileSystem = new InMemoryFileSystem();
            EventBuffer buffer = new EventBuffer();

            buffer.Add(new EventBuilder().Build());

            FakeTimer timer = new FakeTimer();
            FeedWriter feedWriter = new FeedWriter(timer, buffer, fileSystem, new FeedBuilder(SampleLinks.Instance));
            feedWriter.FeedMappingsChanged += ((o, args) => tempFileName = new FileName(args.RecentEventsFeedStoreId));

            timer.Fire();

            RecentEventsFeed rehydratedFeed = feedBuilder.LoadRecentEventsFeed(fileSystem, tempFileName);
            Assert.AreEqual(1, rehydratedFeed.GetSyndicationFeed().Items.Count());
            Assert.AreEqual("?page=1", rehydratedFeed.GetSyndicationFeed().GetViaLink().Uri.Query);

            buffer.Add(new EventBuilder().Build());

            timer.Fire();

            RecentEventsFeed secondRehydratedFeed = feedBuilder.LoadRecentEventsFeed(fileSystem, tempFileName);
            Assert.AreEqual(2, secondRehydratedFeed.GetSyndicationFeed().Items.Count());
            Assert.AreEqual("?page=1", secondRehydratedFeed.GetSyndicationFeed().GetViaLink().Uri.Query);
        }
        public void WhenNumberOfEventsExceedsQuotaShouldArchiveFeedAndBeginAnotherOne()
        {
            FileName tempFileName = null;
            FeedBuilder feedBuilder = new FeedBuilder(SampleLinks.Instance);

            InMemoryFileSystem fileSystem = new InMemoryFileSystem();
            EventBuffer buffer = new EventBuffer();

            EventBuilder eventBuilder = new EventBuilder();
            Repeat.Times(RecentEventsFeed.Quota + 1).Action(() => buffer.Add(eventBuilder.Build()));

            FakeTimer timer = new FakeTimer();
            FeedWriter feedWriter = new FeedWriter(timer, buffer, fileSystem, new FeedBuilder(SampleLinks.Instance));
            feedWriter.FeedMappingsChanged += ((o, args) => tempFileName = new FileName(args.RecentEventsFeedStoreId));

            timer.Fire();

            Assert.AreEqual(1, fileSystem.FileCount(fileSystem.CurrentDirectory));
            Assert.AreEqual(1, fileSystem.FileCount(fileSystem.ArchiveDirectory));

            ArchiveFeed archivedFeed = LoadArchiveFeed(fileSystem, new FileName("1"));
            Assert.AreEqual(10, archivedFeed.GetNumberOfEntries());
            Assert.AreEqual("?page=1", archivedFeed.GetSyndicationFeed().GetSelfLink().Uri.Query);
            Assert.AreEqual("?page=2", archivedFeed.GetSyndicationFeed().GetNextArchiveLink().Uri.Query);

            RecentEventsFeed recentEventsFeed = feedBuilder.LoadRecentEventsFeed(fileSystem, tempFileName);
            Assert.AreEqual(1, recentEventsFeed.GetSyndicationFeed().Items.Count());
            Assert.AreEqual("?page=2", recentEventsFeed.GetSyndicationFeed().GetViaLink().Uri.Query);
        }
 public RecentEventsFeed LoadRecentEventsFeed(IFileSystem fileSystem, FileName fileName)
 {
     using (XmlReader reader = fileSystem.CurrentDirectory.GetXmlReader(fileName))
     {
         SyndicationFeed feed = SyndicationFeed.Load(reader);
         Id id = links.GetIdFromFeedUri(feed.GetViaLink().GetAbsoluteUri());
         return new RecentEventsFeed(feed, new FeedMapping(id), this);
     }
 }
 public XmlWriter GetXmlWriter(FileName fileName)
 {
     return fileName.CreateXmlWriter(directory, WriterSettings);
 }
 public bool Equals(FileName other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.value, value);
 }
 public Entry(SyndicationItem item, FileName fileName)
 {
     this.item = item;
     this.fileName = fileName;
 }
 public void ShouldPreserveExistingAtomExtension()
 {
     FileName fileName = new FileName("abc.atom");
     Assert.AreEqual("abc.atom", fileName.GetValue());
 }
 public void ShouldAddAtomExtensionToValueWithoutExtension()
 {
     FileName fileName = new FileName("abc");
     Assert.AreEqual("abc.atom", fileName.GetValue());
 }
 public void ToStringShouldReturnStringValueOfFileName()
 {
     FileName fileName = new FileName("A");
     Assert.AreEqual("A.atom", fileName.ToString());
 }
 private FeedMapping(Id id, FileName fileName)
 {
     this.id = id;
     this.fileName = fileName;
 }