public async void Create_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IVehicleService, IVehicleRepository>(); var model = new ApiVehicleServerRequestModel(); var validatorMock = new Mock <IApiVehicleServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiVehicleServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>() { new ValidationFailure("text", "test") }))); var service = new VehicleService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALVehicleMapperMock, mock.DALMapperMockFactory.DALVehicleCapabilitiesMapperMock, mock.DALMapperMockFactory.DALVehicleOfficerMapperMock); CreateResponse <ApiVehicleServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiVehicleServerRequestModel>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <VehicleCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }
/// <summary> /// Constructor /// </summary> /// <param name="app">Application</param> /// <param name="distributedCache">Distributed cache</param> /// <param name="httpContextAccessor">Http context accessor</param> public VehicleController(IVMSApp app, IDistributedCache distributedCache, IHttpContextAccessor httpContextAccessor) { // Define the user var user = CreateUser(httpContextAccessor.HttpContext.User, httpContextAccessor.HttpContext.Connection.RemoteIpAddress); // Service Service = VehicleService.Create(app, user); // Cache Cache = distributedCache; }
public void CreateVehicle() { var vehicle = new FormModel { VehicleNumbers = "RP-1223", YearOfProduction = 2010 }; var result = vehicleService.Create(vehicle); Assert.IsNotNull(result); }
public async void Create_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <IVehicleService, IVehicleRepository>(); var model = new ApiVehicleServerRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Vehicle>())).Returns(Task.FromResult(new Vehicle())); var service = new VehicleService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.VehicleModelValidatorMock.Object, mock.DALMapperMockFactory.DALVehicleMapperMock, mock.DALMapperMockFactory.DALVehicleCapabilitiesMapperMock, mock.DALMapperMockFactory.DALVehicleOfficerMapperMock); CreateResponse <ApiVehicleServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.ModelValidatorMockFactory.VehicleModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiVehicleServerRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Vehicle>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <VehicleCreatedNotification>(), It.IsAny <CancellationToken>())); }
public ActionResult <Vehicle> Create(Vehicle vehicle) { return(_vehicleService.Create(vehicle)); }
public IActionResult Create() { var viewModel = _vehicleService.Create(); return(View(viewModel)); }