public static Mock <ILifeformService> GetStandardMockLifeformService(IEnumerable <Lifeform> result = null) { var mockLifeformService = new Mock <ILifeformService>(); mockLifeformService.Setup(s => s.GetLifeformByScientificNameAsync(It.IsAny <string>())) .ReturnsAsync(result.FirstOrDefault() ?? FakeLifeforms.Get().First().AsModel()); return(mockLifeformService); }
public async Task TestGetSomeWithIncludeAsync() { var inventoryItemsDbSetMock = MockEmergenceDbContext.CreateDbSetMock(x => x.InventoryItems, FakeInventories.GetItems()); MockEmergenceDbContext.Setup(c => c.Set <InventoryItem>()).Returns(inventoryItemsDbSetMock.Object); var inventoriesDbSetMock = MockEmergenceDbContext.CreateDbSetMock(x => x.Inventories, FakeInventories.Get()); MockEmergenceDbContext.Setup(c => c.Set <Inventory>()).Returns(inventoriesDbSetMock.Object); var lifeformsDbSetMock = MockEmergenceDbContext.CreateDbSetMock(x => x.Lifeforms, FakeLifeforms.Get()); MockEmergenceDbContext.Setup(c => c.Set <Lifeform>()).Returns(lifeformsDbSetMock.Object); var specimenRepository = new Repository <Specimen>(MockEmergenceDbContext.Object); var specimen = await specimenRepository.GetAsync(s => s.Id == 1, track : false); specimen.InventoryItemId.Should().Be(1); specimen.SpecimenStage.Should().Be("Seed"); specimen.InventoryItem.Should().NotBeNull(); specimen.InventoryItem.Inventory.Should().NotBeNull(); specimen.Lifeform.Should().NotBeNull(); }