public async void TestPost() { using (var client = server.CreateClient().AcceptJson()) { var step = 1; var service = new CountryService(); var countBefore = service.GetAll().Count(); var item = service.GetAll().FirstOrDefault(); if (item == null) { var newItem = new Country() { Id = 0, Name = string.Format("Country {0}", countBefore) }; service.Add(item); item = service.GetAll().FirstOrDefault(); step = 2; } var response = await client.PostAsJsonAsync("/api/Countrys", item); var result = await response.Content.ReadAsJsonAsync <Country>(); var countAfter = service.GetAll().Count(); Assert.Equal(countBefore, countAfter - step); Assert.Equal((int)response.StatusCode, 201); } }
public ActionResult Create(Country ctry) { if (ModelState.IsValid) { _CountryService.Add(ctry); return(RedirectToAction("Index")); } return(View("Create", ctry)); }
public void ThrowArgumentNullException_WhenPassedCountryToAddIsNull() { // arrange var repository = new Mock <IEfRepository <Country> >(); var countryService = new CountryService(repository.Object); // act & assert Assert.Throws <ArgumentNullException>(() => countryService.Add(null)); }
private async Task Save() { CountryModel.RegionId = Regions?.SingleOrDefault(region => region.Id.Equals(RegionId))?.Id; if (Id != 0) { await CountryService.Update(CountryModel); } else { await CountryService.Add(CountryModel); } NavigationService.Previous(); }
public void NotThrow_WhenPassedCountryToAddIsValid() { // arrange var repository = new Mock <IEfRepository <Country> >(); var countryService = new CountryService(repository.Object); var countryModel = new Country() { Name = "SomeName" }; // act & assert Assert.DoesNotThrow(() => countryService.Add(countryModel)); }
private async Task Save() { if (RegionId != 0) { CountryModel.Region = new RegionModel { Id = RegionId }; } if (Id != 0) { await CountryService.Update(CountryModel); } else { await CountryService.Add(CountryModel); } NavigationService.Previous(); }
public void CallRepositoriesAddMethodWithCorrectCountryModel_WhenPassedCountryModelIsValid() { // arrange var repository = new Mock <IEfRepository <Country> >(); var countryService = new CountryService(repository.Object); var countryModel = new Country() { Name = "SomeName" }; repository.Setup(r => r.Add(It.Is <Country>(c => c == countryModel))); // act countryService.Add(countryModel); // assert repository.Verify(r => r.Add(It.Is <Country>(c => c == countryModel)), Times.Once); }
public void TestAdd() { ConfigurationHelper.Ensure(); var service = new CountryService(); var countBefore = service.GetAll().Count(); var newItem = new Country() { Id = 0, Name = string.Format("Country {0}", countBefore) }; service.Add(newItem); var countAfter = service.GetAll().Count(); Assert.Equal(countBefore, countAfter - 1); }
public ActionResult Insert(Country item) { ViewBag.ProvinceID = new SelectList(ilservisi.GetActive(), "ID", "ProvinceName", item.ProvinceID); if (ModelState.IsValid) { bool sonuc = ilceservisi.Add(item); if (sonuc) { return(RedirectToAction("Index")); } else { ViewBag.Mesaj = "İlçe Ekleme işlemi Sirasinda bir hata olustu.Lütfen daha sonra tekrar deneyin."; } } else { ViewBag.Mesaj = "Girmiş oldugunuz bilgiler hatali formattta veya eksiktir.Lütfen girmeye çaliştiğiniz verileri kontrol edin."; } return(View()); }
protected void grid_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "DeleteCountry") { CountryService.Delete(SQLDataHelper.GetInt(e.CommandArgument)); } if (e.CommandName == "AddCountry") { var footer = grid.FooterRow; if ( string.IsNullOrEmpty(((TextBox)footer.FindControl("txtNewName")).Text) || string.IsNullOrEmpty(((TextBox)footer.FindControl("txtNewISO2")).Text) || string.IsNullOrEmpty(((TextBox)footer.FindControl("txtNewISO3")).Text) ) { grid.FooterStyle.BackColor = System.Drawing.Color.FromName("#ffcccc"); return; } CountryService.Add(new Country { Name = ((TextBox)footer.FindControl("txtNewName")).Text, Iso2 = ((TextBox)footer.FindControl("txtNewISO2")).Text, Iso3 = ((TextBox)footer.FindControl("txtNewISO3")).Text, DisplayInPopup = ((CheckBox)footer.FindControl("chkNewDisplayInPopup")).Checked, SortOrder = ((TextBox)footer.FindControl("txtNewSortOrder")).Text.TryParseInt() }); grid.ShowFooter = false; } if (e.CommandName == "CancelAdd") { grid.FooterStyle.BackColor = System.Drawing.Color.FromName("#ccffcc"); grid.ShowFooter = false; } }
public CountryEditViewModel AddCountry(CountryEditViewModel CountryEditView) { var Country = CountryService.Add(CountryEditView); return(Country); }