public async Task <ActionResult <TripDto> > Create(CreatingTripDto obj) { var dto = TripMapper.toDTO(obj); var trip = await _service.AddAsync(dto); return(CreatedAtAction(nameof(GetGetById), new { Id = trip.Id }, trip)); }
public async Task Post_AllParameters_Success() { CreatingTripDto request = new CreatingTripDto("asdsds", "asfdsa", "dcxvxc", new int[] { 1, 2, 3, 4, 5 }); var mock = new Mock <ITripService>(); mock.Setup(service => service.AddAsync(It.IsAny <TripDto>())).Returns(Task.FromResult(TripMapper.toDTO(request))); TripsController controller = new TripsController(mock.Object); var result = await controller.Create(request); mock.Verify(service => service.AddAsync(It.IsAny <TripDto>()), Times.AtLeastOnce()); ActionResult <TripDto> tripDto = TripMapper.toDTO(request); Assert.IsInstanceOfType(result, typeof(ActionResult <TripDto>)); }
public async Task Post_NormalParameters_Sucess() { CreatingTripDto creatingTripDto = new CreatingTripDto("asdsds", "asfdsa", "dcxvxc", new int[] { 1, 2, 3, 4, 5 }); TripDto tripDto = TripMapper.toDTO(creatingTripDto); Trip trip = TripMapper.toDomain(tripDto); var mockRepository = new Mock <ITripRepository>(); mockRepository.Setup(repository => repository.AddAsync(It.IsAny <Trip>())).Returns(Task.FromResult(trip)); var mockUnit = new Mock <IUnitOfWork>(); TripService TripService = new TripService(mockUnit.Object, mockRepository.Object); TripsController controller = new TripsController(TripService); var result = await controller.Create(creatingTripDto); mockRepository.Verify(repository => repository.AddAsync(It.IsAny <Trip>()), Times.AtLeastOnce()); mockUnit.Verify(unit => unit.CommitAsync(), Times.AtLeastOnce()); Assert.IsInstanceOfType(result, typeof(ActionResult <TripDto>)); }
public void testToDomain() { string key = "keyTrip1"; string line = "lineTest1"; string path = "pathTest1"; int[] passingTimes = { 1, 2, 3, 4, 5 }; List <int> lPassingTimes = new List <int>(); lPassingTimes.AddRange(passingTimes); Trip t = new Trip(key, line, path, lPassingTimes); Trip mapperTrip = TripMapper.toDomain(TripMapper.toDTO(new CreatingTripDto(key, line, path, passingTimes))); Assert.AreEqual(t.Key, mapperTrip.Key); Assert.AreEqual(t.Line, mapperTrip.Line); Assert.AreEqual(t.Path, mapperTrip.Path); foreach (PassingTime pt in mapperTrip.PassingTimes) { Assert.IsNotNull(t.PassingTimes.Contains(pt)); } }
public void testToDto() { string key = "keyTrip1"; string line = "lineTest1"; string path = "pathTest1"; int[] passingTimes = { 1, 2, 3, 4, 5 }; List <int> lPassingTimes = new List <int>(); lPassingTimes.AddRange(passingTimes); TripDto tdto = new TripDto(key, line, path, lPassingTimes); TripDto mapperDto = TripMapper.toDTO(new CreatingTripDto(key, line, path, passingTimes)); Assert.AreEqual(tdto.Key, mapperDto.Key); Assert.AreEqual(tdto.Line, mapperDto.Line); Assert.AreEqual(tdto.Path, mapperDto.Path); foreach (int i in mapperDto.PassingTimes) { Assert.IsNotNull(tdto.PassingTimes.Contains(i)); } }