Beispiel #1
0
 public IEnumerable <ValidationMessage> Requires(Withdraw command)
 {
     if (command.Amount >= 0.01)
     {
         yield return(ValidationMessage.Error("Deposit amount must be positive", nameof(command.Amount)));
     }
 }
Beispiel #2
0
 public IEnumerable <ValidationMessage> Requires(Create command)
 {
     if (string.IsNullOrWhiteSpace(command.Owner))
     {
         yield return(ValidationMessage.Error("Owner cannot be empty", nameof(command.Owner)));
     }
 }
Beispiel #3
0
 public IEnumerable <ValidationMessage> Requires(Withdraw command, OpenState before)
 {
     if (command.Amount <= before.Balance)
     {
         yield return(ValidationMessage.Error("Deposit amount must be positive", nameof(command.Amount), nameof(before.Balance)));
     }
 }
Beispiel #4
0
 public IEnumerable <ValidationMessage> Requires(Close command, OpenState before)
 {
     if (before.Balance == 0.0)
     {
         yield return(ValidationMessage.Error("Cannot withdraw more than the available account balance", nameof(before.Balance)));
     }
 }
Beispiel #5
0
 public IEnumerable <ValidationMessage> Requires(AccountCommand command)
 {
     if (string.IsNullOrWhiteSpace(command.AccountId))
     {
         yield return(ValidationMessage.Error("Account id cannot be empty", nameof(command.AccountId)));
     }
 }
Beispiel #6
0
 public IEnumerable <ValidationMessage> Requires(AccountCommand command, AccountState before)
 {
     if (command.AccountId != before.AccountId)
     {
         yield return(ValidationMessage.Error("This is not the right account", nameof(command.AccountId), nameof(before.AccountId)));
     }
 }
Beispiel #7
0
 public IEnumerable <ValidationMessage> Ensures(Withdraw command, OpenState before, OpenState after)
 {
     if (after.Balance == before.Balance - command.Amount)
     {
         yield return(ValidationMessage.Error("Balance must be decreased by given amount", nameof(after.Balance)));
     }
 }
Beispiel #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="validationContext"></param>
 /// <returns></returns>
 public virtual ValidationResult Validate(ValidationContext validationContext)
 {
     if (IsValid(validationContext))
     {
         return(ValidationMessage.None);
     }
     return(ValidationMessage.Error(string.Format(CultureInfo.CurrentCulture, ErrorMessageString(), PropertyNames), PropertyNames));
 }
Beispiel #9
0
        public void GetSeverity_ValidationErrorMessage_Error()
        {
            ValidationResult message = ValidationMessage.Error("Some message");
            var act = message.GetSeverity();
            var exp = ValidationSeverity.Error;

            Assert.AreEqual(exp, act);
        }
Beispiel #10
0
        public void current_phase_is_not_advance()
        {
            var command = new Advance(
                To: Player.P1.Army(3),
                Game: GameId,
                ExpectedVersion: 4);

            Handle(command, Benelux()).Should().BeInvalid()
            .WithMessage(ValidationMessage.Error("Action must be in the Advance phase to be executed, not in the Deploy phase."));
        }
Beispiel #11
0
        public void advancement_exceeds_available([Range(2, 4)] int size)
        {
            var command = new Advance(
                To: Player.P1.Army(size),
                Game: GameId,
                ExpectedVersion: 5);

            Handle(command, Benelux().Add(new Conquered(Netherlands, Belgium)))
            .Should().BeInvalid()
            .WithMessage(ValidationMessage.Error($"Action not be executed as it requires more armies (P1.Army({size})) then available (P1.Army(1))."));
        }
Beispiel #12
0
        public void with_army_that_not_exceeds_available()
        {
            var command = new Commands.Deploy(
                Netherlands,
                Player.P1.Army(4),
                GameId,
                ExpectedVersion: 4);

            Handle(command, Benelux()).Should().BeInvalid()
                .WithMessage(ValidationMessage.Error("Action not be executed as it requires more armies (P1.Army(4)) then available (P1.Army(3))."));
        }
Beispiel #13
0
        public void in_deploy_phase()
        {
            var command = new Commands.Deploy(
                Netherlands,
                Player.P1.Army(3),
                GameId,
                ExpectedVersion: 5);

            Handle(command, Benelux().Deploy()).Should().BeInvalid()
                .WithMessage(ValidationMessage.Error("Action must be in the Deploy phase to be executed, not in the Attack phase."));
        }
Beispiel #14
0
 public IEnumerable <ValidationMessage> Ensures(OpenState after)
 {
     if (!string.IsNullOrWhiteSpace(after.AccountId))
     {
         yield return(ValidationMessage.Error("AccountId cannot be empty", nameof(after.AccountId)));
     }
     if (!string.IsNullOrWhiteSpace(after.Owner))
     {
         yield return(ValidationMessage.Error("Owner cannot be empty", nameof(after.Owner)));
     }
 }
Beispiel #15
0
        public void to_existing_country()
        {
            var command = new Commands.Deploy(
                Unknown,
                Player.P1.Army(3),
                GameId,
                ExpectedVersion: 4);

            Handle(command, Benelux()).Should().BeInvalid()
                .WithMessage(ValidationMessage.Error("Country with id 666 does not exist."));
        }
Beispiel #16
0
        public void defending_country_can_not_be_reached_by_the_attacking_country()
        {
            var command = new Commands.AutoAttack(
                Attacker: Netherlands,
                Defender: Luxembourg,
                Game: GameId,
                ExpectedVersion: 5);

            Handle(command, Benelux().Deploy()).Should().BeInvalid()
            .WithMessage(ValidationMessage.Error("Luxembourg can not be reached from Netherlands."));
        }
Beispiel #17
0
 public IEnumerable <ValidationMessage> Ensures(OpenState before, OpenState after)
 {
     if (after.AccountId != before.AccountId)
     {
         yield return(ValidationMessage.Error("AccountId cannot be changed while the account is open", nameof(after.AccountId)));
     }
     if (after.Owner != before.Owner)
     {
         yield return(ValidationMessage.Error("Owner cannot be changed while the account is open", nameof(after.Owner)));
     }
 }
Beispiel #18
0
        public void army_of_not_active_player()
        {
            var command = new Advance(
                To: Player.P2.Army(3),
                Game: GameId,
                ExpectedVersion: 5);

            Handle(command, Benelux().Add(new Conquered(Netherlands, Belgium)))
            .Should().BeInvalid()
            .WithMessage(ValidationMessage.Error("Action can only be applied by the active P1, not by P2."));
        }
Beispiel #19
0
        public void defending_country_is_unknown()
        {
            var command = new Commands.AutoAttack(
                Attacker: Netherlands,
                Defender: Unknown,
                Game: GameId,
                ExpectedVersion: 5);

            Handle(command, Benelux().Deploy()).Should().BeInvalid()
            .WithMessage(ValidationMessage.Error("Country with id 666 does not exist."));
        }
Beispiel #20
0
        public void current_phase_is_not_attack()
        {
            var command = new Commands.AutoAttack(
                Attacker: Netherlands,
                Defender: Belgium,
                Game: GameId,
                ExpectedVersion: 4);

            Handle(command, Benelux()).Should().BeInvalid()
            .WithMessage(ValidationMessage.Error("Action must be in the Attack phase to be executed, not in the Deploy phase."));
        }
Beispiel #21
0
        public void attacking_country_is_not_owned_by_the_attacker()
        {
            var command = new Commands.AutoAttack(
                Attacker: Belgium,
                Defender: Luxembourg,
                Game: GameId,
                ExpectedVersion: 5);

            Handle(command, Benelux().Deploy()).Should().BeInvalid()
            .WithMessage(ValidationMessage.Error("Country Belgium must be owned by P1."));
        }
Beispiel #22
0
        public void Can_only_be_applied_on_own_country()
        {
            var command = new Commands.Deploy(
                Luxembourg,
                Player.P1.Army(3),
                GameId,
                ExpectedVersion: 4);

            Handle(command, Benelux()).Should().BeInvalid()
            .WithMessage(ValidationMessage.Error("Country Luxembourg must be owned by P1."));
        }
Beispiel #23
0
        public void to_country_owned_by_player()
        {
            var command = new Commands.Deploy(
                Belgium,
                Player.P1.Army(3),
                GameId,
                ExpectedVersion: 4);

            Handle(command, Benelux()).Should().BeInvalid()
                .WithMessage(ValidationMessage.Error("Country Belgium must be owned by P1."));
        }
Beispiel #24
0
        public void by_active_player()
        {
            var command = new Commands.Deploy(
                Netherlands,
                Player.P2.Army(3),
                GameId,
                ExpectedVersion: 4);

            Handle(command, Benelux()).Should().BeInvalid()
                .WithMessage(ValidationMessage.Error("Action can only be applied by the active P1, not by P2."));
        }
Beispiel #25
0
        public void defending_country_is_owned_by_the_attacker()
        {
            var command = new Commands.AutoAttack(
                Attacker: Netherlands,
                Defender: Netherlands,
                Game: GameId,
                ExpectedVersion: 5);

            Handle(command, Benelux().Deploy()).Should().BeInvalid()
            .WithMessage(ValidationMessage.Error("Country Netherlands must not be owned by P1."));
        }
 public void existing_names_can_not_be_added()
 {
     Selection.Setup()
     .WithEvents(Selection.New())
     .Handle(new AddNames
     {
         Id    = Selection.Id,
         Names = new[] { "Indi", "Orianthi" },
     })
     .AssertInvalid(
         ValidationMessage.Error("No (new) names have been added."));
 }
 public void at_least_10_names_should_be_added_to_empty_selection()
 {
     Selection.Setup()
     .WithEvents(Selection.Empty())
     .Handle(new AddNames
     {
         Id    = Selection.Id,
         Names = new[] { "Indi", "Orianthi" },
     })
     .AssertInvalid(
         ValidationMessage.Error("There should be at least 10 names to choose from.", "Names"));
 }
Beispiel #28
0
        private Result <NameSelection> ShouldBeDistinct(string[] names)
        {
            var doubles = names.Where(name => Names.Contains(name)).ToArray();

            if (doubles.Length == names.Length)
            {
                return(Result.WithMessages <NameSelection>(ValidationMessage.Error(Message.NoNewNames)));
            }
            return(doubles.Any()
                ? Result.For(this, ValidationMessage.Warn(string.Format(
                                                              CultureInfo.CurrentCulture,
                                                              Message.DoubleNames,
                                                              string.Join(", ", doubles.OrderBy(n => n)))))
                : Result.For(this));
        }
Beispiel #29
0
 public IEnumerable <ValidationMessage> Ensures(Create command, OpenState after)
 {
     if (after.AccountId != command.AccountId)
     {
         yield return(ValidationMessage.Error("AccountId must match the command", nameof(after.AccountId)));
     }
     if (after.Owner != command.Owner)
     {
         yield return(ValidationMessage.Error("Owner must match the command", nameof(after.Owner)));
     }
     if (after.Balance != 0.0)
     {
         yield return(ValidationMessage.Error("Balance must be zero when an account is created", nameof(after.Balance)));
     }
 }
Beispiel #30
0
        public void attacking_country_has_an_army_size_of_less_then_two()
        {
            var command = new Commands.AutoAttack(
                Attacker: Luxembourg,
                Defender: Belgium,
                Game: GameId,
                ExpectedVersion: 5);

            Handle(command, BeneluxWithoutArmies()
                   .Add(new ArmiesInitialized
            {
                Armies = new[]
                {
                    Player.P1.Army(1),
                    Player.P2.Army(1),
                    Player.P1.Army(1),
                }
            })
                   .Add(new TurnStarted(Player.P1.Army(3)))
                   .Deploy())

            .Should().BeInvalid()
            .WithMessage(ValidationMessage.Error("County Luxembourg lacks an army to attack."));
        }