public void Create_WithEmptyTitle_Throws() { //Arrange const string title = ""; Action run = () => Nutrient.Create(title); //Act //Assert run.Should().ThrowExactly <ArgumentException>() .Where(e => e.Message.Contains(nameof(title))); }
public void ChangeTitle_WithEmptyTitle_Throws() { // Arrange var nutrient = Nutrient.Create(this.fixture.Create <string>()); var newTitle = string.Empty; // Act Action run = () => nutrient.ChangeTitle(newTitle); // Assert run.Should().ThrowExactly <ArgumentException>() .Where(e => e.Message.Contains("newTitle")); }
public void ChangeTitle_WithValidArgs_ChangesTitle() { // Arrange var newTitle = this.fixture.Create <string>(); var oldTitle = this.fixture.Create <string>(); var nutrient = Nutrient.Create(oldTitle); // Act nutrient.ChangeTitle(newTitle); // Assert nutrient.Title.Should().BeEquivalentTo(newTitle); }
public void Create_WithValidParams_CreatesNewInstance() { //Arrange var title = new Fixture().Create <string>(); //Act var instance = Nutrient.Create(title); //Assert instance.Should().NotBeNull(); instance.Title.Should().Be(title); instance.NutrientId.Should().NotBe(Guid.Empty); }
public async Task HandleQueryAsync_WithValidParams_ReturnsNutrient() { // Arrange var id = new Fixture().Create <Guid>(); var query = new GetNutrientDetails(id); var fakeNutrient = Nutrient.Create(new Fixture().Create <string>()); A.CallTo(() => this.repository.GetOneByKeyAsync(id)) .Returns(fakeNutrient); // Act var result = await this.sut.HandleQueryAsync(query); // Assert result.Should().NotBeNull(); A.CallTo(() => this.repository.GetOneByKeyAsync(id)) .MustHaveHappenedOnceExactly(); }
public async Task HandleCommandAsync(CreateNutrient command) { if (command is null) { throw new ArgumentNullException(nameof(command)); } var nutrient = await this.repository.FindOneAsync(n => n.Title.Equals(command.Title)); if (nutrient != null) { throw new InvalidOperationException($"Nutrient with the title {nutrient.Title} already exists"); } nutrient = Nutrient.Create(command.Title); await this.repository.InsertOneAsync(nutrient); }
public void HandleCommandAsync_WithExistingNutrient_Throws() { // Arrange var nutrientTitle = new Fixture().Create <string>(); var fakeNutrient = Nutrient.Create(nutrientTitle); var command = new CreateNutrient(nutrientTitle); A.CallTo(() => this.repository.FindOneAsync(A <Expression <Func <Nutrient, bool> > > .Ignored)) .Returns(fakeNutrient); // Act Func <Task> run = async() => await this.sut.HandleCommandAsync(command); // Assert run.Should().ThrowExactly <InvalidOperationException>() .WithMessage($"Nutrient with the title {nutrientTitle} already exists"); A.CallTo(() => this.repository.FindOneAsync(A <Expression <Func <Nutrient, bool> > > .Ignored)) .MustHaveHappenedOnceExactly(); }
public async Task HandleCommandAsync_WithValidArgs_UpdatesNutrientTitle() { // Arrange var id = this.fixture.Create <Guid>(); var newTitle = this.fixture.Create <string>(); var oldTitle = this.fixture.Create <string>(); var command = new UpdateNutrientTitle(id, newTitle); var fakeNutrient = Nutrient.Create(oldTitle); A.CallTo(() => this.repository.GetOneByKeyAsync(id)) .Returns(fakeNutrient); // Act await this.sut.HandleCommandAsync(command); // Assert A.CallTo(() => this.repository.GetOneByKeyAsync(id)) .MustHaveHappenedOnceExactly(); A.CallTo(() => this.repository.SaveOneAsync(fakeNutrient)) .MustHaveHappenedOnceExactly(); fakeNutrient.Title.Should().BeEquivalentTo(newTitle); }
private static Nutrient CreteFakeNutrient() { return(Nutrient.Create(new Fixture().Create <string>())); }
public void ChangeTitle_WithNullTitle_Throws() { // Arrange var nutrient = Nutrient.Create(this.fixture.Create <string>()); const string newTitle = default !;
private static IEnumerable <Nutrient> GetFakeNutrients(int nutrientsCount) { return(Enumerable .Range(0, nutrientsCount) .Select(i => Nutrient.Create(new Fixture().Create <string>()))); }