예제 #1
0
        public async Task GetLiveWeeksFor_WithRecentlyRegisteredUser_ShouldCallLastFmCorrectly()
        {
            // Arrange
            var context          = FakeThreeChartsContext.BuildInMemoryContext();
            var repo             = new ChartRepository(context);
            var lastFmMock       = new FakeLastFmService();
            var chartDateService = new ChartDateService(context);
            var service          = new ChartService(repo, chartDateService, lastFmMock.Object);

            var userRegisterDate = new DateTime(2020, 4, 21);
            var endDate          = new DateTime(2020, 4, 23, 23, 59, 59);
            var now = new DateTime(2020, 4, 22);

            var user = new User
            {
                UserName     = "******",
                IanaTimezone = "America/Sao_Paulo",
                RegisteredAt = userRegisterDate,
            };

            await context.Users.AddAsync(user);

            await context.SaveChangesAsync();

            // Act
            await service.GetLiveWeekFor(user, now);

            // Assert
            lastFmMock.Fake
            .Verify(lfm => lfm.GetWeeklyTrackChart(
                        It.Is <string>(s => s == "edxds"),
                        It.Is <long>(l => l == new DateTimeOffset(userRegisterDate).ToUnixTimeSeconds()),
                        It.Is <long>(l => l == new DateTimeOffset(endDate).ToUnixTimeSeconds()),
                        It.IsAny <CancellationToken?>()));
        }