public void InvalidPost()
        {
            A.CallTo(() => this.validators.Create.Validate(A<Post>.Ignored))
             .Returns(
                 new ValidationResult(new List<ValidationFailure> { new ValidationFailure("Author", "Mandatory") }));

            var command = new CreatePostCommand(this.stream, this.service, this.validators);

            command.Execute();

            Assert.That(command.IsSuccessful, Is.False);
            Assert.That(command.Results.IsValid, Is.False);
            Assert.That(command.Results.Errors.Count, Is.EqualTo(1));
        }
 public void TearDown()
 {
     this.service = null;
     this.createCommand = null;
     this.updateCommand = null;
     this.connection = null;
 }
 public void Setup()
 {
     this.service = A.Fake<IPostService>();
     this.createCommand = A.Fake<CreatePostCommand>();
     this.updateCommand = A.Fake<UpdatePostCommand>();
     this.connection = A.Fake<IConnectionManager>();
 }
        public void ValidPost()
        {
            A.CallTo(() => this.validators.Create.Validate(A<Post>.Ignored)).Returns(new ValidationResult());

            A.CallTo(() => this.service.Create(A<Post>.That.Matches(x => x.Author == "Jon" && x.Content == "Test")))
             .Returns(true);

            var command = new CreatePostCommand(this.stream, this.service, this.validators);

            command.Author = "Jon";
            command.Content = "Test";

            command.Execute();

            Assert.That(command.IsSuccessful, Is.True);
            Assert.That(command.Results.IsValid, Is.True);
            Assert.That(command.Results.Errors.Count, Is.EqualTo(0));
            A.CallTo(() => this.service.Create(A<Post>.That.Matches(x => x.Author == "Jon" && x.Content == "Test")))
             .MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => this.stream.Raise(A<PostWasCreated>.Ignored)).MustHaveHappened(Repeated.Exactly.Once);
        }