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_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);
        }
Ejemplo n.º 3
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.º 4
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.º 5
0
        public async Task EditGet_WhenIdIsNotNullAndConferenceFound_ShouldReturnConferenceEditView()
        {
            // 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.Edit(id);

            // Assert
            A.CallTo(() => conferenceRepository.GetConferenceAsync(id.Value)).MustHaveHappenedOnceExactly();
            result.ShouldBeOfType <ViewResult>();
            ((ViewResult)result).Model.ShouldBe(conference);
        }
Ejemplo n.º 6
0
        public async Task EditGet_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.Edit(id);

            // Assert
            result.ShouldBeOfType <NotFoundResult>();
        }
Ejemplo n.º 7
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>();
        }