public async Task Should_remove_hearing()
        {
            var       client = new Mock <ITestApiClient>();
            const int COUNT  = 1;

            var deletedResponse = new DeletedResponse()
            {
                NumberOfDeletedHearings = COUNT
            };

            client.Setup(x => x.DeleteTestDataByPartialCaseTextAsync(It.IsAny <DeleteTestHearingDataRequest>()))
            .ReturnsAsync(deletedResponse);

            var controller = new HearingsController(client.Object, _loggerMock.Object);

            var result = await controller.DeleteTestDataByPartialCaseText(_request);

            var typedResult = (ObjectResult)result;

            typedResult.StatusCode.Should().Be((int)HttpStatusCode.OK);

            var response = (DeletedResponse)typedResult.Value;

            response.Should().NotBeNull();
            response.NumberOfDeletedHearings.Should().Be(COUNT);
        }
Exemple #2
0
        public async Task Should_confirm_hearing()
        {
            var hearingId          = Guid.NewGuid();
            var hearing            = new CreateHearingRequestBuilder().Build();
            var hearingResponse    = new HearingsResponseBuilder(hearing).Build();
            var request            = new ConfirmHearingBuilder().Build();
            var conferenceResponse = new ConferenceDetailsResponseBuilder(hearingResponse).Build();

            var client = new Mock <ITestApiClient>();

            client.Setup(x => x.ConfirmHearingByIdAsync(It.IsAny <Guid>(), It.IsAny <UpdateBookingStatusRequest>()))
            .ReturnsAsync(conferenceResponse);

            var controller = new HearingsController(client.Object, _loggerMock.Object);

            var result = await controller.ConfirmHearingById(hearingId, request);

            var typedResult = (ObjectResult)result;

            typedResult.StatusCode.Should().Be((int)HttpStatusCode.Created);

            var hearingDetails = (ConferenceDetailsResponse)typedResult.Value;

            hearingDetails.Should().NotBeNull();
            hearingDetails.Should().BeEquivalentTo(conferenceResponse);
        }
Exemple #3
0
 public void Setup()
 {
     QueryHandler       = new Mock <IQueryHandler>();
     CommandHandler     = new Mock <ICommandHandler>();
     Logger             = new Mock <ILogger <HearingsController> >();
     BookingsApiClient  = new Mock <IBookingsApiClient>();
     BookingsApiService = new Mock <IBookingsApiService>();
     VideoApiClient     = new Mock <IVideoApiClient>();
     VideoApiService    = new Mock <IVideoApiService>();
     Controller         = new HearingsController(Logger.Object, BookingsApiClient.Object, BookingsApiService.Object, VideoApiClient.Object, VideoApiService.Object);
 }
        public void GetHearingById_ReturnsBadRequest()
        {
            // Arrange
            var hearingRepo         = new Mock <IHearingsRepository>();
            var hearingManipulation = new HearingsManipulation(hearingRepo.Object);
            var controller          = new HearingsController(hearingManipulation);

            // Act
            var result = controller.Get(-1);

            // Assert
            Assert.IsType <BadRequestObjectResult>(result);
        }
        public void Delete_ReturnsOK()
        {
            // Arrange
            int      id          = 123;
            DateTime hearingDate = DateTime.Now;

            int createdByUserId = 1;
            int caseId          = 3;

            var usersOnHearing = new List <UserHearingDto>()
            {
                new UserHearingDto()
                {
                    UserId = 1
                }
            };

            var notes = new List <NoteDto>()
            {
                new NoteDto
                {
                    Text            = "test test",
                    CreatedByUserId = 1,
                    HearingId       = 123
                }
            };

            var hearing = new HearingDto()
            {
                HearingId       = id,
                HearingDate     = hearingDate,
                CreatedByUserId = createdByUserId,
                CaseId          = caseId,
                UserHearing     = usersOnHearing,
                Note            = notes
            };

            var hearingRepo = new Mock <IHearingsRepository>();

            hearingRepo.Setup(x => x.InsertHearing(hearing));
            var hearingManipulation = new HearingsManipulation(hearingRepo.Object);


            var controller = new HearingsController(hearingManipulation);

            // Act
            var result = controller.DeleteHearing(3);

            // Assert
            Assert.IsType <OkObjectResult>(result);
        }
        public async Task Should_throw_internal_server()
        {
            var client = new Mock <ITestApiClient>();

            client.Setup(x => x.DeleteTestDataByPartialCaseTextAsync(It.IsAny <DeleteTestHearingDataRequest>()))
            .ThrowsAsync(ExceptionsData.INTERNAL_SERVER_EXCEPTION);

            var controller = new HearingsController(client.Object, _loggerMock.Object);
            var result     = await controller.DeleteTestDataByPartialCaseText(_request);

            var typedResult = (ObjectResult)result;

            typedResult.StatusCode.Should().Be((int)HttpStatusCode.InternalServerError);
        }
        public void Delete_ReturnsBadRequest_GivenInvalidModel()
        {
            // Arrange & Act
            var mockRepo   = new Mock <IHearingsManipulation>();
            var controller = new HearingsController(mockRepo.Object);

            controller.ModelState.AddModelError("error", "some error");

            // Act
            var result = controller.DeleteHearing(100);

            // Assert
            Assert.IsType <BadRequestObjectResult>(result);
        }
Exemple #8
0
        public void SetUp()
        {
            var claims = new List <Claim>
            {
                new Claim(ClaimTypes.Name, "username"),
                new Claim(ClaimTypes.NameIdentifier, "userId"),
                new Claim("name", "John Doe")
            };
            var identity        = new ClaimsIdentity(claims, "TestAuthType");
            var claimsPrincipal = new ClaimsPrincipal(identity);


            _hearingServicesMock    = new Mock <IBookingsApiClient>();
            _userAccountServiceMock = new Mock <IUserAccountService>();
            _userManagerMock        = new Mock <UserManager>(_userAccountServiceMock.Object);
            _userIdentity           = new Mock <IUserIdentity>();

            var context = new ControllerContext
            {
                HttpContext = new DefaultHttpContext
                {
                    User = claimsPrincipal
                }
            };

            _hearingServicesMock.Setup(x => x.CreateHearingAsync(It.IsAny <HearingRequest>())).ReturnsAsync(1);

            _controller = new HearingsController(_hearingServicesMock.Object, _userManagerMock.Object, _userIdentity.Object)
            {
                ControllerContext = context
            };

            var participantRequest = new ParticipantRequest()
            {
                Display_name = "displayname",
                Email        = "*****@*****.**",
                First_name   = "firstname",
                Last_name    = "lastname",
                Phone        = "1234567890",
                Role         = "administrator",
                Title        = "ms",
                Username     = "******"
            };

            feedRequest = new FeedRequest {
                Location = "Administrator", Participants = new List <ParticipantRequest>()
            };
            feedRequest.Participants.Add(participantRequest);
        }
Exemple #9
0
        public async Task Should_throw_internal_server()
        {
            var testApiClientMock = new Mock <ITestApiClient>();

            testApiClientMock
            .Setup(x => x.CreateHearingAsync(It.IsAny <CreateHearingRequest>()))
            .ThrowsAsync(ExceptionsData.INTERNAL_SERVER_EXCEPTION);

            var controller = new HearingsController(testApiClientMock.Object, _loggerMock.Object);
            var result     = await controller.CreateHearing(_request);

            var typedResult = (ObjectResult)result;

            typedResult.StatusCode.Should().Be((int)HttpStatusCode.InternalServerError);
        }
Exemple #10
0
        public async Task Should_throw_internal_server()
        {
            const string CREATED_BY = HearingsData.CREATED_BY;

            var testApiClientMock = new Mock <ITestApiClient>();

            testApiClientMock
            .Setup(x => x.GetAllHearingsAsync())
            .ThrowsAsync(ExceptionsData.INTERNAL_SERVER_EXCEPTION);

            var controller = new HearingsController(testApiClientMock.Object, _loggerMock.Object);
            var result     = await controller.GetAllHearingsByCreatedBy(CREATED_BY);

            var typedResult = (ObjectResult)result;

            typedResult.StatusCode.Should().Be((int)HttpStatusCode.InternalServerError);
        }
Exemple #11
0
        public async Task Should_throw_internal_server()
        {
            var hearingId = Guid.NewGuid();
            var request   = new ConfirmHearingBuilder().Build();

            var client = new Mock <ITestApiClient>();

            client.Setup(x => x.ConfirmHearingByIdAsync(It.IsAny <Guid>(), It.IsAny <UpdateBookingStatusRequest>()))
            .ThrowsAsync(ExceptionsData.INTERNAL_SERVER_EXCEPTION);

            var controller = new HearingsController(client.Object, _loggerMock.Object);
            var result     = await controller.ConfirmHearingById(hearingId, request);

            var typedResult = (ObjectResult)result;

            typedResult.StatusCode.Should().Be((int)HttpStatusCode.InternalServerError);
        }
Exemple #12
0
        public async Task Should_create_hearing()
        {
            var client   = new Mock <ITestApiClient>();
            var response = new HearingsResponseBuilder(_request).Build();

            client.Setup(x => x.CreateHearingAsync(It.IsAny <CreateHearingRequest>()))
            .ReturnsAsync(response);

            var controller = new HearingsController(client.Object, _loggerMock.Object);

            var result = await controller.CreateHearing(_request);

            var typedResult = (ObjectResult)result;

            typedResult.StatusCode.Should().Be((int)HttpStatusCode.Created);

            var hearingDetails = (HearingDetailsResponse)typedResult.Value;

            hearingDetails.Should().NotBeNull();
            hearingDetails.Should().BeEquivalentTo(response);
        }
Exemple #13
0
        public async Task Should_get_all_hearings()
        {
            const string CREATED_BY = HearingsData.CREATED_BY;

            var client = new Mock <ITestApiClient>();
            var createHearingsResponse    = new HearingsResponseBuilder(_request).Build();
            var bookingsHearingResponse   = new BookingsHearingResponseBuilder(createHearingsResponse).Build();
            var bookingsHearingsResponses = new List <BookingsHearingResponse>()
            {
                bookingsHearingResponse
            };
            var hearingsResponse = new List <HearingResponse>()
            {
                new HearingResponse()
                {
                    Case_name     = bookingsHearingResponse.HearingName,
                    Id            = bookingsHearingResponse.HearingId,
                    ScheduledDate = bookingsHearingResponse.ScheduledDateTime
                }
            };

            client.Setup(x => x.GetAllHearingsAsync())
            .ReturnsAsync(bookingsHearingsResponses);

            var controller = new HearingsController(client.Object, _loggerMock.Object);

            var result = await controller.GetAllHearingsByCreatedBy(CREATED_BY);

            var typedResult = (ObjectResult)result;

            typedResult.StatusCode.Should().Be((int)HttpStatusCode.OK);

            var hearingDetails = (List <HearingResponse>)typedResult.Value;

            hearingDetails.Should().NotBeNull();
            hearingDetails.Should().BeEquivalentTo(hearingsResponse);
        }
        public void Update_ReturnsUpdatedHearing()
        {
            // Arrange
            int      id          = 123;
            DateTime hearingDate = DateTime.Now;

            int createdByUserId = 1;
            int caseId          = 3;

            var usersOnHearing = new List <UserHearingDto>()
            {
                new UserHearingDto()
                {
                    UserId = 1
                }
            };

            var notes = new List <NoteDto>()
            {
                new NoteDto
                {
                    Text            = "test test",
                    CreatedByUserId = 1,
                    HearingId       = 123
                }
            };

            var newNotes = new List <NoteDto>()
            {
                new NoteDto
                {
                    Text            = "test test",
                    CreatedByUserId = 1,
                    HearingId       = 123
                },
                new NoteDto
                {
                    Text            = "new note",
                    CreatedByUserId = 2,
                    HearingId       = 123
                },
                new NoteDto
                {
                    Text            = "new note2",
                    CreatedByUserId = 3,
                    HearingId       = 123
                }
            };

            var hearing = new HearingDto()
            {
                HearingId       = id,
                HearingDate     = hearingDate,
                CreatedByUserId = createdByUserId,
                CaseId          = caseId,
                UserHearing     = usersOnHearing,
                Note            = notes
            };

            var hearingRepo = new Mock <IHearingsRepository>();

            hearingRepo.Setup(x => x.InsertHearing(hearing));
            var hearingManipulation = new HearingsManipulation(hearingRepo.Object);


            var controller = new HearingsController(hearingManipulation);

            // Act
            var resultCreated = controller.Post(hearing);

            hearing.HearingDate = DateTime.Now.AddDays(15);
            hearing.Note        = newNotes;

            var resultUpdated = controller.Put(id, hearing);

            // Assert
            Assert.IsType <OkObjectResult>(resultCreated);
            Assert.IsType <OkObjectResult>(resultUpdated);
        }
 public void Setup()
 {
     _service    = new Mock <IHearingsService>();
     _controller = new HearingsController(_service.Object);
     _controller.MockUserIdentity(Username);
 }