public void LocalCache_will_not_store_to_cache_if_content_type_already_added_with_same_refresh_time() { // Arrange var contentRefreshDate = new DateTime(2014, 07, 07, 12, 30, 0); var storageHandler = new Mock<IStorageHandler<Content>>(); storageHandler.Setup(x => x.WriteToStorage(It.IsAny<ContentTypes>(), It.IsAny<Content>())); var cache = new LocalCache<Content>(storageHandler.Object); var footerContent = new Content { Sections = new List<ContentSection> { new ContentSection { Id = ContentTypes.Footer.ToString(), Html = "<div id='footer' />" } }, RefreshDate = contentRefreshDate }; // Act cache.WriteToCache(ContentTypes.Footer, footerContent, footerContent.RefreshDate); cache.WriteToCache(ContentTypes.Footer, footerContent, footerContent.RefreshDate); // Assert storageHandler.Verify(x => x.WriteToStorage(It.IsAny<ContentTypes>(), It.IsAny<Content>()), Times.Once); }
public void LocalCache_will_store_to_cache_if_content_type_exists_with_older_refresh_time() { // Arrange var storageHandler = new Mock<IStorageHandler<Content>>(); storageHandler.Setup(x => x.WriteToStorage(It.IsAny<ContentTypes>(), It.IsAny<Content>())); var cache = new LocalCache<Content>(storageHandler.Object); var oldFooterContent = new Content { Sections = new List<ContentSection> { new ContentSection { Id = ContentTypes.Footer.ToString(), Html = "<div id='footer' />" } }, RefreshDate = new DateTime(2014, 07, 07) }; var newFooterContent = new Content { Sections = new List<ContentSection> { new ContentSection { Id = ContentTypes.Footer.ToString(), Html = "<div id='footer'>footer</div>" } }, RefreshDate = new DateTime(2014, 07, 08) }; // Act cache.WriteToCache(ContentTypes.Footer, oldFooterContent, oldFooterContent.RefreshDate); cache.WriteToCache(ContentTypes.Footer, newFooterContent, newFooterContent.RefreshDate); // Assert storageHandler.Verify(x => x.WriteToStorage(It.IsAny<ContentTypes>(), It.IsAny<Content>()), Times.Exactly(2)); }
public void LocalCache_will_store_to_cache_if_content_type_not_already_added() { // Arrange var storageHandler = new Mock<IStorageHandler<Content>>(); storageHandler.Setup(x => x.WriteToStorage(It.IsAny<ContentTypes>(), It.IsAny<Content>())); var cache = new LocalCache<Content>(storageHandler.Object); var footerContent = new Content { Sections = new List<ContentSection> { new ContentSection { Id = ContentTypes.Footer.ToString(), Html = "<div id='footer' />" } } }; // Act cache.WriteToCache(ContentTypes.Footer, footerContent, DateTime.Now); // Assert storageHandler.Verify(x => x.WriteToStorage(It.IsAny<ContentTypes>(), It.IsAny<Content>()), Times.Once); }