public void AddItemShouldAddAirportAndReturnIdWhenOnAddItemEventIsRaised() { var name = "Test Name"; var abbreviation = "ABC"; var countryId = 1; var airportEventArgs = new AirportsManagementEventArgs() { Name = name, Abbreviation = abbreviation, CountryId = countryId }; this.airportsView.Raise(a => a.OnAirprotsAddItem += null, airportEventArgs); var expectedId = 1; this.airportsServices.Verify( a => a.AddAirport( It.Is <Airport>(ar => ar.Name == name && ar.Abbreviation == abbreviation && ar.CountryId == countryId)), Times.Once); Assert.AreEqual(expectedId, airportEventArgs.Id); }
protected void CreateAirportBtn_Click(object sender, EventArgs e) { if (this.Page.IsValid) { this.OnAirprotsGetData?.Invoke(sender, e); bool doesAbbreviationExist = this.Model.Airports .Any(a => a.Abbreviation.ToLower() == this.AbbreviationTextBox.Text.ToLower()); if (doesAbbreviationExist) { this.AbbreviationTextBox.BorderColor = Color.Red; return; } var airportEventArgs = new AirportsManagementEventArgs() { Name = this.AirportNameTextBox.Text, Abbreviation = this.AbbreviationTextBox.Text.ToUpper(), CountryId = int.Parse(this.CountryDropDownList.SelectedItem.Value) }; this.OnAirprotsAddItem?.Invoke(sender, airportEventArgs); this.SuccessPanel.Visible = true; this.AddedAirportIdLiteral.Text = airportEventArgs.Id.ToString(); this.ClearFields(); } }
private void View_OnAirprotsUpdateItem(object sender, AirportsManagementEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(AirportsManagementEventArgs)); } var airport = this.airportsServices.GetAirport(e.Id); if (airport == null) { this.View.ModelState.AddModelError( ErrorMessages.MODEL_ERROR_KEY, string.Format(ErrorMessages.MODEL_ERROR_MESSAGE, e.Id)); return; } this.View.TryUpdateModel(airport); if (this.View.ModelState.IsValid) { if (e.CountryId <= 0) { throw new ArgumentOutOfRangeException(ErrorMessages.INVALID_ID); } airport.CountryId = e.CountryId; this.airportsServices.UpdateAirport(e.Id, airport); } }
private void View_OnAirportsDeleteItem(object sender, AirportsManagementEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(AirportsManagementEventArgs)); } this.airportsServices.DeleteAirport(e.Id); }
private void View_OnAirprotsAddItem(object sender, AirportsManagementEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(AirportsManagementEventArgs)); } var airport = new Airport() { Name = e.Name, Abbreviation = e.Abbreviation, CountryId = e.CountryId }; e.Id = this.airportsServices.AddAirport(airport); }