Exemplo n.º 1
0
        public async Task AddEditUnit_ReturnsPartialView_WithSingleCategory()
        {
            // Arrange
            var unit = GetListOfUnit().First(x => x.Id == 1);

            mockUnitRepo.Setup(x => x.GetByIdAsync(It.IsAny <int?>())).ReturnsAsync(unit);

            mockUOW.Setup(x => x.Repository <Unit>()).Returns(mockUnitRepo.Object);

            var controller = new UnitsController(mockUOW.Object);

            // Act
            var result = await controller.AddEditUnit(1);

            // Assert
            var viewResult = Assert.IsType <PartialViewResult>(result);
            var model      = Assert.IsAssignableFrom <UnitViewModel>(viewResult.ViewData.Model);

            Assert.Equal(unit.Name, model.Name);
        }
Exemplo n.º 2
0
        public async Task AddEditUnitPost_ReturnsARedirectAndAddBrand_WhenCategoryIsValid()
        {
            // Arrange
            var unit = new UnitViewModel {
                Name = "Apple"
            };

            mockUnitRepo.Setup(x => x.InsertAsync(It.IsAny <Unit>())).Returns(Task.FromResult <Unit>(new Unit())).Verifiable();

            mockUOW.Setup(x => x.Repository <Unit>()).Returns(mockUnitRepo.Object);

            var controller = new UnitsController(mockUOW.Object);

            // Act
            var result = await controller.AddEditUnit(0, unit);

            // Assert
            var redirectResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Null(redirectResult.ControllerName);
            Assert.Equal("Index", redirectResult.ActionName);
            mockUnitRepo.Verify();
        }
Exemplo n.º 3
0
        public async Task AddEditUnitPOST_ReturnsEmptyModelWithError_WhenModelStateInvalid()
        {
            // Arrange
            var unit = new UnitViewModel {
            };

            //mockBrandRepo.Setup(x => x.GetByIdAsync(It.IsAny<int?>())).ReturnsAsync(brand);

            mockUOW.Setup(x => x.Repository <Unit>()).Returns(mockUnitRepo.Object);

            var controller = new UnitsController(mockUOW.Object);

            controller.ModelState.AddModelError("Name", "Required");
            // Act
            var result = await controller.AddEditUnit(0, unit);

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <UnitViewModel>(viewResult.ViewData.Model);

            Assert.Null(model.Name);
            Assert.False(viewResult.ViewData.ModelState.IsValid);
        }
Exemplo n.º 4
0
        public async Task AddEditUnitPost_ReturnsARedirectAndUpdateBrand_WhenBrandIsValid()
        {
            // Arrange
            var brandId = 1;
            var unit    = new UnitViewModel {
                Id = brandId, Name = "Apple"
            };

            mockUnitRepo.Setup(x => x.Update(It.IsAny <Unit>())).Verifiable();

            mockUOW.Setup(x => x.Repository <Unit>()).Returns(mockUnitRepo.Object);

            var controller = new UnitsController(mockUOW.Object);

            // Act
            var result = await controller.AddEditUnit(brandId, unit);

            // Assert
            var redirectResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Null(redirectResult.ControllerName);
            Assert.Equal("Index", redirectResult.ActionName);
        }