public void TestMethod1() { // Arrange var db = new Database.Database(); var service = new CountriesService(db); var countries = service.GetAllCountries(); // Act db.Update(1, "Poland"); var newCountres = service.GetAllCountries(); // Assert Assert.AreEqual(countries, newCountres); }
public void Delete_Country_By_Id() { var countryToSave = new Country(); countryToSave.Name = "sarasa"; countryToSave.Id = 1; var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "Delete_Country_By_Id") .Options; using (var context = new ApplicationDbContext(options)) { var service = new CountriesService(context); service.AddCountry(countryToSave); Assert.Single(service.GetAllCountries()); service.DeleteById(1); Assert.Empty(service.GetAllCountries()); } }
public void Get_All_Countries_in_Database() { var countryToSave = new Country(); countryToSave.Name = "sarasa"; var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "Get_Element_for_Database") .Options; using (var context = new ApplicationDbContext(options)) { var service = new CountriesService(context); service.AddCountry(countryToSave); Assert.Single(service.GetAllCountries()); } }
public async Task GetCountries_CacheMiss_ReturnsResultsFromServiceSetsCache() { _handler .Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>() ) .ReturnsAsync(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent("[{\"name\":\"UK\",\"flag\":\"hi\",\"population\":60000000,\"timezones\":[\"UTC+00:00\"],\"currencies\":[{\"name\":\"British pound\",\"symbol\":\"£\"}],\"languages\":[{\"name\":\"English\",\"nativeName\":\"English\"}],\"borders\":[\"IRL\"]}]"), }) .Verifiable(); var result = await _countriesService.GetAllCountries(); result.Should().HaveCount(1); result.Should().BeEquivalentTo(new List <Country> { new Country { Name = "UK", Flag = "hi", Population = 60000000, Timezones = new List <string> { "UTC+00:00" }, Currencies = new List <Currency> { new Currency { Name = "British pound", Symbol = "£" } }, Languages = new List <Language> { new Language { Name = "English", NativeName = "English" } }, Borders = new List <string> { "IRL" } } }); }
private List <Country> GetAllCountries() { return(CountriesService.GetAllCountries()); }