Ejemplo n.º 1
0
        public async Task <ActionResult <VehicleDutyDto> > Create(CreatingVehicleDutyDto obj)
        {
            var dto         = VehicleDutyMapper.toDTO(obj);
            var vehicleDuty = await _service.AddAsync(dto);

            return(CreatedAtAction(nameof(GetGetById), new { Id = vehicleDuty.Id }, vehicleDuty));
        }
Ejemplo n.º 2
0
        public void testSetParameters()
        {
            string        key     = "vdkey";
            string        vehicle = "vehicle1";
            DateTime      date    = new DateTime(2022, 10, 11);
            List <String> trips   = new List <string>()
            {
                "trip1", "trip2", "trip3"
            };
            List <String> workblocks = new List <string>()
            {
                "wb1", "wb2", "wb3"
            };

            long dateMiliseconds = (long)(new TimeSpan(date.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).Ticks)).TotalMilliseconds;

            CreatingVehicleDutyDto cvddto = new CreatingVehicleDutyDto(key, vehicle, dateMiliseconds, trips.ToArray(), workblocks.ToArray());

            Assert.AreEqual(cvddto.Key, key);
            Assert.AreEqual(cvddto.Vehicle, vehicle);
            Assert.AreEqual(cvddto.Date, dateMiliseconds);
            foreach (String s in cvddto.Trips)
            {
                Assert.IsNotNull(trips.Contains(s));
            }
            foreach (String s in cvddto.Workblocks)
            {
                Assert.IsNotNull(workblocks.Contains(s));
            }
        }
Ejemplo n.º 3
0
        public async Task Post_NormalParameters_Sucess()
        {
            CreatingVehicleDutyDto request = new CreatingVehicleDutyDto("VehicleDut", "V12", 3495566307000, new string[] { "Trip:1", "Trip:2" }, new string[] { "Workblock:1", "Workblock:2" });

            var mock = new Mock <IVehicleDutyService>();

            mock.Setup(service => service.AddAsync(It.IsAny <VehicleDutyDto>())).Returns(Task.FromResult(VehicleDutyMapper.toDTO(request)));
            VehicleDutiesController controller = new VehicleDutiesController(mock.Object);

            var result = await controller.Create(request);

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

            Assert.IsInstanceOfType(result, typeof(ActionResult <VehicleDutyDto>));
        }
Ejemplo n.º 4
0
        public async Task Post_NormalParameters_Sucess()
        {
            CreatingVehicleDutyDto creatingVehicleDutyDto = new CreatingVehicleDutyDto("VehicleDut", "V12", 3495566307000, new string[] { "VehicleDuty:1", "VehicleDuty:2" }, new string[] { "Workblock:1", "Workblock:2" });

            VehicleDutyDto VehicleDutyDto = VehicleDutyMapper.toDTO(creatingVehicleDutyDto);
            VehicleDuty    VehicleDuty    = VehicleDutyMapper.toDomain(VehicleDutyDto);
            var            mockRepository = new Mock <IVehicleDutyRepository>();

            mockRepository.Setup(repository => repository.AddAsync(It.IsAny <VehicleDuty>())).Returns(Task.FromResult(VehicleDuty));

            var mockUnit = new Mock <IUnitOfWork>();

            VehicleDutyService      VehicleDutyService = new VehicleDutyService(mockUnit.Object, mockRepository.Object);
            VehicleDutiesController controller         = new VehicleDutiesController(VehicleDutyService);

            var result = await controller.Create(creatingVehicleDutyDto);

            mockRepository.Verify(repository => repository.AddAsync(It.IsAny <VehicleDuty>()), Times.AtLeastOnce());
            mockUnit.Verify(unit => unit.CommitAsync(), Times.AtLeastOnce());
            Assert.IsInstanceOfType(result, typeof(ActionResult <VehicleDutyDto>));
        }