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);
        }
        public static async Task Returns_404_response_when_existing_request_cannot_be_found(
            bool acceptInterruption)
        {
            var controller = new DailyDetailsController(
                Mock.Of <IDateCalculator>(),
                CreateRequestRepository.WithRequests("user1", 12.July(2021), new List <Request>()),
                Mock.Of <ITriggerRepository>(),
                Mock.Of <IUserRepository>())
            {
                ControllerContext = CreateControllerContext.WithUsername("user1")
            };

            var result = await controller.PatchAsync(
                new StayInterruptedPatchRequest(12.July(2021), acceptInterruption));

            Assert.IsType <NotFoundResult>(result);
        }
        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);
        }