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); }
public static async Task Returns_updated_profile_after_updating() { const string UserId = "User1"; var existingUser = CreateUser.With(userId: UserId); var mockUserRepository = new Mock <IUserRepository>(); mockUserRepository .Setup(r => r.GetUser(UserId)) .ReturnsAsync(existingUser); var request = new ProfilePatchRequest( alternativeRegistrationNumber: "__NEW_ALTERNATIVE_REG__", registrationNumber: "__NEW_REG__", requestReminderEnabled: false, reservationReminderEnabled: true); var controller = new ProfilesController(mockUserRepository.Object) { ControllerContext = CreateControllerContext.WithUsername(UserId) }; var result = await controller.PatchAsync(request); var resultValue = GetResultValue <ProfileResponse>(result); Assert.NotNull(resultValue.Profile); Assert.Equal("__NEW_REG__", resultValue.Profile.RegistrationNumber); Assert.Equal("__NEW_ALTERNATIVE_REG__", resultValue.Profile.AlternativeRegistrationNumber); Assert.False(resultValue.Profile.RequestReminderEnabled); Assert.True(resultValue.Profile.ReservationReminderEnabled); }
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_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); }
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 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_profile_for_current_user() { var user = CreateUser.With( userId: "User1", registrationNumber: "AB123CDE", alternativeRegistrationNumber: "A999XYZ", requestReminderEnabled: true, reservationReminderEnabled: false); var controller = new ProfilesController(CreateUserRepository.WithUser("User1", user)) { ControllerContext = CreateControllerContext.WithUsername("User1") }; var result = await controller.GetAsync(); var resultValue = GetResultValue <ProfileResponse>(result); Assert.NotNull(resultValue.Profile); Assert.Equal("AB123CDE", resultValue.Profile.RegistrationNumber); Assert.Equal("A999XYZ", resultValue.Profile.AlternativeRegistrationNumber); Assert.True(resultValue.Profile.RequestReminderEnabled); Assert.False(resultValue.Profile.ReservationReminderEnabled); }
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 Saves_combined_updated_editable_properties_and_existing_readonly_properties() { const string UserId = "User1"; var existingUser = CreateUser.With( userId: UserId, alternativeRegistrationNumber: "Z999ABC", commuteDistance: 12.3m, emailAddress: "*****@*****.**", firstName: "John", lastName: "Doe", registrationNumber: "AB12CDE", requestReminderEnabled: true, reservationReminderEnabled: false); var mockUserRepository = new Mock <IUserRepository>(); mockUserRepository .Setup(r => r.GetUser(UserId)) .ReturnsAsync(existingUser); var request = new ProfilePatchRequest( alternativeRegistrationNumber: "__NEW_ALTERNATIVE_REG__", registrationNumber: "__NEW_REG__", requestReminderEnabled: false, reservationReminderEnabled: true); var controller = new ProfilesController(mockUserRepository.Object) { ControllerContext = CreateControllerContext.WithUsername(UserId) }; await controller.PatchAsync(request); mockUserRepository.Verify(r => r.GetUser(UserId), Times.Once); mockUserRepository.Verify( r => r.SaveUser( It.Is <User>(u => u.UserId == UserId && u.AlternativeRegistrationNumber == "__NEW_ALTERNATIVE_REG__" && u.CommuteDistance == 12.3m && u.EmailAddress == "*****@*****.**" && u.FirstName == "John" && u.LastName == "Doe" && u.RegistrationNumber == "__NEW_REG__" && u.RequestReminderEnabled == false && u.ReservationReminderEnabled == true)), Times.Once); mockUserRepository.VerifyNoOtherCalls(); }
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 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)); }
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); }
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 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 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); }
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)); }
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); }
public static async Task Defaults_reminder_flags_to_true_when_profile_is_updated() { const string UserId = "User1"; var existingUser = CreateUser.With( userId: UserId, requestReminderEnabled: false); var mockUserRepository = new Mock <IUserRepository>(); mockUserRepository .Setup(r => r.GetUser(UserId)) .ReturnsAsync(existingUser); var request = new ProfilePatchRequest( alternativeRegistrationNumber: "__NEW_ALTERNATIVE_REG__", registrationNumber: "__NEW_REG__", requestReminderEnabled: null, reservationReminderEnabled: null); var controller = new ProfilesController(mockUserRepository.Object) { ControllerContext = CreateControllerContext.WithUsername(UserId) }; await controller.PatchAsync(request); mockUserRepository.Verify(r => r.GetUser(UserId), Times.Once); mockUserRepository.Verify( r => r.SaveUser( It.Is <User>(u => u.UserId == UserId && u.RequestReminderEnabled == true && u.ReservationReminderEnabled == true)), Times.Once); mockUserRepository.VerifyNoOtherCalls(); }
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); }
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); }
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)); }
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)); }
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)); }
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); }