Exemple #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);
        }
        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);
        }
        public static async Task Returns_caption_based_on_requests()
        {
            var requests = new[]
            {
                new Request("USER1", 20.September(2021), RequestStatus.Allocated),

                new Request("USER1", 21.September(2021), RequestStatus.Allocated),
                new Request("USER2", 21.September(2021), RequestStatus.Interrupted),

                new Request("USER1", 22.September(2021), RequestStatus.Allocated),
                new Request("USER2", 22.September(2021), RequestStatus.Interrupted),

                new Request("USER1", 27.September(2021), RequestStatus.Interrupted),
                new Request("USER2", 27.September(2021), RequestStatus.Allocated),

                new Request("USER1", 28.September(2021), RequestStatus.SoftInterrupted),
                new Request("USER2", 28.September(2021), RequestStatus.Allocated),

                new Request("USER1", 29.September(2021), RequestStatus.HardInterrupted),
                new Request("USER2", 29.September(2021), RequestStatus.Allocated),

                new Request("USER1", 30.September(2021), RequestStatus.Cancelled),

                new Request("USER1", 1.October(2021), RequestStatus.Pending),
            };

            var reservations = new[]
            {
                new Reservation("USER1", 22.September(2021)),
            };

            var dateInterval = new DateInterval(FirstDate, LastDate).ToArray();

            var requestRepository      = CreateRequestRepository.WithRequests(dateInterval, requests);
            var reservationsRepository = CreateReservationRepository.WithReservations(dateInterval, reservations);

            var controller = new HistoryController(
                CreateDefaultDateCalculator(),
                requestRepository,
                reservationsRepository);

            var result = await controller.GetAsync("USER1", LastDate);

            var actual = GetResultValue <HistoryResponse>(result).History;

            Assert.Equal(string.Empty, GetDailyData(actual, 13.September(2021)));

            Assert.Equal("Allocated (uncontested)", GetDailyData(actual, 20.September(2021)));
            Assert.Equal("Allocated (contested)", GetDailyData(actual, 21.September(2021)));
            Assert.Equal("Allocated (reserved)", GetDailyData(actual, 22.September(2021)));

            Assert.Equal("Interrupted", GetDailyData(actual, 27.September(2021)));
            Assert.Equal("Interrupted (day ahead)", GetDailyData(actual, 28.September(2021)));
            Assert.Equal("Interrupted (stay interrupted)", GetDailyData(actual, 29.September(2021)));

            Assert.Equal("Cancelled", GetDailyData(actual, 30.September(2021)));
            Assert.Equal("Pending", GetDailyData(actual, 1.October(2021)));
        }
        public static async Task Returns_allocation_counts_based_on_requests()
        {
            var requests = new[]
            {
                new Request("USER1", 20.September(2021), RequestStatus.Allocated),

                new Request("USER1", 21.September(2021), RequestStatus.Allocated),
                new Request("USER2", 21.September(2021), RequestStatus.Interrupted),

                new Request("USER1", 22.September(2021), RequestStatus.Allocated),
                new Request("USER2", 22.September(2021), RequestStatus.Interrupted),

                new Request("USER1", 27.September(2021), RequestStatus.Interrupted),
                new Request("USER2", 27.September(2021), RequestStatus.Allocated),

                new Request("USER1", 28.September(2021), RequestStatus.SoftInterrupted),
                new Request("USER2", 28.September(2021), RequestStatus.Allocated),

                new Request("USER1", 29.September(2021), RequestStatus.HardInterrupted),
                new Request("USER2", 29.September(2021), RequestStatus.Allocated),

                new Request("USER1", 30.September(2021), RequestStatus.Cancelled),

                new Request("USER1", 1.October(2021), RequestStatus.Pending),
            };

            var reservations = new[]
            {
                new Reservation("USER1", 22.September(2021)),
            };

            var dateInterval = new DateInterval(FirstDate, LastDate).ToArray();

            var requestRepository      = CreateRequestRepository.WithRequests(dateInterval, requests);
            var reservationsRepository = CreateReservationRepository.WithReservations(dateInterval, reservations);

            var controller = new HistoryController(
                CreateDefaultDateCalculator(),
                requestRepository,
                reservationsRepository);

            var result = await controller.GetAsync("USER1", LastDate);

            var actual = GetResultValue <HistoryResponse>(result);

            Assert.Equal(1, actual.AllocatedContestedRequestsCount);
            Assert.Equal(4, actual.TotalContestedRequestsCount);
            Assert.Equal(0.25m, actual.AllocationRatio);
        }
        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 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));
        }
Exemple #8
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);
        }
Exemple #9
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);
        }
Exemple #10
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 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));
        }
        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);
        }
Exemple #13
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));
        }
Exemple #14
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);
        }
Exemple #15
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);
        }
Exemple #16
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);
        }
Exemple #17
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));
        }
Exemple #18
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));
        }
Exemple #19
0
        public static async Task Groups_allocated_and_interrupted_users_sorted_by_last_name()
        {
            var activeDates = new[] { 15.February(2021) };

            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"),
            };

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

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

            var result = await controller.GetAsync();

            var resultValue = GetResultValue <OverviewResponse>(result);

            var data = GetDailyData(resultValue.Overview, 15.February(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));
        }
Exemple #20
0
        public static async Task Get_summary_ignores_cancelled_requests()
        {
            var activeDates = new[] { 28.June(2021) };

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

            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.Null(data.Status);
            Assert.False(data.IsProblem);
        }