public void Delete_ExistingId_Success() { mockUnitOfWork.Setup(u => u.CountryRepository.Get(new Guid("62FA647C-AD54-4BCC-A860-E5A2664B019D"))) .Returns(new Country() { Id = new Guid("62FA647C-AD54-4BCC-A860-E5A2664B019D"), Name = "City1" }); var res = countryService.DeleteAsync(new Guid("62FA647C-AD54-4BCC-A860-E5A2664B019D")); Assert.IsTrue(res.Result.Successed); }
public async Task DeleteAsync_UnknownIdPassed_ThrowAnException() { // Arrange int countryId = 11; _repositoryMock .Setup(rep => rep.GetByIdAsync(countryId)) .ReturnsAsync(TestData.GetCountyById(countryId)); // Act var exception = await Assert.ThrowsAsync <Exception>(() => _countryService.DeleteAsync(countryId)); // Assert Assert.NotNull(exception); }
public async Task SaveAndDeleteCountry() { var countriesList = new List <Country>(); var mockRepo = new Mock <IRepository <Country> >(); mockRepo.Setup(r => r.All()).Returns(countriesList.AsQueryable()); mockRepo.Setup(r => r.AddAsync(It.IsAny <Country>())).Callback <Country>(country => countriesList.Add(new Country { Id = 1, Name = country.Name, Code = country.Code })); mockRepo.Setup(r => r.Delete(It.IsAny <Country>())).Callback <Country>(country => countriesList.Remove(country)); var countryService = new CountryService(mockRepo.Object); var countryViewModel = new CountryViewModel { Name = "Norway", Code = "NO" }; await countryService.CreateAsync(countryViewModel); await countryService.DeleteAsync(1); Assert.Empty(countryService.GetAll()); }
public async Task <IActionResult> Delete(Guid countryUuid) { var result = await _countryService.DeleteAsync(new DeleteCountryDto(countryUuid)); if (result.IsFailed && result.Errors.Exists(e => e.HasMetadata("errCode", e => (string)e == "errCountryNotFound"))) { return(NotFound()); } return(Ok()); }
public async Task DeleteNotExistingCountry() { var countriesList = new List <Country>(); var mockRepo = new Mock <IRepository <Country> >(); mockRepo.Setup(r => r.All()).Returns(countriesList.AsQueryable()); var countryService = new CountryService(mockRepo.Object); await Assert.ThrowsAsync <Exception>(() => countryService.DeleteAsync(1)); }
public void DeleteCountryShouldInvokeDeleteRepositoryMethodOnce() { //Arrange var country = new Country { Name = "Bulgaria" }; var repo = new Mock <IDeletableEntityRepository <Country> >(); repo.Setup(x => x.GetByIdAsync(It.IsAny <string>())).Returns(Task.FromResult(country)); var service = new CountryService(repo.Object); //Act service.DeleteAsync("70400fb3-aed2-4876-aa9a-bcf8ba49ca9f").GetAwaiter().GetResult(); //Assert repo.Verify(x => x.Delete(country), Times.Once); }