Example #1
0
        public void GetCreateShouldReturnViewWithValidModel()
        {
            // Arrange
            var controller = new StoreController(null, null, null);

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

            // Assert
            result.Should().BeOfType <ViewResult>();
        }
Example #2
0
        public void CanDoPostBackCreate()
        {
            //ACT
            var store = new Store   {
                Name = "Store 4", HubID = 2, IsActive = true, IsTemporary = false, Number = 101, StackCount = 1, StoreManName = "Mezgebu"
            };
            var result = _storeController.Create(store);

            //Assert
            Assert.IsInstanceOf <ActionResult>(result);
            Assert.IsInstanceOf <int>(store.StoreID);
        }
        public async void Create_Errors()
        {
            StoreControllerMockFacade mock = new StoreControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiStoreResponseModel> >(new FluentValidation.Results.ValidationResult());
            var mockRecord   = new ApiStoreResponseModel();

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiStoreRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiStoreResponseModel> >(mockResponse.Object));
            StoreController controller = new StoreController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiStoreRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiStoreRequestModel>()));
        }
        public async void Create_No_Errors()
        {
            StoreControllerMockFacade mock = new StoreControllerMockFacade();

            var mockResponse = new CreateResponse <ApiStoreResponseModel>(new FluentValidation.Results.ValidationResult());

            mockResponse.SetRecord(new ApiStoreResponseModel());
            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiStoreRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiStoreResponseModel> >(mockResponse));
            StoreController controller = new StoreController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiStoreRequestModel());

            response.Should().BeOfType <CreatedResult>();
            (response as CreatedResult).StatusCode.Should().Be((int)HttpStatusCode.Created);
            var createResponse = (response as CreatedResult).Value as CreateResponse <ApiStoreResponseModel>;

            createResponse.Record.Should().NotBeNull();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiStoreRequestModel>()));
        }