public void testToDomain() { string licensePlate = "66-99-HC"; string VIN = "12345678912345678"; String type = "Miniautocarro"; DateTime serviceAdmission = new DateTime(2020, 11, 15); VehicleType vType = new VehicleType("Miniautocarro"); long serviceAdmissionMiliseconds = (long)(new TimeSpan(serviceAdmission.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).Ticks)).TotalMilliseconds; CreatingVehicleDto cvdto = new CreatingVehicleDto(licensePlate, VIN, type, serviceAdmissionMiliseconds); Vehicle vMapper = VehicleMapper.toDomain(VehicleMapper.toDTO(cvdto)); Vehicle v = new Vehicle(licensePlate, VIN, vType, serviceAdmission); Assert.AreEqual(vMapper.LicensePlate, v.LicensePlate); Assert.AreEqual(vMapper.VIN, v.VIN); Assert.AreEqual <String>(vMapper.Type.Value, v.Type.Value); Assert.AreEqual(vMapper.ServiceAdmission, v.ServiceAdmission); }
public async Task Post_NormalParameters_Sucess() { CreatingVehicleDto creatingVehicleDto = new CreatingVehicleDto("AA-12-BB", "A1B2C3D4E5F6G7H8I", "Miniautocarro", 1000); VehicleDto VehicleDto = VehicleMapper.toDTO(creatingVehicleDto); Vehicle Vehicle = VehicleMapper.toDomain(VehicleDto); var mockRepository = new Mock <IVehicleRepository>(); mockRepository.Setup(repository => repository.AddAsync(It.IsAny <Vehicle>())).Returns(Task.FromResult(Vehicle)); var mockUnit = new Mock <IUnitOfWork>(); VehicleService VehicleService = new VehicleService(mockUnit.Object, mockRepository.Object); VehiclesController controller = new VehiclesController(VehicleService); var result = await controller.Create(creatingVehicleDto); mockRepository.Verify(repository => repository.AddAsync(It.IsAny <Vehicle>()), Times.AtLeastOnce()); mockUnit.Verify(unit => unit.CommitAsync(), Times.AtLeastOnce()); Assert.IsInstanceOfType(result, typeof(ActionResult <VehicleDto>)); }