Ejemplo n.º 1
0
        public async Task TryGetByIdAsync_ShouldCallQueryService_AndReturnNull_WhenEntityIsNotFound()
        {
            // Arrange
            const int id = 42;

            _mockQueryService
            .Setup(i => i.TryGetByIdAsync(id))
            .ReturnsAsync((FakeEntity <int>)null);

            var subject = new ComposedAsyncRepository <FakeEntity <int>, int>(_mockQueryService.Object, _mockCommandService.Object);

            // Act
            var result = await subject.TryGetByIdAsync(id).ConfigureAwait(false);

            // Assert
            result.Should().BeNull();

            _mockQueryService.VerifyAll();
            _mockCommandService.VerifyAll();
        }
Ejemplo n.º 2
0
        public async Task TryGetByIdAsync_ShouldCallQueryService_AndReturnEntity_WhenEntityIsFound()
        {
            // Arrange
            var entity = new FakeEntity <int> {
                Id = 42
            };

            _mockQueryService
            .Setup(i => i.TryGetByIdAsync(entity.Id))
            .ReturnsAsync(entity);

            var subject = new ComposedAsyncRepository <FakeEntity <int>, int>(_mockQueryService.Object, _mockCommandService.Object);

            // Act
            var result = await subject.TryGetByIdAsync(entity.Id).ConfigureAwait(false);

            // Assert
            result.Should().BeSameAs(entity);

            _mockQueryService.VerifyAll();
            _mockCommandService.VerifyAll();
        }