示例#1
0
        public void TryGetById_ShouldCallQueryService_AndReturnFalse_WhenEntityIsNotFound()
        {
            // Arrange
            const int        id     = 42;
            FakeEntity <int> person = null;

            _mockQueryService
            .Setup(i => i.TryGetById(id, out person))
            .Returns(false);

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

            // Act
            var success = subject.TryGetById(id, out var result);

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

            _mockQueryService.VerifyAll();
            _mockCommandService.VerifyAll();
        }
示例#2
0
        public void TryGetById_ShouldCallQueryService_AndReturnTrue_WhenEntityIsFound()
        {
            // Arrange
            var entity = new FakeEntity <int> {
                Id = 42
            };

            _mockQueryService
            .Setup(i => i.TryGetById(entity.Id, out entity))
            .Returns(true);

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

            // Act
            var success = subject.TryGetById(entity.Id, out var result);

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

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