Exemplo n.º 1
0
        public async Task GetAsync_ExistingId_ReturnsEntity()
        {
            // Arrange
            var expected = new[]
            {
                new AnyEntity
                {
                    Id        = 1,
                    AnyString = "Any"
                },
                new AnyEntity {
                    Id        = 2,
                    AnyString = "Any"
                }
            };

            dbContext.AnyEntities.AddRange(expected);
            dbContext.SaveChanges();

            // Act
            var actual = await repository.GetAsync(1);

            // Assert
            actual.Should().BeEquivalentTo(expected.First());
        }
        public async Task Read_AnyId_ReturnsEntityFromRepository()
        {
            // Arrange
            var expected = new AnyEntity
            {
                Id        = 1,
                AnyString = "AnyString"
            };

            A.CallTo(() => repository.GetAsync(1)).Returns(expected);

            // Act
            var result = (await controller.Read(1)).Result as OkObjectResult;

            // Assert
            result.Should().NotBeNull();
            result.Value.Should().Be(expected);
        }