public async Task <HttpResponseMessage> CreateHardware(CreateHardwareRequest createHardwareRequest) { var content = IntegrationHttpRequest.CreateContentRequest(createHardwareRequest); HttpResponseMessage response = await client.PostAsync(UrlBase + "api/v1/create-hardware", content); return(response); }
private async Task <HardwareResponse> CreatedDefaultHardware() { CreateHardwareRequest hardware = HardwareComponentsValues.CreateHardwareRequestBasic(); var request = AutomapperSingleton.Mapper.Map <HardwareResponse>(hardware); IActionResult actionResult = await CreateHardware(hardware); ObjectResult objectResult = actionResult is ObjectResult ? actionResult as ObjectResult : null; if (objectResult != null && objectResult.Value is Guid) { var identifier = objectResult.Value as Guid?; if (identifier.HasValue) { request.Id = identifier.Value; } else { Assert.Fail("Return value isn't a identifier valid"); } } else { Assert.Fail("Imposible create default record"); } return(request); }
public async Task <Guid> CreateHardwareAsync(CreateHardwareRequest request) { var id = await AddAsync(_mapper.Map <DomainModel.Hardware>(request)); await SaveAsync(); return(id); }
public async Task TestCreateHardwareAsync(CreateHardwareRequest obj, ObjectResult resultAction) { var request = AutomapperSingleton.Mapper.Map <CreateHardwareRequest>(obj); HttpResponseMessage actionResult = await _hardwareAPI.CreateHardware(request); if (actionResult.StatusCode == HttpStatusCode.OK) { dynamic id = JsonConvert.DeserializeObject(actionResult.Content.ReadAsStringAsync().Result, resultAction.Value.GetType()); HardwareComponentsValues.GuidAvailable = (Guid)id; //RecordComponentsValues.NameAvailable = obj.Name; } base.CheckAssert(actionResult, resultAction); }
public async Task TestCreateHardware(CreateHardwareRequest obj, IActionResult resultAction) { //var request = AutomapperSingleton.Mapper.Map<CreateCompanyRequest>(obj); IActionResult actionResult = await CreateHardware(obj); var objectResult = actionResult as ObjectResult; if (objectResult.StatusCode == 200) { dynamic id = Guid.Parse(objectResult.Value.ToString()); HardwareComponentsValues.GuidAvailable = (Guid)id; //RecordComponentsValues.NameAvailable = obj.Name; } base.CheckAssert(actionResult, resultAction); }
private async Task <IActionResult> CreateHardware(CreateHardwareRequest createHardwareRequest) { var options = new DbContextOptionsBuilder <Context>() .UseInMemoryDatabase(databaseName: "Hardware") .Options; // Run the test against one instance of the context using (var context = new Context(options)) { var repository = new HardwareRepository(context, AutomapperSingleton.Mapper); var service = new HardwareService(repository, AutomapperSingleton.Mapper); var controller = new HardwareController(service); Mock <HttpRequest> mockCreateRequest = MockHttpRequest.CreateMockRequest(createHardwareRequest); return(await controller.CreateHardwareAsync(mockCreateRequest.Object, _logger)); //as GridController; } }
public async Task <Guid> CreateHardwareAsync(CreateHardwareRequest request) { var id = await _hardwareRepository.CreateHardwareAsync(request); return(id); }