Esempio n. 1
0
        public async Task <ActionResult <VehicleDto> > Create(CreatingVehicleDto obj)
        {
            var dto     = VehicleMapper.toDTO(obj);
            var vehicle = await _service.AddAsync(dto);

            return(CreatedAtAction(nameof(GetGetById), new { Id = vehicle.Id }, vehicle));
        }
Esempio n. 2
0
        public void testSetParameters()
        {
            string   licensePlate     = "66-99-HC";
            string   VIN              = "12345678912345678";
            String   type             = "Miniautocarro";
            DateTime serviceAdmission = new DateTime(2020, 11, 15);

            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);

            Assert.AreEqual(cvdto.LicensePlate, licensePlate);
            Assert.AreEqual(cvdto.VIN, VIN);
            Assert.AreEqual(cvdto.Type, type);
            Assert.AreEqual(cvdto.ServiceAdmission, serviceAdmissionMiliseconds);
        }
Esempio n. 3
0
        public async Task Post_NormalParameters_Sucess()
        {
            CreatingVehicleDto request = new CreatingVehicleDto("AA-12-BB", "A1B2C3D4E5F6G7H8I", "Miniautocarro", 1000);

            var mock = new Mock <IVehicleService>();

            mock.Setup(service => service.AddAsync(It.IsAny <VehicleDto>())).Returns(Task.FromResult(VehicleMapper.toDTO(request)));
            VehiclesController controller = new VehiclesController(mock.Object);

            var result = await controller.Create(request);

            mock.Verify(service => service.AddAsync(It.IsAny <VehicleDto>()), Times.AtLeastOnce());
            ActionResult <VehicleDto> VehicleDto = VehicleMapper.toDTO(request);

            Assert.IsInstanceOfType(result, typeof(ActionResult <VehicleDto>));
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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>));
        }