public async Task Should_send_email_for_new_individual_participant_added()
        {
            var participant = new BookingsApi.Contract.Requests.ParticipantRequest
            {
                Username        = string.Empty, // New participant
                CaseRoleName    = "Applicant",
                HearingRoleName = "Individual"
            };

            var newUserName = "******";
            // setup response
            var hearingDetailsResponse = HearingResponseBuilder.Build()
                                         .WithParticipant("Individual", newUserName);

            _bookingsApiClient.Setup(x => x.BookNewHearingAsync(It.IsAny <BookNewHearingRequest>()))
            .ReturnsAsync(hearingDetailsResponse);
            _userAccountService
            .Setup(x => x.UpdateParticipantUsername(It.IsAny <BookingsApi.Contract.Requests.ParticipantRequest>()))
            .Callback <BookingsApi.Contract.Requests.ParticipantRequest>(p => { p.Username = newUserName; })
            .ReturnsAsync(new User {
                UserName = newUserName, Password = "******"
            });

            await PostWithParticipants(participant);

            _notificationApiMock.Verify(x => x.CreateNewNotificationAsync(It.Is <AddNotificationRequest>(request =>
                                                                                                         request.NotificationType == NotificationType.CreateIndividual)), Times.Once);
        }
        public async Task Should_pass_current_user_as_created_by_to_service()
        {
            const string CURRENT_USERNAME = "******";

            _userIdentity.Setup(x => x.GetUserIdentityName()).Returns(CURRENT_USERNAME);

            // setup response
            var hearingDetailsResponse = HearingResponseBuilder.Build()
                                         .WithParticipant("Representative")
                                         .WithParticipant("Individual");

            _bookingsApiClient.Setup(x => x.BookNewHearingAsync(It.IsAny <BookNewHearingRequest>()))
            .ReturnsAsync(hearingDetailsResponse);

            var result = await PostNewHearing();

            result.Result.Should().BeOfType <CreatedResult>();
            var createdResult = (CreatedResult)result.Result;

            createdResult.Location.Should().Be("");

            _bookingsApiClient.Verify(x => x.BookNewHearingAsync(It.Is <BookNewHearingRequest>(
                                                                     request => request.CreatedBy == CURRENT_USERNAME)), Times.Once);
            _userAccountService.Verify(x => x.AssignParticipantToGroup(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
        }
        public async Task Should_create_a_hearing_with_endpoints()
        {
            var newHearingRequest = new BookNewHearingRequest
            {
                Participants = new List <BookingsApi.Contract.Requests.ParticipantRequest>
                {
                    new BookingsApi.Contract.Requests.ParticipantRequest
                    {
                        CaseRoleName     = "CaseRole", ContactEmail = "*****@*****.**",
                        HearingRoleName  = "HearingRole", DisplayName = "display name1",
                        FirstName        = "fname", MiddleNames = "", LastName = "lname1", Username = "******",
                        OrganisationName = "", Representee = "", TelephoneNumber = ""
                    },
                    new BookingsApi.Contract.Requests.ParticipantRequest
                    {
                        CaseRoleName    = "CaseRole", ContactEmail = "*****@*****.**",
                        HearingRoleName = "HearingRole", DisplayName = "display name2",
                        FirstName       = "fname2", MiddleNames = "", LastName = "lname2",
                        Username        = "******", OrganisationName = "", Representee = "",
                        TelephoneNumber = ""
                    },
                },
                Endpoints = new List <EndpointRequest>
                {
                    new EndpointRequest
                    {
                        DisplayName = "displayname1", DefenceAdvocateUsername = "******"
                    },
                    new EndpointRequest
                    {
                        DisplayName = "displayname2", DefenceAdvocateUsername = "******"
                    },
                }
            };

            var bookingRequest = new BookHearingRequest
            {
                BookingDetails = newHearingRequest
            };

            // setup response
            var hearingDetailsResponse = HearingResponseBuilder.Build()
                                         .WithEndPoints(2)
                                         .WithParticipant("Representative", "*****@*****.**")
                                         .WithParticipant("Individual", "*****@*****.**");

            _bookingsApiClient.Setup(x => x.BookNewHearingAsync(newHearingRequest))
            .ReturnsAsync(hearingDetailsResponse);

            var result = await _controller.Post(bookingRequest);

            result.Result.Should().BeOfType <CreatedResult>();
            var createdObjectResult = (CreatedResult)result.Result;

            createdObjectResult.StatusCode.Should().Be(201);
        }
        private HearingDetailsResponse InitBookingForResponse(Guid hearingId)
        {
            var hearing = HearingResponseBuilder.Build()
                          .WithParticipant("Representative", "*****@*****.**")
                          .WithParticipant("Individual", "*****@*****.**")
                          .WithParticipant("Judicial Office Holder", "*****@*****.**")
                          .WithParticipant("Judge", "*****@*****.**");

            hearing.Id      = hearingId;
            hearing.GroupId = hearingId;
            return(hearing);
        }
Beispiel #5
0
        public async Task should_send_multi_day_notice_confirmation_when_hearing_is_a_multi_day_hearing()
        {
            // setup response
            var hearingDetailsResponse = HearingResponseBuilder.Build()
                                         .WithEndPoints(2)
                                         .WithParticipant("Representative", "*****@*****.**")
                                         .WithParticipant("Individual", "*****@*****.**")
                                         .WithParticipant("Individual", "*****@*****.**")
                                         .WithParticipant("Judicial Office Holder", "*****@*****.**")
                                         .WithParticipant("Judge", "*****@*****.**");

            _bookingsApiClient.Setup(x => x.BookNewHearingAsync(_bookNewHearingRequest))
            .ReturnsAsync(hearingDetailsResponse);

            var bookingRequest = new BookHearingRequest
            {
                BookingDetails      = _bookNewHearingRequest,
                IsMultiDay          = true,
                MultiHearingDetails = new MultiHearingRequest
                {
                    StartDate = hearingDetailsResponse.ScheduledDateTime,
                    EndDate   = hearingDetailsResponse.ScheduledDateTime.AddDays(7)
                }
            };
            var result = await _controller.Post(bookingRequest);

            result.Result.Should().BeOfType <CreatedResult>();
            var createdObjectResult = (CreatedResult)result.Result;

            createdObjectResult.StatusCode.Should().Be(201);

            _notificationApiMock.Verify(
                x => x.CreateNewNotificationAsync(It.Is <AddNotificationRequest>(notification =>
                                                                                 notification.NotificationType == NotificationType.HearingConfirmationJudgeMultiDay)), Times.Never);

            _notificationApiMock.Verify(
                x => x.CreateNewNotificationAsync(It.Is <AddNotificationRequest>(notification =>
                                                                                 notification.NotificationType == NotificationType.HearingConfirmationLipMultiDay)),
                Times.AtLeast(1));

            _notificationApiMock.Verify(
                x => x.CreateNewNotificationAsync(It.Is <AddNotificationRequest>(notification =>
                                                                                 notification.NotificationType == NotificationType.HearingConfirmationRepresentativeMultiDay)),
                Times.AtLeast(1));

            _notificationApiMock.Verify(
                x => x.CreateNewNotificationAsync(It.Is <AddNotificationRequest>(notification =>
                                                                                 notification.NotificationType == NotificationType.HearingConfirmationJohMultiDay)),
                Times.AtLeast(1));
        }
Beispiel #6
0
        public async Task Should_book_hearing()
        {
            // setup response
            var hearingDetailsResponse = HearingResponseBuilder.Build()
                                         .WithEndPoints(2)
                                         .WithParticipant("Representative", "*****@*****.**")
                                         .WithParticipant("Individual", "*****@*****.**")
                                         .WithParticipant("Individual", "*****@*****.**")
                                         .WithParticipant("Judicial Office Holder", "*****@*****.**")
                                         .WithParticipant("Judge", "*****@*****.**");

            _bookingsApiClient.Setup(x => x.BookNewHearingAsync(_bookNewHearingRequest))
            .ReturnsAsync(hearingDetailsResponse);

            var bookingRequest = new BookHearingRequest
            {
                BookingDetails = _bookNewHearingRequest
            };
            var result = await _controller.Post(bookingRequest);

            result.Result.Should().BeOfType <CreatedResult>();
            var createdObjectResult = (CreatedResult)result.Result;

            createdObjectResult.StatusCode.Should().Be(201);

            _bookNewHearingRequest.Participants.Any(x => string.IsNullOrWhiteSpace(x.Username)).Should().BeFalse();
            _pollyRetryServiceMock.Verify(x => x.WaitAndRetryAsync <Exception, Task>
                                          (
                                              It.IsAny <int>(), It.IsAny <Func <int, TimeSpan> >(), It.IsAny <Action <int> >(),
                                              It.IsAny <Func <Task, bool> >(), It.IsAny <Func <Task <Task> > >()
                                          ), Times.Exactly(4));

            _notificationApiMock.Verify(
                x => x.CreateNewNotificationAsync(It.Is <AddNotificationRequest>(notification =>
                                                                                 notification.NotificationType == NotificationType.HearingConfirmationJudge)), Times.Never);

            _notificationApiMock.Verify(
                x => x.CreateNewNotificationAsync(It.Is <AddNotificationRequest>(notification =>
                                                                                 notification.NotificationType == NotificationType.HearingConfirmationLip)), Times.AtLeast(1));

            _notificationApiMock.Verify(
                x => x.CreateNewNotificationAsync(It.Is <AddNotificationRequest>(notification =>
                                                                                 notification.NotificationType == NotificationType.HearingConfirmationRepresentative)),
                Times.AtLeast(1));

            _notificationApiMock.Verify(
                x => x.CreateNewNotificationAsync(It.Is <AddNotificationRequest>(notification =>
                                                                                 notification.NotificationType == NotificationType.HearingConfirmationJoh)), Times.AtLeast(1));
        }
        public async Task Should_update_participant_username_to_aad_email_id()
        {
            var participant = new BookingsApi.Contract.Requests.ParticipantRequest
            {
                Username        = "******",
                CaseRoleName    = "Applicant",
                HearingRoleName = "Representative",
                ContactEmail    = "*****@*****.**"
            };
            var participantList = new List <BookingsApi.Contract.Requests.ParticipantRequest> {
                participant
            };

            const string da        = "*****@*****.**";
            var          endpoints = new EndpointRequest {
                DisplayName = "displayname", DefenceAdvocateUsername = da
            };
            var endpointList = new List <EndpointRequest> {
                endpoints
            };

            var hearing = new BookNewHearingRequest
            {
                Participants = participantList,
                Endpoints    = endpointList
            };

            var bookingRequest = new BookHearingRequest
            {
                BookingDetails = hearing
            };

            // setup response
            var hearingDetailsResponse = HearingResponseBuilder.Build()
                                         .WithParticipant("Representative", participant.Username);

            _bookingsApiClient.Setup(x => x.BookNewHearingAsync(It.IsAny <BookNewHearingRequest>()))
            .ReturnsAsync(hearingDetailsResponse);

            await _controller.Post(bookingRequest);

            _userAccountService.Verify(x => x.GetAdUserIdForUsername(participant.Username), Times.Once);
        }
Beispiel #8
0
        public async Task should_not_send_notice_email_for_generic_hearing()
        {
            // setup response
            var hearingDetailsResponse = HearingResponseBuilder.Build()
                                         .WithEndPoints(2)
                                         .WithParticipant("Representative", "*****@*****.**")
                                         .WithParticipant("Individual", "*****@*****.**")
                                         .WithParticipant("Individual", "*****@*****.**")
                                         .WithParticipant("Judicial Office Holder", "*****@*****.**")
                                         .WithParticipant("Judge", "*****@*****.**");

            hearingDetailsResponse.CaseTypeName = "Generic";
            _bookingsApiClient.Setup(x => x.BookNewHearingAsync(_bookNewHearingRequest))
            .ReturnsAsync(hearingDetailsResponse);

            var bookingRequest = new BookHearingRequest
            {
                BookingDetails = _bookNewHearingRequest
            };
            var result = await _controller.Post(bookingRequest);

            result.Result.Should().BeOfType <CreatedResult>();
            var createdObjectResult = (CreatedResult)result.Result;

            createdObjectResult.StatusCode.Should().Be(201);

            _notificationApiMock.Verify(
                x => x.CreateNewNotificationAsync(It.Is <AddNotificationRequest>(notification =>
                                                                                 notification.NotificationType == NotificationType.HearingConfirmationJudge)), Times.Never);

            _notificationApiMock.Verify(
                x => x.CreateNewNotificationAsync(It.Is <AddNotificationRequest>(notification =>
                                                                                 notification.NotificationType == NotificationType.HearingConfirmationLip)), Times.Never);

            _notificationApiMock.Verify(
                x => x.CreateNewNotificationAsync(It.Is <AddNotificationRequest>(notification =>
                                                                                 notification.NotificationType == NotificationType.HearingConfirmationRepresentative)), Times.Never);

            _notificationApiMock.Verify(
                x => x.CreateNewNotificationAsync(It.Is <AddNotificationRequest>(notification =>
                                                                                 notification.NotificationType == NotificationType.HearingConfirmationJoh)), Times.Never);
        }
        public async Task Should_update_participant_user_details()
        {
            var participant = new BookingsApi.Contract.Requests.ParticipantRequest
            {
                Username        = "******",
                CaseRoleName    = "Applicant",
                HearingRoleName = "Representative"
            };

            // setup response
            var hearingDetailsResponse = HearingResponseBuilder.Build()
                                         .WithParticipant("Representative", "username");

            _bookingsApiClient.Setup(x => x.BookNewHearingAsync(It.IsAny <BookNewHearingRequest>()))
            .ReturnsAsync(hearingDetailsResponse);

            await PostWithParticipants(participant);

            _userAccountService.Verify(x => x.GetAdUserIdForUsername(participant.Username), Times.Once);
        }
        public async Task Should_not_update_user_details_for_winger()
        {
            var participant = new BookingsApi.Contract.Requests.ParticipantRequest
            {
                Username        = "******",
                CaseRoleName    = "",
                HearingRoleName = "Winger"
            };

            // setup  response
            var hearingDetailsResponse = HearingResponseBuilder.Build()
                                         .WithParticipant("");

            _bookingsApiClient.Setup(x => x.BookNewHearingAsync(It.IsAny <BookNewHearingRequest>()))
            .ReturnsAsync(hearingDetailsResponse);

            await PostWithParticipants(participant);

            _userAccountService.Verify(x => x.UpdateParticipantUsername(participant), Times.Never);
            _userAccountService.Verify(x => x.GetAdUserIdForUsername(participant.Username), Times.Never);
        }
        public async Task Should_not_send_email_for_existing_participant_added()
        {
            var existingUserName = "******";
            var participant      = new BookingsApi.Contract.Requests.ParticipantRequest
            {
                Username        = existingUserName,
                CaseRoleName    = "Applicant",
                HearingRoleName = "Representative"
            };

            // setup response
            var hearingDetailsResponse = HearingResponseBuilder.Build()
                                         .WithParticipant("Representative", existingUserName);

            _bookingsApiClient.Setup(x => x.BookNewHearingAsync(It.IsAny <BookNewHearingRequest>()))
            .ReturnsAsync(hearingDetailsResponse);

            await PostWithParticipants(participant);

            _notificationApiMock.Verify(
                x => x.CreateNewNotificationAsync(It.Is <AddNotificationRequest>(request =>
                                                                                 request.NotificationType == NotificationType.CreateRepresentative)), Times.Never);
        }