Example #1
0
        public void Add_AddsEmployeeAndReturnsARedirect_WhenModelStateIsValid()
        {
            //Arrange
            var mockMemoryService = new Mock <IService <IRepository <Memory>, Memory> >();

            mockMemoryService.Setup(repo => repo.GetByIdAsync(1)).ReturnsAsync(GetMemory())
            .Verifiable();
            var httpContext = new DefaultHttpContext();
            var tempData    = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>());
            var controller  = new MemoryController(mockMemoryService.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);
            mockMemoryService.Verify();
        }
Example #2
0
        public void Add_ReturnsBadRequestResult_WhenModelStateIsInvalid()
        {
            // Arrange
            var mockMemoryService = new Mock <IService <IRepository <Memory>, Memory> >();
            var inputModel        = new PCItemInputModel()
            {
                Id = 0, Quantity = 0
            };
            var controller = new MemoryController(mockMemoryService.Object);

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

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

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