Пример #1
0
        public async Task GetTheCountOfPromotionsForTheLastTenDaysAsync_WithValidData_ShouldReturnCorrectResult()
        {
            //Arrange
            var expected = new List <int> {
                1, 0, 1, 0, 2, 0, 0, 0, 1, 1
            };

            var moqAdsService = new Mock <IAdsService>();
            var context       = InitializeContext.CreateContextForInMemory();

            promotionsService = new PromotionsService(context, moqAdsService.Object);

            var testingPromotions = new List <PromotionOrder>
            {
                new PromotionOrder {
                    Id = 1, CreatedOn = DateTime.UtcNow.AddDays(-5)
                },
                new PromotionOrder {
                    Id = 2, CreatedOn = DateTime.UtcNow.AddDays(-5)
                },
                new PromotionOrder {
                    Id = 3, CreatedOn = DateTime.UtcNow.AddDays(-7)
                },
                new PromotionOrder {
                    Id = 4, CreatedOn = DateTime.UtcNow.AddDays(-9)
                },
                new PromotionOrder {
                    Id = 5, CreatedOn = DateTime.UtcNow.AddDays(-1)
                },
                new PromotionOrder {
                    Id = 6, CreatedOn = DateTime.UtcNow.AddDays(-10)
                },
                new PromotionOrder {
                    Id = 7, CreatedOn = DateTime.UtcNow.AddDays(-30)
                },
                new PromotionOrder {
                    Id = 8, CreatedOn = DateTime.UtcNow
                }
            };

            await context.PromotionOrders.AddRangeAsync(testingPromotions);

            await context.SaveChangesAsync();

            //Act
            var actual = await promotionsService.GetTheCountOfPromotionsForTheLastTenDaysAsync();

            //Assert
            Assert.Equal(expected[0], actual[0]);
            Assert.Equal(expected[1], actual[1]);
            Assert.Equal(expected[2], actual[2]);
            Assert.Equal(expected[3], actual[3]);
            Assert.Equal(expected[4], actual[4]);
            Assert.Equal(expected[5], actual[5]);
            Assert.Equal(expected[6], actual[6]);
            Assert.Equal(expected[7], actual[7]);
            Assert.Equal(expected[8], actual[8]);
            Assert.Equal(expected[9], actual[9]);
        }
Пример #2
0
        public async Task GetTheCountOfPromotionsForTheLastTenDaysAsync_WithValidData_ShouldReturnCorrectCollectionLength()
        {
            //Arrange
            var expectedLength = 10;

            var moqAdsService = new Mock <IAdsService>();
            var context       = InitializeContext.CreateContextForInMemory();

            promotionsService = new PromotionsService(context, moqAdsService.Object);

            //Act
            var actual = await promotionsService.GetTheCountOfPromotionsForTheLastTenDaysAsync();

            //Assert
            Assert.Equal(expectedLength, actual.Count);
        }