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(); }
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(); }