Exemplo n.º 1
0
 /// <summary>
 ///
 /// Initializes a new instance of the <see cref="OperationHandler"/> class.
 /// </summary>
 /// <param name="handler"></param>
 /// <param name="orderDirective"></param>
 /// <param name="operationDirective"></param>
 /// <exception cref="ArgumentNullException">If <see cref="handler"/> is null.</exception>
 /// <exception cref="ArgumentException">If <see cref="orderDirective"/> is not a valid value.</exception>
 /// <exception cref="ArgumentException">If <see cref="operationDirective"/> is not a valid value.</exception>
 public OperationHandler(
     IHandler <T> handler,
     OrderDirective orderDirective,
     OperationDirective operationDirective)
     : this(handler, orderDirective, new[] { operationDirective })
 {
 }
        public void Execute_Should_ReturnCorrectNumberOfMessages(OrderDirective order, OperationDirective operation)
        {
            var handler           = new OperationHandlerContainer <PersonStub>(OperationHandlers);
            var expectedFirstName = EnumUtilities.GetDescription(order);
            var expectedLastName  = expectedFirstName + EnumUtilities.GetDescription(operation);

            var container = handler.GetHandlerContainer(order, operation);
            var person    = PersonFactory.CreateEmpty();
            var messages  = new List <string>();

            container.InvalidResult += (object sender, ValidationHandlerArgs e) => messages.Add(e.ValidationResult.ErrorMessage);

            container.Execute(person);

            person.FirstName.Should().Be(expectedFirstName);
            person.LastName.Should().Be(expectedLastName);
            messages.Count.Should().Be(2);
            messages.Should().Contain(expectedFirstName);
            messages.Should().Contain(expectedLastName);
        }
Exemplo n.º 3
0
        public IValidationResultHandler <T> GetHandlerContainer(OrderDirective orderDirective, OperationDirective operationDirective)
        {
            if (HandlerContainers.ContainsKey(orderDirective) &&
                HandlerContainers[orderDirective].ContainsKey(operationDirective))
            {
                return(HandlerContainers[orderDirective][operationDirective]);
            }

            return(null);
        }