public void InvalidPost() { A.CallTo(() => this.service.GetById(1)).Returns(new Post { Id = 1, Author = "Jon", Content = "Test" }); A.CallTo( () => this.validators.Update.Validate( A<Post>.That.Matches(x => x.Id == 1 && x.Author == string.Empty && x.Content == "Welcome"))) .Returns( new ValidationResult(new List<ValidationFailure> { new ValidationFailure("Author", "Mandatory") })); var command = new UpdatePostCommand(this.stream, this.service, this.validators); command.Id = 1; command.Author = string.Empty; command.Content = "Welcome"; 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.service.GetById(1)).Returns(new Post { Id = 1, Author = "Jon", Content = "Test" }); A.CallTo(() => this.validators.Update.Validate(A<Post>.Ignored)).Returns(new ValidationResult()); A.CallTo( () => this.service.Update(A<Post>.That.Matches(x => x.Author == "David" && x.Content == "Welcome"))) .Returns(true); var command = new UpdatePostCommand(this.stream, this.service, this.validators); command.Id = 1; command.Author = "David"; command.Content = "Welcome"; 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.Update(A<Post>.That.Matches(x => x.Author == "David" && x.Content == "Welcome"))) .MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => this.stream.Raise(A<PostWasUpdated>.Ignored)).MustHaveHappened(Repeated.Exactly.Once); }