public async Task GetById_ShouldReturnQueryableWithSingleRecipient_WhenIdMatches() { // Arrange const int recipientId = 2; DbSet <Recipient> databaseRecipients = new[] { new Recipient { RecipientId = 1 }, new Recipient { RecipientId = 2 }, } .AsQueryable() .BuildMockDbSet() .Object; _contextMock .Setup(m => m.Recipients) .Returns(databaseRecipients); RecipientRepository repository = new RecipientRepository(_contextMock.Object); // Act Recipient recipient = await repository .GetById(recipientId) .SingleOrDefaultAsync(); // Assert Assert.NotNull(recipient); Assert.Equal(recipientId, recipient.RecipientId); }
public async Task GetById_ShouldReturnEmptyQueryable_WhenIdDoesNotMatch() { // Arrange const int recipientId = 5431; DbSet <Recipient> databaseRecipients = Enumerable .Empty <Recipient>() .AsQueryable() .BuildMockDbSet() .Object; _contextMock .Setup(m => m.Recipients) .Returns(databaseRecipients); RecipientRepository repository = new RecipientRepository(_contextMock.Object); // Act Recipient recipient = await repository .GetById(recipientId) .SingleOrDefaultAsync(); // Assert Assert.Null(recipient); }