Ejemplo n.º 1
0
        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)));
        }
Ejemplo n.º 2
0
        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"));
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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();
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
 private static Nutrient CreteFakeNutrient()
 {
     return(Nutrient.Create(new Fixture().Create <string>()));
 }
Ejemplo n.º 10
0
 public void ChangeTitle_WithNullTitle_Throws()
 {
     // Arrange
     var          nutrient = Nutrient.Create(this.fixture.Create <string>());
     const string newTitle = default !;
Ejemplo n.º 11
0
 private static IEnumerable <Nutrient> GetFakeNutrients(int nutrientsCount)
 {
     return(Enumerable
            .Range(0, nutrientsCount)
            .Select(i => Nutrient.Create(new Fixture().Create <string>())));
 }