public void ConstructWithNullEventArgs(ModelStateEventArgs eventArgs, IApplicationModel model, Exception e) { "Given the event args" .x(() => eventArgs.Should().BeNull()); "And the model state" .x(() => model.Should().BeNull()); "When constructing with null model state" .x(() => e = Record.Exception(() => new ModelStateEventArgs(model))); "Then the event args constructor should throw an exception" .x(() => e.Should().NotBeNull().And.Subject.Should().BeOfType <ArgumentNullException>().Which.ParamName.Should().Be("model")); }
private void OnUpdating(object sender, ModelStateEventArgs e) { var entity = ConvertViewModelToEntity(this.View.Model); dbcontext.Entry(entity).State = EntityState.Modified; try { dbcontext.SaveChanges(); } catch (DbUpdateException updateException) { // add the error to the model state for display by the view e.ModelState.AddModelError(string.Empty, updateException.GetBaseException().Message); } }
public void ConstructWithSuccess(ModelStateEventArgs eventArgs, IApplicationModel model, Exception e) { "Given the event args" .x(() => eventArgs.Should().BeNull()); "And the model state" .x(() => model = _mockModel.Object); "When constructing the event args" .x(() => e = Record.Exception(() => eventArgs = new ModelStateEventArgs(model))); "Then the event args constructor should succeed" .x(() => e.Should().BeNull()); "And the model state should be available" .x(() => eventArgs.Model.Should().NotBeNull().And.BeSameAs(model)); }
/// <summary> /// Fire event handler when having finished execution of a stage runner. /// </summary> /// <param name="e">The model state event argument.</param> protected virtual void OnAfterStageRunner(ModelStateEventArgs e) { AfterStageRunner?.Invoke(this, e); }
/// <summary> /// Fire event handler when starting execution of a stage runner. /// </summary> /// <param name="e">The model state event argument.</param> protected virtual void OnBeforeStageRunner(ModelStateEventArgs e) { BeforeStageRunner?.Invoke(this, e); }