Пример #1
0
        public void CreateGet_ShouldReturnDivisionCreateView()
        {
            // Arrange
            var divisionsIndexViewModel   = A.Fake <IDivisionsIndexViewModel>();
            var divisionsDetailsViewModel = A.Fake <IDivisionsDetailsViewModel>();
            var divisionRepository        = A.Fake <IDivisionRepository>();
            var sharedRepository          = A.Fake <ISharedRepository>();
            var testController            = new DivisionsController(divisionsIndexViewModel, divisionsDetailsViewModel,
                                                                    divisionRepository, sharedRepository);

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

            // Assert
            result.ShouldBeOfType <ViewResult>();
        }
Пример #2
0
        public async Task CreatePost_WhenModelStateIsValid_ShouldAddDivisionToDataStoreAndRedirectToIndexView()
        {
            // Arrange
            var divisionsIndexViewModel   = A.Fake <IDivisionsIndexViewModel>();
            var divisionsDetailsViewModel = A.Fake <IDivisionsDetailsViewModel>();
            var divisionRepository        = A.Fake <IDivisionRepository>();
            var sharedRepository          = A.Fake <ISharedRepository>();
            var testController            = new DivisionsController(divisionsIndexViewModel, divisionsDetailsViewModel,
                                                                    divisionRepository, sharedRepository);

            var division = new Division();

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

            // Assert
            A.CallTo(() => divisionRepository.AddAsync(division)).MustHaveHappenedOnceExactly();
            A.CallTo(() => sharedRepository.SaveChangesAsync()).MustHaveHappenedOnceExactly();
            result.ShouldBeOfType <RedirectToActionResult>();
            ((RedirectToActionResult)result).ActionName.ShouldBe <string>(nameof(testController.Index));
        }
Пример #3
0
        public async Task CreatePost_WhenModelStateIsNotValid_ShouldReturnDivisionCreateView()
        {
            // Arrange
            var divisionsIndexViewModel   = A.Fake <IDivisionsIndexViewModel>();
            var divisionsDetailsViewModel = A.Fake <IDivisionsDetailsViewModel>();
            var divisionRepository        = A.Fake <IDivisionRepository>();
            var sharedRepository          = A.Fake <ISharedRepository>();
            var testController            = new DivisionsController(divisionsIndexViewModel, divisionsDetailsViewModel,
                                                                    divisionRepository, sharedRepository);

            var division = new Division();

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

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

            // Assert
            A.CallTo(() => divisionRepository.AddAsync(division)).MustNotHaveHappened();
            A.CallTo(() => sharedRepository.SaveChangesAsync()).MustNotHaveHappened();
            result.ShouldBeOfType <ViewResult>();
            ((ViewResult)result).Model.ShouldBe(division);
        }