private async Task <IActionResult> CreateDevice(CreateDeviceRequest createDeviceRequest) { var options = new DbContextOptionsBuilder <Context>() .UseInMemoryDatabase(databaseName: "Device") .Options; // Run the test against one instance of the context using (var context = new Context(options)) { var repository = new DeviceRepository(context, AutomapperSingleton.Mapper); var service = new DeviceService(repository, AutomapperSingleton.Mapper); var controller = new DeviceController(service); Mock <HttpRequest> mockCreateRequest = MockHttpRequest.CreateMockRequest(createDeviceRequest); return(await controller.CreateDeviceAsync(mockCreateRequest.Object, _logger)); //as GridController; } }