Example #1
0
        public void UpdateCachedCollection_WhenCacheExpires()
        {
            // Arrange
            IEnumerable <MailchimpList> expectedInitialForms = MailchimpListModelMocksProvider.CreateMockedListsCollection(5);

            Mock.Arrange(() => this.mailchimpListClient.GetLists()).Returns(expectedInitialForms);

            var backgroundTaskService = Mock.Create <IBackgroundTasksService>();

            Mock.Arrange(() => backgroundTaskService.EnqueueTask(Arg.IsAny <Action>())).DoInstead((Action action) => { action(); });

            IMailchimpListCache mailchimpFormsCache = new MailchimpListCache(this.mailchimpListClient, this.cacheManager);

            ObjectFactory.RunWithContainer(
                new UnityContainer(),
                () =>
            {
                // Act
                ObjectFactory.Container.RegisterInstance <IBackgroundTasksService>(backgroundTaskService);
                IEnumerable <MailchimpList> actualInitialForms = mailchimpFormsCache.GetLists();

                this.SetCacheItemsAsExpired();

                IEnumerable <MailchimpList> expectedUpdatedForms = MailchimpListModelMocksProvider.CreateMockedListsCollection(5);
                Mock.Arrange(() => this.mailchimpListClient.GetLists()).Returns(expectedUpdatedForms);

                IEnumerable <MailchimpList> actualExpiredForms = mailchimpFormsCache.GetLists();
                IEnumerable <MailchimpList> actualUpdatedForms = mailchimpFormsCache.GetLists();

                // Assert
                Assert.IsTrue(MailchimpListModelsComparer.AreEqual(expectedInitialForms, actualInitialForms));
                Assert.IsTrue(MailchimpListModelsComparer.AreEqual(expectedInitialForms, actualExpiredForms));
                Assert.IsTrue(MailchimpListModelsComparer.AreEqual(expectedUpdatedForms, actualUpdatedForms));
            });
        }
Example #2
0
        public void ReturnEmptyCollection_WhenOriginalCollectionIsEmpty()
        {
            // Arrange
            IEnumerable <MailchimpList> expectedForms = Enumerable.Empty <MailchimpList>();

            Mock.Arrange(() => this.mailchimpListClient.GetLists()).Returns(expectedForms);

            IMailchimpListCache mailchimpFormsCache = new MailchimpListCache(this.mailchimpListClient, this.cacheManager);

            // Act
            IEnumerable <MailchimpList> actualForms = mailchimpFormsCache.GetLists();

            // Assert
            Assert.IsTrue(MailchimpListModelsComparer.AreEqual(expectedForms, actualForms));
        }
Example #3
0
        public void ReturnCollection_WhenCallingGetForTheFirstTime()
        {
            // Arrange
            IEnumerable <MailchimpList> expectedLists = MailchimpListModelMocksProvider.CreateMockedListsCollection(5);

            Mock.Arrange(() => this.mailchimpListClient.GetLists()).Returns(expectedLists);

            IMailchimpListCache mailchimpFormsCache = new MailchimpListCache(this.mailchimpListClient, this.cacheManager);

            // Act
            IEnumerable <MailchimpList> actualLists = mailchimpFormsCache.GetLists();

            // Assert
            Assert.IsTrue(MailchimpListModelsComparer.AreEqual(expectedLists, actualLists));
        }