Пример #1
0
        public static async Task Get_summary_returns_request_status(
            RequestStatus requestStatus,
            SummaryStatus expectedSummaryStatus,
            bool expectedIsProblem)
        {
            var activeDates = new[] { 28.June(2021) };

            var requests = new[] { new Request("user1", 28.June(2021), requestStatus) };

            var dateCalculator = CreateDateCalculator.WithActiveDates(activeDates);

            var controller = new SummaryController(
                dateCalculator,
                CreateRequestRepository.WithRequests("user1", activeDates, requests))
            {
                ControllerContext = CreateControllerContext.WithUsername("user1")
            };

            var result = await controller.GetSummaryAsync();

            var resultValue = GetResultValue <SummaryResponse>(result);

            var data = GetDailyData(resultValue.Summary, 28.June(2021));

            Assert.Equal(expectedSummaryStatus, data.Status);
            Assert.Equal(expectedIsProblem, data.IsProblem);
        }
Пример #2
0
        public static async Task Returns_sorted_list_of_users()
        {
            var activeDates = new[] { 15.February(2021) };

            var controller = new ReservationsController(
                CreateConfigurationRepository.WithDefaultConfiguration(),
                CreateDateCalculator.WithActiveDates(activeDates),
                CreateReservationRepository.WithReservations(activeDates, new List <Reservation>()),
                CreateUserRepository.WithUsers(DefaultUsers));

            var result = await controller.GetAsync();

            var resultValue = GetResultValue <ReservationsResponse>(result);

            Assert.NotNull(resultValue.Users);

            var actualUsers = resultValue.Users.ToArray();

            Assert.Equal(3, actualUsers.Length);

            Assert.Equal("User2", actualUsers[0].UserId);
            Assert.Equal("Kendricks Hawke", actualUsers[0].Name);

            Assert.Equal("User1", actualUsers[1].UserId);
            Assert.Equal("Silvester Probet", actualUsers[1].Name);

            Assert.Equal("User3", actualUsers[2].UserId);
            Assert.Equal("Rupert Trollope", actualUsers[2].Name);
        }
Пример #3
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);
        }
Пример #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);
        }
Пример #5
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);
        }
Пример #6
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);
        }
        public static async Task Returns_stay_interrupted_status_when_no_user_requests_exist()
        {
            var activeDates = new[] { 12.July(2021) };

            var dateCalculator = CreateDateCalculator.WithActiveDates(activeDates);

            var requests = new[]
            {
                new Request("user2", 12.July(2021), RequestStatus.SoftInterrupted),
            };

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

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

            var result = await controller.GetAsync();

            var resultValue = GetResultValue <DailyDetailsResponse>(result);

            var actual = GetDailyData(resultValue.Details, 12.July(2021)).StayInterruptedStatus;

            Assert.False(actual.IsAllowed);
            Assert.False(actual.IsSet);
        }
Пример #8
0
        public static async Task Does_not_save_reservations_outside_active_date_range()
        {
            var activeDates = new[] { 2.February(2021), 3.February(2021) };

            var mockReservationRepository =
                CreateReservationRepository.MockWithReservations(activeDates, new List <Reservation>());

            mockReservationRepository
            .Setup(r => r.SaveReservations(
                       It.IsAny <IReadOnlyCollection <Reservation> >(),
                       It.IsAny <IReadOnlyCollection <User> >()))
            .Returns(Task.CompletedTask);

            var patchRequest = new ReservationsPatchRequest(new[]
            {
                new ReservationsPatchRequestDailyData(1.February(2021), new List <string> {
                    "User1", "User2"
                }),
                new ReservationsPatchRequestDailyData(4.February(2021), new List <string> {
                    "User1", "User2"
                }),
            });

            var controller = new ReservationsController(
                CreateConfigurationRepository.WithDefaultConfiguration(),
                CreateDateCalculator.WithActiveDates(activeDates),
                mockReservationRepository.Object,
                CreateUserRepository.WithUsers(DefaultUsers));

            await controller.PatchAsync(patchRequest);

            CheckSavedReservations(mockReservationRepository, new List <Reservation>());
        }
Пример #9
0
        public static async Task Returns_previously_saved_reservations()
        {
            var activeDates = new[] { 15.February(2021), 16.February(2021), 18.February(2021) };

            var reservations = new[]
            {
                new Reservation("User1", 15.February(2021)),
                new Reservation("User2", 15.February(2021)),
                new Reservation("User3", 15.February(2021)),
            };

            var controller = new ReservationsController(
                CreateConfigurationRepository.WithDefaultConfiguration(),
                CreateDateCalculator.WithActiveDates(activeDates),
                CreateReservationRepository.WithReservations(activeDates, reservations),
                CreateUserRepository.WithUsers(DefaultUsers));

            var result = await controller.GetAsync();

            var resultValue = GetResultValue <ReservationsResponse>(result);

            var data = GetDailyData(resultValue.Reservations, 15.February(2021));

            Assert.Equal(new[] { "User1", "User2", "User3" }, data.UserIds);
        }
        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 Highlights_active_user()
        {
            var activeDates = new[] { 16.July(2021), 17.July(2021), 18.July(2021) };

            var dateCalculator = CreateDateCalculator.WithActiveDates(activeDates);

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

            var requests = new[]
            {
                new Request("user1", 16.July(2021), RequestStatus.Allocated),
                new Request("user2", 16.July(2021), RequestStatus.SoftInterrupted),
                new Request("user1", 17.July(2021), RequestStatus.Interrupted),
                new Request("user2", 17.July(2021), RequestStatus.Allocated),
                new Request("user2", 18.July(2021), RequestStatus.Pending),
            };

            var controller = new DailyDetailsController(
                dateCalculator,
                CreateRequestRepository.WithRequests(activeDates, requests),
                Mock.Of <ITriggerRepository>(),
                CreateUserRepository.WithUsers(users))
            {
                ControllerContext = CreateControllerContext.WithUsername("user2")
            };

            var result = await controller.GetAsync();

            var resultValue = GetResultValue <DailyDetailsResponse>(result);

            var day1Data = GetDailyData(resultValue.Details, 16.July(2021));
            var day2Data = GetDailyData(resultValue.Details, 17.July(2021));
            var day3Data = GetDailyData(resultValue.Details, 18.July(2021));

            Assert.False(day1Data.AllocatedUsers.Single().IsHighlighted);
            Assert.True(day1Data.InterruptedUsers.Single().IsHighlighted);

            Assert.True(day2Data.AllocatedUsers.Single().IsHighlighted);
            Assert.False(day2Data.InterruptedUsers.Single().IsHighlighted);

            Assert.True(day3Data.PendingUsers.Single().IsHighlighted);
        }
        public static async Task Groups_allocated_and_interrupted_users_sorted_by_last_name()
        {
            var activeDates = new[] { 12.July(2021) };

            var dateCalculator = CreateDateCalculator.WithActiveDates(activeDates);

            var users = new[]
            {
                CreateUser.With(userId: "user1", firstName: "Cathie", lastName: "Phoenix"),
                CreateUser.With(userId: "user2", firstName: "Hynda", lastName: "Lindback"),
                CreateUser.With(userId: "user3", firstName: "Shannen", lastName: "Muddicliffe"),
                CreateUser.With(userId: "user4", firstName: "Marco", lastName: "Call"),
                CreateUser.With(userId: "user5", firstName: "Eugenio", lastName: "Veazey"),
                CreateUser.With(userId: "user6", firstName: "Evangelin", lastName: "Calway"),
            };

            var requests = new[]
            {
                new Request("user1", 12.July(2021), RequestStatus.Allocated),
                new Request("user2", 12.July(2021), RequestStatus.Allocated),
                new Request("user3", 12.July(2021), RequestStatus.Interrupted),
                new Request("user4", 12.July(2021), RequestStatus.SoftInterrupted),
                new Request("user5", 12.July(2021), RequestStatus.Pending),
                new Request("user6", 12.July(2021), RequestStatus.Pending),
            };

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

            var result = await controller.GetAsync();

            var resultValue = GetResultValue <DailyDetailsResponse>(result);

            var data = GetDailyData(resultValue.Details, 12.July(2021));

            Assert.Equal(new[] { "Hynda Lindback", "Cathie Phoenix" }, data.AllocatedUsers.Select(u => u.Name));
            Assert.Equal(new[] { "Marco Call", "Shannen Muddicliffe" }, data.InterruptedUsers.Select(u => u.Name));
            Assert.Equal(new[] { "Evangelin Calway", "Eugenio Veazey" }, data.PendingUsers.Select(u => u.Name));
        }
Пример #14
0
        public static async Task Returns_short_lead_time_spaces_count()
        {
            var configuration = CreateConfiguration.With(shortLeadTimeSpaces: 2);

            var activeDates = new[] { 15.February(2021) };

            var controller = new ReservationsController(
                CreateConfigurationRepository.WithConfiguration(configuration),
                CreateDateCalculator.WithActiveDates(activeDates),
                CreateReservationRepository.WithReservations(activeDates, new List <Reservation>()),
                CreateUserRepository.WithUsers(new List <User>()));

            var result = await controller.GetAsync();

            var resultValue = GetResultValue <ReservationsResponse>(result);

            Assert.Equal(2, resultValue.ShortLeadTimeSpaces);
        }
Пример #15
0
        public static async Task Returns_updated_reservations_after_saving()
        {
            var activeDates = new[] { 2.February(2021), 3.February(2021) };

            var returnedReservations = new[]
            {
                new Reservation("User1", 2.February(2021)),
                new Reservation("User2", 2.February(2021)),
                new Reservation("User2", 3.February(2021)),
                new Reservation("User3", 3.February(2021)),
            };

            var mockReservationRepository =
                CreateReservationRepository.MockWithReservations(activeDates, returnedReservations);

            mockReservationRepository
            .Setup(r => r.SaveReservations(
                       It.IsAny <IReadOnlyCollection <Reservation> >(),
                       It.IsAny <IReadOnlyCollection <User> >()))
            .Returns(Task.CompletedTask);

            var patchRequest = new ReservationsPatchRequest(new[]
            {
                new ReservationsPatchRequestDailyData(2.February(2021), new[] { "User1", "User2" })
            });

            var controller = new ReservationsController(
                CreateConfigurationRepository.WithDefaultConfiguration(),
                CreateDateCalculator.WithActiveDates(activeDates),
                mockReservationRepository.Object,
                CreateUserRepository.WithUsers(DefaultUsers));

            var result = await controller.PatchAsync(patchRequest);

            var resultValue = GetResultValue <ReservationsResponse>(result);

            var day1Data = GetDailyData(resultValue.Reservations, 2.February(2021));
            var day2Data = GetDailyData(resultValue.Reservations, 3.February(2021));

            Assert.Equal(new[] { "User1", "User2" }, day1Data.UserIds);
            Assert.Equal(new[] { "User2", "User3" }, day2Data.UserIds);
        }
Пример #16
0
        public static async Task Returns_data_for_given_user_when_specified()
        {
            var activeDates = new[] { 2.February(2021) };

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

            var controller = new RequestsController(
                CreateDateCalculator.WithActiveDates(activeDates),
                CreateRequestRepository.WithRequests(UserId, activeDates, requests),
                Mock.Of <ITriggerRepository>(),
                CreateUserRepository.WithUserExists(UserId, true));

            var result = await controller.GetByIdAsync(UserId);

            var resultValue = GetResultValue <RequestsResponse>(result);

            var data = GetDailyData(resultValue.Requests, 2.February(2021));

            Assert.True(data.Requested);
        }
Пример #17
0
        public static async Task Returns_empty_reservations_object_when_no_reservations_exist()
        {
            var activeDates = new[] { 15.February(2021) };

            var controller = new ReservationsController(
                CreateConfigurationRepository.WithDefaultConfiguration(),
                CreateDateCalculator.WithActiveDates(activeDates),
                CreateReservationRepository.WithReservations(activeDates, new List <Reservation>()),
                CreateUserRepository.WithUsers(new List <User>()));

            var result = await controller.GetAsync();

            var resultValue = GetResultValue <ReservationsResponse>(result);

            var data = GetDailyData(resultValue.Reservations, 15.February(2021));

            Assert.NotNull(data.UserIds);

            Assert.Empty(data.UserIds);
        }
        public static async Task Returns_details_data_for_each_active_date()
        {
            var activeDates = new[] { 12.July(2021), 13.July(2021), 16.July(2021) };

            var dateCalculator = CreateDateCalculator.WithActiveDates(activeDates);

            var controller = new DailyDetailsController(
                dateCalculator,
                CreateRequestRepository.WithRequests(activeDates, new List <Request>()),
                Mock.Of <ITriggerRepository>(),
                CreateUserRepository.WithUsers(new List <User>()))
            {
                ControllerContext = CreateControllerContext.WithUsername("user1")
            };

            var result = await controller.GetAsync();

            var resultValue = GetResultValue <DailyDetailsResponse>(result);

            Assert.Equal(activeDates, resultValue.Details.Select(d => d.LocalDate));
        }
Пример #19
0
        public static async Task Returns_empty_object_when_no_requests_exist()
        {
            var activeDates = new[] { 15.February(2021) };

            var controller = new OverviewController(
                CreateDateCalculator.WithActiveDates(activeDates),
                CreateRequestRepository.WithRequests(activeDates, new List <Request>()),
                CreateUserRepository.WithUsers(new List <User>()))
            {
                ControllerContext = CreateControllerContext.WithUsername("user1")
            };

            var result = await controller.GetAsync();

            var resultValue = GetResultValue <OverviewResponse>(result);

            var data = GetDailyData(resultValue.Overview, 15.February(2021));

            Assert.Empty(data.AllocatedUsers);
            Assert.Empty(data.InterruptedUsers);
        }
Пример #20
0
        public static async Task Returns_false_when_space_has_not_been_requested()
        {
            var activeDates = new[] { 2.February(2021) };

            var controller = new RequestsController(
                CreateDateCalculator.WithActiveDates(activeDates),
                CreateRequestRepository.WithRequests(UserId, activeDates, new List <Request>()),
                Mock.Of <ITriggerRepository>(),
                CreateUserRepository.WithUserExists(UserId, true))
            {
                ControllerContext = CreateControllerContext.WithUsername(UserId)
            };

            var result = await controller.GetAsync();

            var resultValue = GetResultValue <RequestsResponse>(result);

            var data = GetDailyData(resultValue.Requests, 2.February(2021));

            Assert.False(data.Requested);
        }
        public static async Task Ignores_cancelled_requests()
        {
            var activeDates = new[] { 16.July(2021), 17.July(2021) };

            var dateCalculator = CreateDateCalculator.WithActiveDates(activeDates);

            var users = new[]
            {
                CreateUser.With(userId: "user1", firstName: "Cathie", lastName: "Phoenix"),
                CreateUser.With(userId: "user2", firstName: "Hynda", lastName: "Lindback"),
                CreateUser.With(userId: "user3", firstName: "Shannen", lastName: "Muddicliffe"),
            };

            var requests = new[]
            {
                new Request("user1", 16.July(2021), RequestStatus.Cancelled),
                new Request("user2", 16.July(2021), RequestStatus.Cancelled),
                new Request("user3", 17.July(2021), RequestStatus.Cancelled),
            };

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

            var result = await controller.GetAsync();

            var resultValue = GetResultValue <DailyDetailsResponse>(result);

            var day1Data = GetDailyData(resultValue.Details, 16.July(2021));
            var day2Data = GetDailyData(resultValue.Details, 17.July(2021));

            Assert.Empty(day1Data.AllocatedUsers);
            Assert.Empty(day1Data.InterruptedUsers);
            Assert.Empty(day2Data.PendingUsers);
        }
Пример #22
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);
        }
Пример #23
0
        public static async Task Returns_overview_data_for_each_active_date()
        {
            var activeDates = new[] { 15.February(2021), 16.February(2021), 18.February(2021) };

            var controller = new OverviewController(
                CreateDateCalculator.WithActiveDates(activeDates),
                CreateRequestRepository.WithRequests(activeDates, new List <Request>()),
                CreateUserRepository.WithUsers(new List <User>()))
            {
                ControllerContext = CreateControllerContext.WithUsername("user1")
            };

            var result = await controller.GetAsync();

            var resultValue = GetResultValue <OverviewResponse>(result);

            var visibleDays = GetVisibleDays(resultValue.Overview);

            Assert.Equal(activeDates, visibleDays.Select(d => d.LocalDate));

            Assert.All(visibleDays, d => Assert.NotNull(d.Data));
        }
Пример #24
0
        public static async Task Highlights_active_user()
        {
            var activeDates = new[] { 15.February(2021), 16.February(2021) };

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

            var requests = new[]
            {
                new Request("user1", 15.February(2021), RequestStatus.Allocated),
                new Request("user2", 15.February(2021), RequestStatus.SoftInterrupted),
                new Request("user1", 16.February(2021), RequestStatus.Interrupted),
                new Request("user2", 16.February(2021), RequestStatus.Allocated),
            };

            var controller = new OverviewController(
                CreateDateCalculator.WithActiveDates(activeDates),
                CreateRequestRepository.WithRequests(activeDates, requests),
                CreateUserRepository.WithUsers(users))
            {
                ControllerContext = CreateControllerContext.WithUsername("user2")
            };

            var result = await controller.GetAsync();

            var resultValue = GetResultValue <OverviewResponse>(result);

            var day1Data = GetDailyData(resultValue.Overview, 15.February(2021));
            var day2Data = GetDailyData(resultValue.Overview, 16.February(2021));

            Assert.False(day1Data.AllocatedUsers.Single().IsHighlighted);
            Assert.True(day1Data.InterruptedUsers.Single().IsHighlighted);

            Assert.True(day2Data.AllocatedUsers.Single().IsHighlighted);
            Assert.False(day2Data.InterruptedUsers.Single().IsHighlighted);
        }
        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);
        }
Пример #26
0
        public static async Task Returns_reservations_data_for_each_active_date()
        {
            var activeDates = new[] { 15.February(2021), 16.February(2021), 18.February(2021) };

            var controller = new ReservationsController(
                CreateConfigurationRepository.WithDefaultConfiguration(),
                CreateDateCalculator.WithActiveDates(activeDates),
                CreateReservationRepository.WithReservations(activeDates, new List <Reservation>()),
                CreateUserRepository.WithUsers(DefaultUsers));

            var result = await controller.GetAsync();

            var resultValue = GetResultValue <ReservationsResponse>(result);

            Assert.NotNull(resultValue.Reservations);

            var visibleDays = GetVisibleDays(resultValue.Reservations);

            Assert.Equal(activeDates, visibleDays.Select(d => d.LocalDate));

            Assert.All(visibleDays, d => Assert.NotNull(d.Data));
        }
Пример #27
0
        public static async Task Get_summary_returns_null_status_when_no_request_exists()
        {
            var activeDates = new[] { 28.June(2021) };

            var dateCalculator = CreateDateCalculator.WithActiveDates(activeDates);

            var controller = new SummaryController(
                dateCalculator,
                CreateRequestRepository.WithRequests("user1", activeDates, new List <Request>()))
            {
                ControllerContext = CreateControllerContext.WithUsername("user1")
            };

            var result = await controller.GetSummaryAsync();

            var resultValue = GetResultValue <SummaryResponse>(result);

            var data = GetDailyData(resultValue.Summary, 28.June(2021));

            Assert.Null(data.Status);
            Assert.False(data.IsProblem);
        }
Пример #28
0
        public static async Task Returns_requests_data_for_each_active_date()
        {
            var activeDates = new[] { 2.February(2021), 3.February(2021), 4.February(2021) };

            var controller = new RequestsController(
                CreateDateCalculator.WithActiveDates(activeDates),
                CreateRequestRepository.WithRequests(UserId, activeDates, new List <Request>()),
                Mock.Of <ITriggerRepository>(),
                CreateUserRepository.WithUserExists(UserId, true))
            {
                ControllerContext = CreateControllerContext.WithUsername(UserId)
            };

            var result = await controller.GetAsync();

            var resultValue = GetResultValue <RequestsResponse>(result);

            var visibleDays = GetVisibleDays(resultValue.Requests);

            Assert.Equal(activeDates, visibleDays.Select(d => d.LocalDate));

            Assert.All(visibleDays, d => Assert.NotNull(d.Data));
        }
Пример #29
0
        public static async Task Ignores_cancelled_requests()
        {
            var activeDates = new[] { 15.February(2021) };

            var requests = new[] { new Request("user1", 15.February(2021), RequestStatus.Cancelled) };

            var controller = new OverviewController(
                CreateDateCalculator.WithActiveDates(activeDates),
                CreateRequestRepository.WithRequests(activeDates, requests),
                CreateUserRepository.WithUsers(new List <User>()))
            {
                ControllerContext = CreateControllerContext.WithUsername("user1")
            };

            var result = await controller.GetAsync();

            var resultValue = GetResultValue <OverviewResponse>(result);

            var data = GetDailyData(resultValue.Overview, 15.February(2021));

            Assert.Empty(data.AllocatedUsers);
            Assert.Empty(data.InterruptedUsers);
        }
Пример #30
0
        public static async Task Get_summary_returns_summary_data_for_each_active_date()
        {
            var activeDates = new[] { 28.June(2021), 29.June(2021), 1.July(2021) };

            var dateCalculator = CreateDateCalculator.WithActiveDates(activeDates);

            var controller = new SummaryController(
                dateCalculator,
                CreateRequestRepository.WithRequests("user1", activeDates, new List <Request>()))
            {
                ControllerContext = CreateControllerContext.WithUsername("user1")
            };

            var result = await controller.GetSummaryAsync();

            var resultValue = GetResultValue <SummaryResponse>(result);

            var visibleDays = GetVisibleDays(resultValue.Summary);

            Assert.Equal(activeDates, visibleDays.Select(d => d.LocalDate));

            Assert.All(visibleDays, d => Assert.NotNull(d.Data));
        }