コード例 #1
0
ファイル: MachineTest.cs プロジェクト: Viktor5528/CarSale
        public void CreateSuccessWithNoteExistingBrandId()
        {
            MachineController controller = new MachineController(mockMachine.Object, mockBrand.Object, _mapper);

            var result = controller.Create(new CreateMachineViewModel
            {
                BrandId = 2, EngineType = Enums.EngineType.Petrol, BodyType = Enums.BodyType.Coupe
            });

            Assert.IsType <BadRequestObjectResult>(result);
        }
コード例 #2
0
ファイル: MachineTest.cs プロジェクト: Viktor5528/CarSale
        public void CreateWithInvalidBrandId()
        {
            MachineController controller = new MachineController(mockMachine.Object, mockBrand.Object, _mapper);

            var result = controller.Create(new CreateMachineViewModel
            {
                BrandId = -1, BodyType = Enums.BodyType.Coupe, EngineType = Enums.EngineType.Petrol
            });

            Assert.IsType <BadRequestObjectResult>(result);
        }
コード例 #3
0
        public async void Create_Errors()
        {
            MachineControllerMockFacade mock = new MachineControllerMockFacade();

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

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

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiMachineRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiMachineResponseModel> >(mockResponse.Object));
            MachineController controller = new MachineController(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 ApiMachineRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiMachineRequestModel>()));
        }
コード例 #4
0
        public async void Create_No_Errors()
        {
            MachineControllerMockFacade mock = new MachineControllerMockFacade();

            var mockResponse = ValidationResponseFactory <ApiMachineServerResponseModel> .CreateResponse(null as ApiMachineServerResponseModel);

            mockResponse.SetRecord(new ApiMachineServerResponseModel());
            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiMachineServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiMachineServerResponseModel> >(mockResponse));
            MachineController controller = new MachineController(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 ApiMachineServerRequestModel());

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

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