Beispiel #1
0
        public void Add_AddsEmployeeAndReturnsARedirect_WhenModelStateIsValid()
        {
            //Arrange
            var mockMotherboardService = new Mock <IService <IRepository <Motherboard>, Motherboard> >();

            mockMotherboardService.Setup(repo => repo.GetByIdAsync(1)).ReturnsAsync(GetMotherboard())
            .Verifiable();
            var httpContext = new DefaultHttpContext();
            var tempData    = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>());
            var controller  = new MotherboardController(mockMotherboardService.Object)
            {
                TempData = tempData
            };

            controller.ModelState.AddModelError("Quantity", "Required");
            var inputModel = new PCItemInputModel()
            {
                Id = 1, Quantity = 1
            };

            // Act
            var result = controller.Add(inputModel);

            // Assert
            Assert.IsType <JsonResult>(result.Result);
            mockMotherboardService.Verify();
        }
Beispiel #2
0
        public void Add_ReturnsBadRequestResult_WhenModelStateIsInvalid()
        {
            // Arrange
            var mockMotherboardService = new Mock <IService <IRepository <Motherboard>, Motherboard> >();
            var inputModel             = new PCItemInputModel()
            {
                Id = 0, Quantity = 0
            };
            var controller = new MotherboardController(mockMotherboardService.Object);

            controller.ModelState.AddModelError("Quantity", "Required");

            // Act
            var result = controller.Add(inputModel);

            // Assert
            var badRequestResult = Assert.IsType <BadRequestResult>(result.Result);
        }