Ejemplo n.º 1
0
        // 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);
        }
Ejemplo n.º 2
0
        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)));
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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)
                );
        }