public void testToDomain() { 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; VehicleDuty vdMapper = VehicleDutyMapper.toDomain(VehicleDutyMapper.toDTO(new CreatingVehicleDutyDto(key, vehicle, dateMiliseconds, trips.ToArray(), workblocks.ToArray()))); VehicleDuty vd = new VehicleDuty(key, vehicle, date, trips, workblocks); Assert.AreEqual(vdMapper.Key, vd.Key); Assert.AreEqual(vdMapper.Vehicle, vd.Vehicle); Assert.AreEqual(vdMapper.Date, vd.Date); foreach (VDTripKey vdk in vd.Trips) { Assert.IsNotNull(vdMapper.Trips.Contains(vdk)); } foreach (VDWorkblockKey vdwb in vd.Workblocks) { Assert.IsNotNull(vdMapper.Workblocks.Contains(vdwb)); } }
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>)); }