Ejemplo n.º 1
0
        public async Task EditPost_WhenIdEqualsConferenceIdAndModelStateIsValidAndDbUpdateConcurrencyExceptionIsCaughtAndConferenceWithIdExists_ShouldRethrowException()
        {
            // Arrange
            var conferencesIndexViewModel   = A.Fake <IConferencesIndexViewModel>();
            var conferencesDetailsViewModel = A.Fake <IConferencesDetailsViewModel>();

            var conferenceRepository = A.Fake <IConferenceRepository>();

            A.CallTo(() => conferenceRepository.Update(A <Conference> .Ignored)).Throws <DbUpdateConcurrencyException>();
            A.CallTo(() => conferenceRepository.ConferenceExists(A <int> .Ignored)).Returns(true);

            var sharedRepository = A.Fake <ISharedRepository>();
            var testController   = new ConferencesController(conferencesIndexViewModel, conferencesDetailsViewModel,
                                                             conferenceRepository, sharedRepository);

            int id         = 1;
            var conference = new Conference
            {
                ID = 1
            };

            // Act
            var func = new Func <Task <IActionResult> >(async() => await testController.Edit(id, conference));

            // Assert
            await func.ShouldThrowAsync <DbUpdateConcurrencyException>();
        }
Ejemplo n.º 2
0
        public async Task EditPost_WhenIdEqualsConferenceIdAndModelStateIsValidAndDbUpdateConcurrencyExceptionIsCaughtAndConferenceWithIdDoesNotExist_ShouldReturnNotFound()
        {
            // Arrange
            var conferencesIndexViewModel   = A.Fake <IConferencesIndexViewModel>();
            var conferencesDetailsViewModel = A.Fake <IConferencesDetailsViewModel>();

            var conferenceRepository = A.Fake <IConferenceRepository>();

            A.CallTo(() => conferenceRepository.Update(A <Conference> .Ignored)).Throws <DbUpdateConcurrencyException>();
            A.CallTo(() => conferenceRepository.ConferenceExists(A <int> .Ignored)).Returns(false);

            var sharedRepository = A.Fake <ISharedRepository>();
            var testController   = new ConferencesController(conferencesIndexViewModel, conferencesDetailsViewModel,
                                                             conferenceRepository, sharedRepository);

            int id         = 1;
            var conference = new Conference
            {
                ID = 1
            };

            // Act
            var result = await testController.Edit(id, conference);

            // Assert
            result.ShouldBeOfType <NotFoundResult>();
        }
Ejemplo n.º 3
0
        public async Task Details_WhenIdIsNotNullAndConferenceFound_ShouldReturnConferenceDetailsView()
        {
            // Arrange
            var conferencesIndexViewModel   = A.Fake <IConferencesIndexViewModel>();
            var conferencesDetailsViewModel = A.Fake <IConferencesDetailsViewModel>();

            var        conferenceRepository = A.Fake <IConferenceRepository>();
            Conference?conference           = new Conference();

            A.CallTo(() => conferenceRepository.GetConferenceAsync(A <int> .Ignored)).Returns(conference);

            var sharedRepository = A.Fake <ISharedRepository>();
            var testController   = new ConferencesController(conferencesIndexViewModel, conferencesDetailsViewModel,
                                                             conferenceRepository, sharedRepository);

            int?id = 0;

            // Act
            var result = await testController.Details(id);

            // Assert
            A.CallTo(() => conferenceRepository.GetConferenceAsync(id.Value)).MustHaveHappenedOnceExactly();
            conferencesDetailsViewModel.Conference.ShouldBe(conference);
            result.ShouldBeOfType <ViewResult>();
            ((ViewResult)result).Model.ShouldBe(conferencesDetailsViewModel);
        }
Ejemplo n.º 4
0
        public async Task EditPost_WhenIdEqualsConferenceIdAndModelStateIsNotValid_ShouldReturnConferenceEditView()
        {
            // Arrange
            var conferencesIndexViewModel   = A.Fake <IConferencesIndexViewModel>();
            var conferencesDetailsViewModel = A.Fake <IConferencesDetailsViewModel>();
            var conferenceRepository        = A.Fake <IConferenceRepository>();
            var sharedRepository            = A.Fake <ISharedRepository>();
            var testController = new ConferencesController(conferencesIndexViewModel, conferencesDetailsViewModel,
                                                           conferenceRepository, sharedRepository);

            int id         = 1;
            var conference = new Conference
            {
                ID = 1
            };

            testController.ModelState.AddModelError("LongName", "Please enter a long name.");

            // Act
            var result = await testController.Edit(id, conference);

            // Assert
            A.CallTo(() => conferenceRepository.Update(A <Conference> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => sharedRepository.SaveChangesAsync()).MustNotHaveHappened();
            result.ShouldBeOfType <ViewResult>();
            ((ViewResult)result).Model.ShouldBe(conference);
        }
        public async Task Should_get_conferences_for_today()
        {
            var conferencesForAdminResponse = new ConferencesForAdminResponseBuilder().Build();
            var conferencesResponse         = new ConferenceResponseBuilder(conferencesForAdminResponse).BuildFromAdminResponse();

            var testApiClientMock = new Mock <ITestApiClient>();

            testApiClientMock
            .Setup(x => x.GetConferencesForTodayVhoAsync())
            .ReturnsAsync(conferencesForAdminResponse);

            var controller = new ConferencesController(testApiClientMock.Object, _loggerMock.Object);

            var response = await controller.GetConferencesForTodayAsync();

            response.Should().NotBeNull();

            var result = (OkObjectResult)response;

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

            var conferenceDetails = (List <ConferenceResponse>)result.Value;

            conferenceDetails.Should().NotBeNull();
            conferenceDetails.Should().BeEquivalentTo(conferencesResponse);
        }
        public async Task Should_get_conference_by_id()
        {
            var hearing                   = new CreateHearingRequestBuilder().Build();
            var hearingResponse           = new HearingsResponseBuilder(hearing).Build();
            var conferenceDetailsResponse = new ConferenceDetailsResponseBuilder(hearingResponse).Build();
            var conferenceResponse        = new ConferenceResponseBuilder(conferenceDetailsResponse).Build();

            var testApiClientMock = new Mock <ITestApiClient>();

            testApiClientMock
            .Setup(x => x.GetConferenceByHearingRefIdAsync(hearingResponse.Id))
            .ReturnsAsync(conferenceDetailsResponse);

            var controller = new ConferencesController(testApiClientMock.Object, _loggerMock.Object);

            var response = await controller.GetConferenceByHearingRefId(hearingResponse.Id);

            response.Should().NotBeNull();

            var result = (OkObjectResult)response;

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

            var conferenceDetails = (ConferenceResponse)result.Value;

            conferenceDetails.Should().NotBeNull();
            conferenceDetails.Should().BeEquivalentTo(conferenceResponse);
        }
        public ConferencesControllerTestBase()
        {
            ConferenceService = new Mock <IConferenceService>();
            Logger            = new Mock <ILoggerAdapter <ConferencesController> >();

            Controller = new ConferencesController(ConferenceService.Object, Logger.Object);
        }
Ejemplo n.º 8
0
        public async Task EditPost_WhenIdEqualsConferenceIdAndModelStateIsValidAndDbUpdateConcurrencyExceptionIsNotCaught_ShouldUpdateConferenceInDataStoreAndRedirectToIndexView()
        {
            // Arrange
            var conferencesIndexViewModel   = A.Fake <IConferencesIndexViewModel>();
            var conferencesDetailsViewModel = A.Fake <IConferencesDetailsViewModel>();
            var conferenceRepository        = A.Fake <IConferenceRepository>();
            var sharedRepository            = A.Fake <ISharedRepository>();
            var testController = new ConferencesController(conferencesIndexViewModel, conferencesDetailsViewModel,
                                                           conferenceRepository, sharedRepository);

            int id         = 1;
            var conference = new Conference
            {
                ID = 1
            };

            // Act
            var result = await testController.Edit(id, conference);

            // Assert
            A.CallTo(() => conferenceRepository.Update(conference)).MustHaveHappenedOnceExactly();
            A.CallTo(() => sharedRepository.SaveChangesAsync()).MustHaveHappenedOnceExactly();
            result.ShouldBeOfType <RedirectToActionResult>();
            ((RedirectToActionResult)result).ActionName.ShouldBe <string>(nameof(testController.Index));
        }
Ejemplo n.º 9
0
        public void Setup()
        {
            _mocker = AutoMock.GetLoose();

            var parameters = new ParameterBuilder(_mocker)
                             .AddTypedParameters <ParticipantResponseMapper>()
                             .AddTypedParameters <EndpointsResponseMapper>()
                             .AddTypedParameters <ParticipantForJudgeResponseMapper>()
                             .AddTypedParameters <ParticipantResponseForVhoMapper>()
                             .AddTypedParameters <ParticipantForUserResponseMapper>()
                             .Build();

            _mocker.Mock <IMapperFactory>().Setup(x => x.Get <VideoApi.Contract.Responses.ConferenceForJudgeResponse, VideoWeb.Contract.Responses.ConferenceForJudgeResponse>()).Returns(_mocker.Create <ConferenceForJudgeResponseMapper>(parameters));
            _mocker.Mock <IMapperFactory>().Setup(x => x.Get <VideoApi.Contract.Responses.ConferenceForIndividualResponse, VideoWeb.Contract.Responses.ConferenceForIndividualResponse>()).Returns(_mocker.Create <ConferenceForIndividualResponseMapper>(parameters));
            _mocker.Mock <IMapperFactory>().Setup(x => x.Get <ConferenceForAdminResponse, ConferenceForVhOfficerResponse>()).Returns(_mocker.Create <ConferenceForVhOfficerResponseMapper>(parameters));
            _mocker.Mock <IMapperFactory>().Setup(x => x.Get <ConferenceDetailsResponse, ConferenceResponseVho>()).Returns(_mocker.Create <ConferenceResponseVhoMapper>(parameters));
            _mocker.Mock <IMapperFactory>().Setup(x => x.Get <ConferenceDetailsResponse, ConferenceResponse>()).Returns(_mocker.Create <ConferenceResponseMapper>(parameters));

            var claimsPrincipal = new ClaimsPrincipalBuilder().Build();
            var context         = new ControllerContext
            {
                HttpContext = new DefaultHttpContext
                {
                    User = claimsPrincipal
                }
            };

            _controller = _mocker.Create <ConferencesController>();
            _controller.ControllerContext = context;

            _mocker.Mock <IConferenceCache>().Setup(x => x.AddConferenceAsync(It.IsAny <ConferenceDetailsResponse>()));
        }
        public void DeleteWithIncorrectId()
        {
            var testConference = new ConferenceWithoutIDModel();
            var testId         = new Guid().ToString("N");
            var testController = new ConferencesController();

            Assert.Throws <NotFoudException>(delegate { testController.Delete(testId); });
        }
        public void Post()
        {
            var testConference = new ConferenceWithoutIDModel();
            var result         = new Guid().ToString("N");
            var testController = new ConferencesController();

            Assert.AreEqual(result.GetType(), testController.Post(testConference).GetType());
        }
Ejemplo n.º 12
0
        public void Setup()
        {
            _mocker = AutoMock.GetLoose();

            var claimsPrincipal = new ClaimsPrincipalBuilder().WithRole(AppRoles.VhOfficerRole).Build();

            _controller = SetupControllerWithClaims(claimsPrincipal);
        }
Ejemplo n.º 13
0
 public void Setup()
 {
     QueryHandler   = new Mock <IQueryHandler>();
     CommandHandler = new Mock <ICommandHandler>();
     Logger         = new Mock <ILogger <ConferencesController> >();
     VideoApiClient = new Mock <IVideoApiClient>();
     Controller     = new ConferencesController(Logger.Object, VideoApiClient.Object);
 }
Ejemplo n.º 14
0
        public void Setup()
        {
            _videoApiClientMock  = new Mock <IVideoApiClient>();
            _mockLogger          = new Mock <ILogger <ConferencesController> >(MockBehavior.Loose);
            _mockConferenceCache = new Mock <IConferenceCache>();

            var claimsPrincipal = new ClaimsPrincipalBuilder().WithRole(AppRoles.VhOfficerRole).Build();

            _controller = SetupControllerWithClaims(claimsPrincipal);

            _mockConferenceCache.Setup(x => x.AddConferenceAsync(It.IsAny <ConferenceDetailsResponse>()));
        }
Ejemplo n.º 15
0
        public async Task Should_throw_internal_server()
        {
            var testApiClientMock = new Mock <ITestApiClient>();

            testApiClientMock
            .Setup(x => x.CreateEventAsync(It.IsAny <ConferenceEventRequest>()))
            .ThrowsAsync(ExceptionsData.INTERNAL_SERVER_EXCEPTION);

            var controller = new ConferencesController(testApiClientMock.Object, _loggerMock.Object);
            var result     = await controller.CreateVideoEvent(_request);

            var typedResult = (ObjectResult)result;

            typedResult.StatusCode.Should().Be((int)HttpStatusCode.InternalServerError);
        }
Ejemplo n.º 16
0
        public void CreateGet_ShouldReturnConferenceCreateView()
        {
            // Arrange
            var conferencesIndexViewModel   = A.Fake <IConferencesIndexViewModel>();
            var conferencesDetailsViewModel = A.Fake <IConferencesDetailsViewModel>();
            var conferenceRepository        = A.Fake <IConferenceRepository>();
            var sharedRepository            = A.Fake <ISharedRepository>();
            var testController = new ConferencesController(conferencesIndexViewModel, conferencesDetailsViewModel,
                                                           conferenceRepository, sharedRepository);

            // Act
            var result = testController.Create();

            // Assert
            result.ShouldBeOfType <ViewResult>();
        }
Ejemplo n.º 17
0
 public ConferenceControllerTests()
 {
     _loggerMock = new Mock <ILogger <ConferencesController> >();
     _controller = new ConferencesController(_testApiClientMock.Object, _loggerMock.Object);
     _request    = new ConferenceEventRequest()
     {
         ConferenceId  = Guid.NewGuid().ToString(),
         EventId       = Guid.NewGuid().ToString(),
         EventType     = EventsData.EVENT_TYPE,
         ParticipantId = Guid.NewGuid().ToString(),
         Phone         = EventsData.PHONE,
         Reason        = EventsData.REASON,
         TimeStampUtc  = DateTime.UtcNow,
         TransferFrom  = EventsData.TRANSFER_FROM,
         TransferTo    = EventsData.TRANSFER_TO
     };
 }
Ejemplo n.º 18
0
        public async Task Details_WhenIdIsNull_ShouldReturnNotFound()
        {
            // Arrange
            var conferencesIndexViewModel   = A.Fake <IConferencesIndexViewModel>();
            var conferencesDetailsViewModel = A.Fake <IConferencesDetailsViewModel>();
            var conferenceRepository        = A.Fake <IConferenceRepository>();
            var sharedRepository            = A.Fake <ISharedRepository>();
            var testController = new ConferencesController(conferencesIndexViewModel, conferencesDetailsViewModel,
                                                           conferenceRepository, sharedRepository);

            int?id = null;

            // Act
            var result = await testController.Details(id);

            // Assert
            result.ShouldBeOfType <NotFoundResult>();
        }
        public async Task Should_return_not_found_for_non_existent_hearing_id()
        {
            var hearingId = Guid.NewGuid();

            var testApiClientMock = new Mock <ITestApiClient>();

            testApiClientMock
            .Setup(x => x.GetConferenceByHearingRefIdAsync(hearingId))
            .ThrowsAsync(new TestApiException("Message", (int)HttpStatusCode.NotFound, "response", null, null));

            var controller = new ConferencesController(testApiClientMock.Object, _loggerMock.Object);

            var response = await controller.GetConferenceByHearingRefId(hearingId);

            response.Should().NotBeNull();

            var result = (ObjectResult)response;

            result.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
        }
        public async Task Get_conferences()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Get_conferences")
                          .Options;

            await GetTestConferences(options);

            using (var context = new ApplicationDbContext(options))
            {
                var controller = new ConferencesController(context);
                var result     = await controller.GetConferences();

                var okResult = Assert.IsType <OkObjectResult>(result);
                var response = Assert.IsType <List <ConferenceResponse> >(okResult.Value);

                Assert.Equal(2, response.Count);
                Assert.Contains(response, c => c.Name == "Conference1");
                Assert.Contains(response, c => c.Name == "Conference2");
            }
        }
Ejemplo n.º 21
0
        public async Task DeleteConfirmed_ShouldDeleteConferenceFromDataStoreAndRedirectToIndexView()
        {
            // Arrange
            var conferencesIndexViewModel   = A.Fake <IConferencesIndexViewModel>();
            var conferencesDetailsViewModel = A.Fake <IConferencesDetailsViewModel>();
            var conferenceRepository        = A.Fake <IConferenceRepository>();
            var sharedRepository            = A.Fake <ISharedRepository>();
            var testController = new ConferencesController(conferencesIndexViewModel, conferencesDetailsViewModel,
                                                           conferenceRepository, sharedRepository);

            int id = 1;

            // Act
            var result = await testController.DeleteConfirmed(id);

            // Assert
            A.CallTo(() => conferenceRepository.DeleteAsync(id)).MustHaveHappenedOnceExactly();
            A.CallTo(() => sharedRepository.SaveChangesAsync()).MustHaveHappenedOnceExactly();
            result.ShouldBeOfType <RedirectToActionResult>();
            ((RedirectToActionResult)result).ActionName.ShouldBe <string>(nameof(testController.Index));
        }
        public async Task Get_conference_by_id()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Get_conferences")
                          .Options;

            await GetTestConferences(options);

            var id = 1;

            using (var context = new ApplicationDbContext(options))
            {
                var controller = new ConferencesController(context);
                var result     = await controller.GetConference(id);

                var okResult = Assert.IsType <OkObjectResult>(result);
                var response = Assert.IsType <ConferenceResponse>(okResult.Value);

                Assert.Equal("Conference1", response.Name);
            }
        }
Ejemplo n.º 23
0
        public async Task CreatePost_WhenModelStateIsValid_ShouldAddConferenceToDataStoreAndRedirectToIndexView()
        {
            // Arrange
            var conferencesIndexViewModel   = A.Fake <IConferencesIndexViewModel>();
            var conferencesDetailsViewModel = A.Fake <IConferencesDetailsViewModel>();
            var conferenceRepository        = A.Fake <IConferenceRepository>();
            var sharedRepository            = A.Fake <ISharedRepository>();
            var testController = new ConferencesController(conferencesIndexViewModel, conferencesDetailsViewModel,
                                                           conferenceRepository, sharedRepository);

            var conference = new Conference();

            // Act
            var result = await testController.Create(conference);

            // Assert
            A.CallTo(() => conferenceRepository.AddAsync(conference)).MustHaveHappenedOnceExactly();
            A.CallTo(() => sharedRepository.SaveChangesAsync()).MustHaveHappenedOnceExactly();
            result.ShouldBeOfType <RedirectToActionResult>();
            ((RedirectToActionResult)result).ActionName.ShouldBe <string>(nameof(testController.Index));
        }
Ejemplo n.º 24
0
        public void Setup()
        {
            _videoApiClientMock  = new Mock <IVideoApiClient>();
            _mockLogger          = new Mock <ILogger <ConferencesController> >(MockBehavior.Loose);
            _mockConferenceCache = new Mock <IConferenceCache>();
            var claimsPrincipal = new ClaimsPrincipalBuilder().Build();
            var context         = new ControllerContext
            {
                HttpContext = new DefaultHttpContext
                {
                    User = claimsPrincipal
                }
            };

            _controller = new ConferencesController(_videoApiClientMock.Object,
                                                    _mockLogger.Object, _mockConferenceCache.Object)
            {
                ControllerContext = context
            };

            _mockConferenceCache.Setup(x => x.AddConferenceAsync(It.IsAny <ConferenceDetailsResponse>()));
        }
Ejemplo n.º 25
0
        public async Task EditPost_WhenIdDoesNotEqualConferenceId_ShouldReturnNotFound()
        {
            // Arrange
            var conferencesIndexViewModel   = A.Fake <IConferencesIndexViewModel>();
            var conferencesDetailsViewModel = A.Fake <IConferencesDetailsViewModel>();
            var conferenceRepository        = A.Fake <IConferenceRepository>();
            var sharedRepository            = A.Fake <ISharedRepository>();
            var testController = new ConferencesController(conferencesIndexViewModel, conferencesDetailsViewModel,
                                                           conferenceRepository, sharedRepository);

            int id         = 0;
            var conference = new Conference
            {
                ID = 1
            };

            // Act
            var result = await testController.Edit(id, conference);

            // Assert
            result.ShouldBeOfType <NotFoundResult>();
        }
Ejemplo n.º 26
0
        public async Task CreatePost_WhenModelStateIsNotValid_ShouldReturnConferenceCreateView()
        {
            // Arrange
            var conferencesIndexViewModel   = A.Fake <IConferencesIndexViewModel>();
            var conferencesDetailsViewModel = A.Fake <IConferencesDetailsViewModel>();
            var conferenceRepository        = A.Fake <IConferenceRepository>();
            var sharedRepository            = A.Fake <ISharedRepository>();
            var testController = new ConferencesController(conferencesIndexViewModel, conferencesDetailsViewModel,
                                                           conferenceRepository, sharedRepository);

            var conference = new Conference();

            testController.ModelState.AddModelError("LongName", "Please enter a long name.");

            // Act
            var result = await testController.Create(conference);

            // Assert
            A.CallTo(() => conferenceRepository.AddAsync(conference)).MustNotHaveHappened();
            A.CallTo(() => sharedRepository.SaveChangesAsync()).MustNotHaveHappened();
            result.ShouldBeOfType <ViewResult>();
            ((ViewResult)result).Model.ShouldBe(conference);
        }
Ejemplo n.º 27
0
        public async Task Index_ShouldReturnConferencesIndexView()
        {
            // Arrange
            var conferencesIndexViewModel   = A.Fake <IConferencesIndexViewModel>();
            var conferencesDetailsViewModel = A.Fake <IConferencesDetailsViewModel>();

            var conferenceRepository = A.Fake <IConferenceRepository>();
            var conferences          = new List <Conference>();

            A.CallTo(() => conferenceRepository.GetConferencesAsync()).Returns(conferences);

            var sharedRepository = A.Fake <ISharedRepository>();
            var testController   = new ConferencesController(conferencesIndexViewModel, conferencesDetailsViewModel,
                                                             conferenceRepository, sharedRepository);

            // Act
            var result = await testController.Index();

            // Assert
            A.CallTo(() => conferenceRepository.GetConferencesAsync()).MustHaveHappenedOnceExactly();
            conferencesIndexViewModel.Conferences.ShouldBe(conferences);
            result.ShouldBeOfType <ViewResult>();
            ((ViewResult)result).Model.ShouldBe(conferencesIndexViewModel);
        }
        public void Get()
        {
            var testController = new ConferencesController();

            Assert.DoesNotThrow(delegate { testController.Get(); });
        }
        public void GetByTitleWithWrongTitle()
        {
            var testController = new ConferencesController();

            Assert.Throws <NotFoudException>(delegate { testController.GetByTitle("WrongName"); });
        }