public async Task CreateCityAsync_Should_Throw_ObjectConflictException() { var city = new City() { CityId = 1, Name = "Stockholm" }; var cityDto = new CityCreateDto() { Name = "Stockholm" }; var mockedRepository = new Mock <ICitiesRepository>(); mockedRepository.Setup(x => x.FindByNameAsync(It.IsAny <string>())) .ReturnsAsync(city); var mapperConfiguration = new MapperConfiguration(cfg => { cfg.AddProfile(new DomainProfile()); }); var mockedMapper = mapperConfiguration.CreateMapper(); var cityService = new CitiesService(mockedRepository.Object, mockedMapper); await Assert.ThrowsAsync <ObjectConflictException>(() => cityService.CreateCityAsync(cityDto)); }