public async Task <ActionResult> Update([FromBody] CarCategoryDto carCategoryDto) { try { await _carCategoryService.UpdateAsync(carCategoryDto); return(Ok()); } catch (Exception e) { return(BadRequest(e)); } }
public async Task <ActionResult> Post([FromBody] CarCategoryDto carCategoryDto) { try { if (carCategoryDto == null) { return(BadRequest($"{nameof(carCategoryDto)} can not not be null!")); } await _carCategoryService.AddAsync(carCategoryDto); return(Ok()); } catch (Exception e) { return(BadRequest(e)); } }
public async Task CategoryServiceService_GetCategoryById_GetExactlyOneCategoryWithSpecifiedValues() { var categoryToReturn = new CarCategory { Id = Guid.Empty, Name = "Test", DailyFee = 300m }; var expectedOjbect = new CarCategoryDto { Id = Guid.Empty, Name = "Test", DailyFee = 300m }; var config = new MapperConfiguration(cfg => cfg.CreateMap <CarCategory, CarCategoryDto>()); var repo = A.Fake <ICarCategoryRepository>(); var categoryService = new CarCategoryService(repo, config.CreateMapper()); A.CallTo(() => repo.GetAsync(Guid.Empty)).Returns(categoryToReturn); var result = await categoryService.GetByIdAsync(Guid.Empty); Assert.That(result.DailyFee, Is.EqualTo(expectedOjbect.DailyFee)); Assert.That(result.Name, Is.EqualTo(expectedOjbect.Name)); Assert.That(result.Id, Is.EqualTo(expectedOjbect.Id)); }
public async Task UpdateAsync(CarCategoryDto obj) => await _repository.UpdateAsync(_mapper.Map <CarCategoryDto, CarCategory>(obj));