Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/686 part 2b #773

Merged
merged 2 commits into from
Feb 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Bifrost.Commands;
using Bifrost.Exceptions;
using Bifrost.Security;
using Bifrost.Validation;
using Machine.Specifications;
using Moq;

Expand All @@ -13,15 +13,17 @@ public abstract class a_command_coordinator : Globalization.given.a_localizer_mo
protected static Mock<ICommandContextManager> command_context_manager_mock;
protected static Mock<ICommandSecurityManager> command_security_manager_mock;
protected static Mock<ICommandValidators> command_validators_mock;
protected static Mock<ICommand> command_mock;
protected static Mock<ICommandContext> command_context_mock;
protected static Mock<IExceptionPublisher> exception_publisher_mock;
protected static ICommand command;

Establish context = () =>
{
command_mock = new Mock<ICommand>();
command = Mock.Of<ICommand>();
command_handler_manager_mock = new Mock<ICommandHandlerManager>();
command_context_manager_mock = new Mock<ICommandContextManager>();
command_validators_mock = new Mock<ICommandValidators>();
exception_publisher_mock = new Mock<IExceptionPublisher>();

command_context_mock = new Mock<ICommandContext>();
command_context_manager_mock.Setup(c => c.EstablishForCommand(Moq.It.IsAny<ICommand>())).
Expand All @@ -36,7 +38,8 @@ public abstract class a_command_coordinator : Globalization.given.a_localizer_mo
command_context_manager_mock.Object,
command_security_manager_mock.Object,
command_validators_mock.Object,
localizer_mock.Object
localizer_mock.Object,
exception_publisher_mock.Object
);
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Bifrost.Commands;
using Bifrost.Security;
using Machine.Specifications;
using Bifrost.Testing.Fakes.Commands;
using Moq;
using It = Machine.Specifications.It;

Expand All @@ -10,7 +9,6 @@ namespace Bifrost.Specs.Commands.for_CommandCoordinator
[Subject(typeof(CommandCoordinator))]
public class when_handling_a_command_that_fails_security : given.a_command_coordinator
{
static ICommand command;
static CommandResult result;
static Mock<AuthorizationResult> authorization_result;

Expand All @@ -19,8 +17,7 @@ public class when_handling_a_command_that_fails_security : given.a_command_coord
authorization_result = new Mock<AuthorizationResult>();
authorization_result.Setup(r => r.IsAuthorized).Returns(false);
authorization_result.Setup(r => r.BuildFailedAuthorizationMessages()).Returns(new[] { "Something went wrong" });
command = new SimpleCommand();
command_security_manager_mock.Setup(c => c.Authorize(Moq.It.IsAny<ICommand>())).Returns(authorization_result.Object);
command_security_manager_mock.Setup(c => c.Authorize(command)).Returns(authorization_result.Object);
};

Because of = () => result = coordinator.Handle(command);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
using Bifrost.Commands;
using Machine.Specifications;
using Bifrost.Validation;
using Machine.Specifications;
using Moq;
using It = Machine.Specifications.It;

namespace Bifrost.Specs.Commands.for_CommandCoordinator
{
[Subject(typeof(CommandCoordinator))]
public class when_handling_an_invalid_command : given.a_command_coordinator
{
static CommandResult Result;
static CommandResult result;
static CommandValidationResult validation_errors;

Establish context = () =>
{
validation_errors = new CommandValidationResult
{
ValidationResults = new ValidationResult[]
{
new ValidationResult("First validation failure"),
new ValidationResult("Second validation failure")
}
};
{
validation_errors = new CommandValidationResult
{
ValidationResults = new[]
{
new ValidationResult("First validation failure"),
new ValidationResult("Second validation failure")
}
};

command_validators_mock.Setup(cvs => cvs.Validate(command_mock.Object)).Returns(
validation_errors);
};
command_validators_mock
.Setup(cvs => cvs.Validate(command))
.Returns(validation_errors);
};

Because of = () => Result = coordinator.Handle(command_mock.Object);

Because of = () => result = coordinator.Handle(command);

It should_have_validated_the_command = () => command_validators_mock.VerifyAll();
It should_have_a_result = () => Result.ShouldNotBeNull();
It should_have_success_set_to_false = () => Result.Success.ShouldBeFalse();
It should_have_a_record_of_each_validation_failure = () => Result.ValidationResults.ShouldContainOnly(validation_errors.ValidationResults);
It should_not_handle_the_command = () => command_handler_manager_mock.Verify(chm => chm.Handle(command_mock.Object), Moq.Times.Never());
It should_rollback_the_command_context = () => command_context_mock.Verify(c => c.Rollback(), Moq.Times.Once());
It should_have_a_result = () => result.ShouldNotBeNull();
It should_have_success_set_to_false = () => result.Success.ShouldBeFalse();
It should_have_a_record_of_each_validation_failure = () => result.ValidationResults.ShouldContainOnly(validation_errors.ValidationResults);
It should_not_handle_the_command = () => command_handler_manager_mock.Verify(chm => chm.Handle(command), Times.Never());
It should_rollback_the_command_context = () => command_context_mock.Verify(c => c.Rollback(), Times.Once());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Bifrost.Commands;
using Bifrost.Exceptions;
using Machine.Specifications;

namespace Bifrost.Specs.Commands.for_CommandCoordinator
Expand All @@ -11,14 +12,15 @@ public class when_handling_command_and_an_exception_occurs_during_authorization
static Exception exception;

Establish context = () =>
{
exception = new Exception();
command_security_manager_mock.Setup(cvs => cvs.Authorize(command_mock.Object)).Throws(exception);
};
{
exception = new Exception();
command_security_manager_mock.Setup(cvs => cvs.Authorize(command)).Throws(exception);
};

Because of = () => result = coordinator.Handle(command_mock.Object);
Because of = () => result = coordinator.Handle(command);

It should_have_exception_in_result = () => result.Exception.ShouldEqual(exception);
It should_have_success_set_to_false = () => result.Success.ShouldBeFalse();
It should_have_published_the_exception = () => exception_publisher_mock.Verify(m => m.Publish(exception));
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using Bifrost.Commands;
using Machine.Specifications;
using It = Machine.Specifications.It;
using Bifrost.Exceptions;
using Bifrost.Validation;
using Machine.Specifications;

namespace Bifrost.Specs.Commands.for_CommandCoordinator
{
Expand All @@ -13,18 +13,19 @@ public class when_handling_command_and_an_exception_occurs_during_handling : giv
static Exception exception;

Establish context = () =>
{
exception = new Exception();
var validation_results = new CommandValidationResult { ValidationResults = new ValidationResult[0] };
command_validators_mock.Setup(cvs => cvs.Validate(command_mock.Object)).Returns(validation_results);
command_handler_manager_mock.Setup(c => c.Handle(Moq.It.IsAny<ICommand>())).Throws(exception);
};
{
exception = new Exception();
var validationResults = new CommandValidationResult {ValidationResults = new ValidationResult[0]};
command_validators_mock.Setup(cvs => cvs.Validate(command)).Returns(validationResults);
command_handler_manager_mock.Setup(c => c.Handle(Moq.It.IsAny<ICommand>())).Throws(exception);
};

Because of = () => result = coordinator.Handle(command_mock.Object);
Because of = () => result = coordinator.Handle(command);

It should_have_validated_the_command = () => command_validators_mock.VerifyAll();
It should_have_authenticated_the_command = () => command_security_manager_mock.VerifyAll();
It should_have_exception_in_result = () => result.Exception.ShouldEqual(exception);
It should_have_success_set_to_false = () => result.Success.ShouldBeFalse();
It should_have_published_the_exception = () => exception_publisher_mock.Verify(m => m.Publish(exception));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Bifrost.Commands;
using Bifrost.Exceptions;
using Machine.Specifications;

namespace Bifrost.Specs.Commands.for_CommandCoordinator
Expand All @@ -11,15 +12,16 @@ public class when_handling_command_and_an_exception_occurs_during_validation : g
static Exception exception;

Establish context = () =>
{
exception = new Exception();
command_validators_mock.Setup(cvs => cvs.Validate(command_mock.Object)).Throws(exception);
};
{
exception = new Exception();
command_validators_mock.Setup(cvs => cvs.Validate(command)).Throws(exception);
};

Because of = () => result = coordinator.Handle(command_mock.Object);
Because of = () => result = coordinator.Handle(command);

It should_have_authorized_the_command = () => command_security_manager_mock.VerifyAll();
It should_have_exception_in_result = () => result.Exception.ShouldEqual(exception);
It should_have_success_set_to_false = () => result.Success.ShouldBeFalse();
It should_have_published_the_exception = () => exception_publisher_mock.Verify(m => m.Publish(exception));
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
using Bifrost.Commands;
using Machine.Specifications;
using It = Machine.Specifications.It;
using Bifrost.Validation;

namespace Bifrost.Specs.Commands.for_CommandCoordinator
{
[Subject(typeof(CommandCoordinator))]
public class when_handling_command_with_success : given.a_command_coordinator
{
static CommandResult Result;
static CommandResult result;

Establish context = () =>
{
var validation_results = new CommandValidationResult();
command_validators_mock.Setup(cvs => cvs.Validate(command_mock.Object)).Returns(validation_results);
};
command_validators_mock.Setup(cvs => cvs.Validate(command)).Returns(new CommandValidationResult());

Because of = () =>
{
Result = coordinator.Handle(command_mock.Object);
};
Because of = () => result = coordinator.Handle(command);

It should_have_validated_the_command = () => command_validators_mock.VerifyAll();
It should_have_a_result = () => Result.ShouldNotBeNull();
It should_have_success_set_to_true = () => Result.Success.ShouldBeTrue();
It should_have_a_result = () => result.ShouldNotBeNull();
It should_have_success_set_to_true = () => result.Success.ShouldBeTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public class a_query_coordinator : all_dependencies
container_mock.Object,
fetching_security_manager_mock.Object,
query_validator_mock.Object,
read_model_filters_mock.Object);
read_model_filters_mock.Object,
exception_publisher_mock.Object);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public class a_query_coordinator_with_known_provider : a_query_coordinator
container_mock.Object,
fetching_security_manager_mock.Object,
query_validator_mock.Object,
read_model_filters_mock.Object);
read_model_filters_mock.Object,
exception_publisher_mock.Object);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public class a_query_coordinator_with_non_generic_known_provider : a_query_coord
container_mock.Object,
fetching_security_manager_mock.Object,
query_validator_mock.Object,
read_model_filters_mock.Object);
read_model_filters_mock.Object,
exception_publisher_mock.Object);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public class a_query_coordinator_with_provider_for_known_query_and_one_for_deriv
container_mock.Object,
fetching_security_manager_mock.Object,
query_validator_mock.Object,
read_model_filters_mock.Object);
read_model_filters_mock.Object,
exception_publisher_mock.Object);
};
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Bifrost.Execution;
using Bifrost.Exceptions;
using Bifrost.Execution;
using Bifrost.Read;
using Bifrost.Read.Validation;
using Machine.Specifications;
Expand All @@ -13,6 +14,7 @@ public class all_dependencies
protected static Mock<IFetchingSecurityManager> fetching_security_manager_mock;
protected static Mock<IReadModelFilters> read_model_filters_mock;
protected static Mock<IQueryValidator> query_validator_mock;
protected static Mock<IExceptionPublisher> exception_publisher_mock;

Establish context = () =>
{
Expand All @@ -21,6 +23,7 @@ public class all_dependencies
fetching_security_manager_mock = new Mock<IFetchingSecurityManager>();
read_model_filters_mock = new Mock<IReadModelFilters>();
query_validator_mock = new Mock<IQueryValidator>();
exception_publisher_mock = new Mock<IExceptionPublisher>();
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ public class when_executing_and_provider_throws_an_exception : given.a_query_coo
Because of = () => result = coordinator.Execute(query, paging);

It should_set_the_exception_on_the_result = () => result.Exception.ShouldEqual(exception_thrown);

It should_publish_the_exception = () => exception_publisher_mock.Verify(m => m.Publish(exception_thrown));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Bifrost.Events;
using Bifrost.Exceptions;
using Bifrost.Execution;
using Bifrost.Sagas;
using Bifrost.Validation;
using Machine.Specifications;
using Moq;

Expand All @@ -14,21 +14,23 @@ public class a_saga_narrator
protected static Mock<IContainer> container_mock;
protected static Mock<IChapterValidationService> chapter_validation_service_mock;
protected static Mock<IEventStore> event_store_mock;
protected static Mock<IExceptionPublisher> exception_publisher_mock;

Establish context = () =>
{
librarian_mock = new Mock<ISagaLibrarian>();
container_mock = new Mock<IContainer>();
chapter_validation_service_mock = new Mock<IChapterValidationService>();
event_store_mock = new Mock<IEventStore>();
{
librarian_mock = new Mock<ISagaLibrarian>();
container_mock = new Mock<IContainer>();
chapter_validation_service_mock = new Mock<IChapterValidationService>();
event_store_mock = new Mock<IEventStore>();
exception_publisher_mock = new Mock<IExceptionPublisher>();

narrator = new SagaNarrator(
librarian_mock.Object,
container_mock.Object,
chapter_validation_service_mock.Object,
event_store_mock.Object
);

};
narrator = new SagaNarrator(
librarian_mock.Object,
container_mock.Object,
chapter_validation_service_mock.Object,
event_store_mock.Object,
exception_publisher_mock.Object
);
};
}
}
Loading