public async Task FindAgent_ExistingAgent_NoError() { // Arrange DbContextOptions <YellowJacketContext> options = new DbContextOptionsBuilder <YellowJacketContext>() .UseInMemoryDatabase("FindAgent_ExistingAgent_NoError") .Options; const string agentName = "MyAgent"; // Act using (YellowJacketContext context = new YellowJacketContext(options)) { context.Agents.Add(new AgentEntity { Name = agentName, LastUpdateOn = DateTime.Now, RegisteredOn = DateTime.Now, Status = AgentStatus.Idle.ToString() }); context.SaveChanges(); } List <AgentModel> models; using (YellowJacketContext context = new YellowJacketContext(options)) { IAgentRepository agentRepository = new AgentRepository(context); IAgentService service = new AgentService(agentRepository, GetMapper()); models = await service.GetAll(); } AgentModel model = models.First(); // Assert using (YellowJacketContext context = new YellowJacketContext(options)) { IAgentRepository agentRepository = new AgentRepository(context); IAgentService service = new AgentService(agentRepository, GetMapper()); model = await service.Find(model.Id); Assert.That(model, !Is.Null, "The agent shouldn't be null."); } }