// This is here to compare the above pattern to a more traditional, // less-abstracted pattern. Food for thought... // // Note: Not tested, don't use. // private AggregateResult <ExamplePerson> SetEmailAddress2(string emailAddress) { AggregateResult <ExamplePerson> result; var notifications = new NotificationList(); if (emailAddress == null) { throw new ArgumentNullException(nameof(emailAddress)); } if (!RegexUtilities.IsValidEmail(emailAddress)) { notifications.AddNotification(nameof(EmailAddress), "A valid email address is required."); } if (notifications.HasNotifications) { result = AggregateResult <ExamplePerson> .Fail(notifications); } else { _emailAddress = emailAddress.Trim(); result = AggregateResult <ExamplePerson> .Success(this); } return(result); }
public void Success_should_return_correct_properties() { var result = AggregateResult <ConcreteAggregate> .Success(); result.ShouldSatisfyAllConditions( () => result.Succeeded.ShouldBeTrue(), () => result.Notifications.ShouldBeEmpty(), () => result.Exception.ShouldBeNull(), () => result.NewAggregate.ShouldBe(default(ConcreteAggregate))); }
public void Success_with_aggregate_should_return_aggregate() { var aggregate = new ConcreteAggregate(); var result = AggregateResult <ConcreteAggregate> .Success(aggregate); result.ShouldSatisfyAllConditions( () => result.Succeeded.ShouldBeTrue(), () => result.Notifications.ShouldBeEmpty(), () => result.Exception.ShouldBeNull(), () => result.NewAggregate.ShouldBe(aggregate)); }
public void Case_succeeded_should_set_properties() { var aggregate = new ConcreteAggregate(); var aggregateResult = AggregateResult <ConcreteAggregate> .Success(aggregate); var commandResult = aggregateResult.ToCommandResult(); commandResult.ShouldSatisfyAllConditions( () => commandResult.Succeeded.ShouldBeTrue(), () => commandResult.Notifications.ShouldBeEmpty(), () => commandResult.Exception.ShouldBeNull(), () => commandResult.Status.ShouldBe(CommandResultStatus.Succeeded) ); }