示例#1
0
        public static async Task Returns_updated_requests_after_saving()
        {
            var activeDates = new[] { 2.February(2021), 3.February(2021) };

            var returnedRequests = new[] { new Request(UserId, 2.February(2021), RequestStatus.Pending) };

            var mockRequestRepository =
                CreateRequestRepository.MockWithRequests(UserId, activeDates, returnedRequests);

            mockRequestRepository
            .Setup(r => r.SaveRequests(It.IsAny <IReadOnlyCollection <Request> >(), It.IsAny <IReadOnlyCollection <User> >()))
            .Returns(Task.CompletedTask);

            var patchRequest =
                new RequestsPatchRequest(new[] { new RequestsPatchRequestDailyData(2.February(2021), true) });

            var controller = new RequestsController(
                CreateDateCalculator.WithActiveDates(activeDates),
                mockRequestRepository.Object,
                Mock.Of <ITriggerRepository>(),
                CreateUserRepository.WithUsers(DefaultUsers))
            {
                ControllerContext = CreateControllerContext.WithUsername(UserId)
            };

            var result = await controller.PatchAsync(patchRequest);

            var resultValue = GetResultValue <RequestsResponse>(result);

            var day1data = GetDailyData(resultValue.Requests, 2.February(2021));
            var day2data = GetDailyData(resultValue.Requests, 3.February(2021));

            Assert.True(day1data.Requested);
            Assert.False(day2data.Requested);
        }
示例#2
0
        public static async Task Does_not_update_requests_outside_active_date_range()
        {
            var activeDates = new[] { 2.February(2021), 3.February(2021) };

            var mockRequestRepository =
                CreateRequestRepository.MockWithRequests(UserId, activeDates, new List <Request>());

            mockRequestRepository
            .Setup(r => r.SaveRequests(It.IsAny <IReadOnlyCollection <Request> >(), It.IsAny <IReadOnlyCollection <User> >()))
            .Returns(Task.CompletedTask);

            var patchRequest = new RequestsPatchRequest(new[]
            {
                new RequestsPatchRequestDailyData(1.February(2021), true),
                new RequestsPatchRequestDailyData(4.February(2021), true)
            });

            var controller = new RequestsController(
                CreateDateCalculator.WithActiveDates(activeDates),
                mockRequestRepository.Object,
                Mock.Of <ITriggerRepository>(),
                CreateUserRepository.WithUsers(DefaultUsers))
            {
                ControllerContext = CreateControllerContext.WithUsername(UserId)
            };

            await controller.PatchAsync(patchRequest);

            CheckSavedRequests(mockRequestRepository, new List <Request>(), DefaultUsers);
        }
示例#3
0
        public static async Task Updates_data_for_given_user_when_specified()
        {
            var activeDates = new[] { 2.February(2021) };

            var mockRequestRepository =
                CreateRequestRepository.MockWithRequests(UserId, activeDates, new List <Request>());

            mockRequestRepository
            .Setup(r => r.SaveRequests(It.IsAny <IReadOnlyCollection <Request> >(), It.IsAny <IReadOnlyCollection <User> >()))
            .Returns(Task.CompletedTask);

            var patchRequest = new RequestsPatchRequest(new[]
            {
                new RequestsPatchRequestDailyData(2.February(2021), true),
                new RequestsPatchRequestDailyData(3.February(2021), false),
            });

            var controller = new RequestsController(
                CreateDateCalculator.WithActiveDates(activeDates),
                mockRequestRepository.Object,
                Mock.Of <ITriggerRepository>(),
                CreateUserRepository.WithUserExistsAndUsers(UserId, true, DefaultUsers));

            await controller.PatchByIdAsync(UserId, patchRequest);

            var expectedSavedRequests = new[] { new Request(UserId, 2.February(2021), RequestStatus.Pending) };

            CheckSavedRequests(mockRequestRepository, expectedSavedRequests, DefaultUsers);
        }
示例#4
0
        public static async Task Adds_recalculation_trigger_when_saving_requests()
        {
            var activeDates = new[] { 2.February(2021) };

            var mockRequestRepository =
                CreateRequestRepository.MockWithRequests(UserId, activeDates, new List <Request>());

            mockRequestRepository
            .Setup(r => r.SaveRequests(It.IsAny <IReadOnlyCollection <Request> >(), It.IsAny <IReadOnlyCollection <User> >()))
            .Returns(Task.CompletedTask);

            var mockTriggerRepository = new Mock <ITriggerRepository>();

            var patchRequest = new RequestsPatchRequest(new List <RequestsPatchRequestDailyData>());

            var controller = new RequestsController(
                CreateDateCalculator.WithActiveDates(activeDates),
                mockRequestRepository.Object,
                mockTriggerRepository.Object,
                CreateUserRepository.WithUsers(DefaultUsers))
            {
                ControllerContext = CreateControllerContext.WithUsername(UserId)
            };

            await controller.PatchAsync(patchRequest);

            mockTriggerRepository.Verify(r => r.AddTrigger(), Times.Once);
        }
        public static async Task Returns_updated_daily_details_when_updating_interruption_status(
            RequestStatus initialRequestStatus,
            RequestStatus updatedRequestStatus,
            bool value)
        {
            var activeDates = new[] { 28.June(2021), 29.June(2021) };

            var dateCalculator = CreateDateCalculator.WithActiveDates(activeDates);

            var initialRequest = new Request("user1", 28.June(2021), initialRequestStatus);

            var updatedRequests = new[]
            {
                new Request("user1", 28.June(2021), updatedRequestStatus),
                new Request("user1", 29.June(2021), RequestStatus.Interrupted),
            };

            var mockRequestRepository =
                CreateRequestRepository.MockWithRequests("user1", activeDates, new[] { initialRequest });

            mockRequestRepository
            .Setup(r => r.GetRequests("user1", 28.June(2021), 28.June(2021)))
            .ReturnsAsync(new[] { initialRequest });
            mockRequestRepository
            .Setup(r => r.SaveRequests(It.IsAny <IReadOnlyCollection <Request> >(), It.IsAny <IReadOnlyCollection <User> >()))
            .Returns(Task.CompletedTask);
            mockRequestRepository
            .Setup(r => r.GetRequests(28.June(2021), 29.June(2021)))
            .ReturnsAsync(updatedRequests);

            var users = new[]
            {
                CreateUser.With(userId: "user1", firstName: "Cathie", lastName: "Phoenix"),
            };

            var controller = new DailyDetailsController(
                dateCalculator,
                mockRequestRepository.Object,
                Mock.Of <ITriggerRepository>(),
                CreateUserRepository.WithUsers(users))
            {
                ControllerContext = CreateControllerContext.WithUsername("user1")
            };

            var result = await controller.PatchAsync(
                new StayInterruptedPatchRequest(28.June(2021), value));

            var resultValue = GetResultValue <DailyDetailsResponse>(result);

            var actual = GetDailyData(resultValue.Details, 28.June(2021)).StayInterruptedStatus;

            Assert.True(actual.IsAllowed);
            Assert.Equal(value, actual.IsSet);
        }
        public static async Task Updates_interruption_status(
            RequestStatus initialRequestStatus,
            bool acceptInterruption,
            RequestStatus expectedRequestStatus)
        {
            var activeDates = new[] { 12.July(2021) };

            var dateCalculator = CreateDateCalculator.WithActiveDates(activeDates);

            var requestDate = activeDates.Single();

            var existingRequests = new[] { new Request("user1", requestDate, initialRequestStatus) };

            var mockRequestRepository = CreateRequestRepository.MockWithRequests("user1", activeDates, existingRequests);

            mockRequestRepository
            .Setup(r => r.SaveRequests(It.IsAny <IReadOnlyCollection <Request> >(), It.IsAny <IReadOnlyCollection <User> >()))
            .Returns(Task.CompletedTask);
            mockRequestRepository
            .Setup(r => r.GetRequests(It.IsAny <LocalDate>(), It.IsAny <LocalDate>()))
            .ReturnsAsync(new List <Request>());

            var users = new[]
            {
                CreateUser.With(userId: "user1", firstName: "Cathie", lastName: "Phoenix"),
            };

            var controller = new DailyDetailsController(
                dateCalculator,
                mockRequestRepository.Object,
                Mock.Of <ITriggerRepository>(),
                CreateUserRepository.WithUsers(users))
            {
                ControllerContext = CreateControllerContext.WithUsername("user1")
            };

            await controller.PatchAsync(
                new StayInterruptedPatchRequest(requestDate, acceptInterruption));

            var expectedRequests = new[] { new Request("user1", requestDate, expectedRequestStatus) };

            mockRequestRepository.Verify(r => r.SaveRequests(
                                             It.Is <IReadOnlyCollection <Request> >(actual => CheckRequests(expectedRequests, actual.ToList())),
                                             users),
                                         Times.Once);
        }
示例#7
0
        public static async Task Updates_requests_with_last_given_value_for_each_date()
        {
            var activeDates = new[] { 2.February(2021), 3.February(2021) };

            var mockRequestRepository =
                CreateRequestRepository.MockWithRequests(UserId, activeDates, new List <Request>());

            mockRequestRepository
            .Setup(r => r.SaveRequests(It.IsAny <IReadOnlyCollection <Request> >(), It.IsAny <IReadOnlyCollection <User> >()))
            .Returns(Task.CompletedTask);

            var patchRequest = new RequestsPatchRequest(new[]
            {
                new RequestsPatchRequestDailyData(2.February(2021), true),
                new RequestsPatchRequestDailyData(2.February(2021), false),
                new RequestsPatchRequestDailyData(2.February(2021), true),
                new RequestsPatchRequestDailyData(3.February(2021), false),
                new RequestsPatchRequestDailyData(3.February(2021), true),
                new RequestsPatchRequestDailyData(3.February(2021), false),
            });

            var controller = new RequestsController(
                CreateDateCalculator.WithActiveDates(activeDates),
                mockRequestRepository.Object,
                Mock.Of <ITriggerRepository>(),
                CreateUserRepository.WithUsers(DefaultUsers))
            {
                ControllerContext = CreateControllerContext.WithUsername(UserId)
            };

            await controller.PatchAsync(patchRequest);

            var expectedSavedRequests = new[]
            {
                new Request(UserId, 2.February(2021), RequestStatus.Pending),
                new Request(UserId, 3.February(2021), RequestStatus.Cancelled),
            };

            CheckSavedRequests(mockRequestRepository, expectedSavedRequests, DefaultUsers);
        }
        public static async Task Creates_recalculation_trigger_when_updating_interruption_status()
        {
            var activeDates = new[] { 28.June(2021) };

            var dateCalculator = CreateDateCalculator.WithActiveDates(activeDates);

            var requestDate = activeDates.Single();

            var existingRequests = new[] { new Request("user1", requestDate, RequestStatus.SoftInterrupted) };

            var mockRequestRepository = CreateRequestRepository.MockWithRequests("user1", activeDates, existingRequests);

            mockRequestRepository
            .Setup(r => r.SaveRequests(It.IsAny <IReadOnlyCollection <Request> >(), It.IsAny <IReadOnlyCollection <User> >()))
            .Returns(Task.CompletedTask);
            mockRequestRepository
            .Setup(r => r.GetRequests(It.IsAny <LocalDate>(), It.IsAny <LocalDate>()))
            .ReturnsAsync(new List <Request>());

            var users = new[]
            {
                CreateUser.With(userId: "user1", firstName: "Cathie", lastName: "Phoenix"),
            };

            var mockTriggerRepository = new Mock <ITriggerRepository>();

            var controller = new DailyDetailsController(
                dateCalculator,
                mockRequestRepository.Object,
                mockTriggerRepository.Object,
                CreateUserRepository.WithUsers(users))
            {
                ControllerContext = CreateControllerContext.WithUsername("user1")
            };

            await controller.PatchAsync(new StayInterruptedPatchRequest(requestDate, true));

            mockTriggerRepository.Verify(r => r.AddTrigger(), Times.Once);
        }