PageRenderTime 6ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/Source/Bifrost.Specs/Validation/for_CommandValidationService/when_validating_a_command_that_has_incorrect_inputs.cs

#
C# | 43 lines | 36 code | 7 blank | 0 comment | 0 complexity | fb34401df960a12008c87859a9a62281 MD5 | raw file
 1using System.Collections.Generic;
 2using System.ComponentModel.DataAnnotations;
 3using Bifrost.Commands;
 4using Bifrost.Specs.Validation.for_CommandValidationService.given;
 5using Bifrost.Validation;
 6using Machine.Specifications;
 7using Moq;
 8using It = Machine.Specifications.It;
 9
10namespace Bifrost.Specs.Validation.for_CommandValidationService
11{
12    public class when_validating_a_command_that_has_incorrect_inputs : a_command_validation_service
13    {
14        static IEnumerable<ValidationResult> input_validation_errors;
15        static IEnumerable<ValidationResult> validation_results;
16        static Mock<ICommand> command_mock;
17        static Mock<ICommandInputValidator> command_input_validator_mock;
18        static Mock<ICommandBusinessValidator> command_validator_mock;
19
20        Establish context = () =>
21        {
22            input_validation_errors = new List<ValidationResult>()
23                                          {
24                                              new ValidationResult("first failed input"),
25                                              new ValidationResult("second failed input")
26                                          };
27
28            command_mock = new Mock<ICommand>();
29            command_input_validator_mock = new Mock<ICommandInputValidator>();
30            command_validator_mock = new Mock<ICommandBusinessValidator>();
31
32            command_input_validator_mock.Setup(iv => iv.ValidateInput(command_mock.Object)).Returns(input_validation_errors);
33
34            command_validator_service_mock.Setup(cvs => cvs.GetInputValidatorFor(command_mock.Object)).Returns(command_input_validator_mock.Object);
35        };
36
37        Because of = () => validation_results = command_validation_service.Validate(command_mock.Object);
38
39        It should_have_failed_validations = () => validation_results.ShouldNotBeEmpty();
40        It should_have_all_the_failed_input_validations = () => validation_results.ShouldContainOnly(input_validation_errors);
41        It should_not_have_validated_the_command_business_rules = () => command_validator_mock.VerifyAll();
42    }
43}