public virtual async void TestDelete() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); client.SetBearerToken(JWTTestHelper.GenerateBearerToken()); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; IMachineService service = testServer.Host.Services.GetService(typeof(IMachineService)) as IMachineService; var model = new ApiMachineServerRequestModel(); model.SetProperties("B", "B", "B", Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), "B"); CreateResponse <ApiMachineServerResponseModel> createdResponse = await service.Create(model); createdResponse.Success.Should().BeTrue(); ActionResponse deleteResult = await client.MachineDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiMachineServerResponseModel verifyResponse = await service.Get(2); verifyResponse.Should().BeNull(); }
public async Task <Machine> Get(int id) { if (id == -1) { return(await _service.DefaultMachine()); } return(await _service.Get(id)); }
public IActionResult GetById(string id) { if (id.Equals(null)) { return(BadRequest()); } var machine = machineService.Get(id); if (machine.Equals(null)) { return(NotFound()); } return(Ok(machine)); }
public virtual async void TestUpdate() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); client.SetBearerToken(JWTTestHelper.GenerateBearerToken()); var mapper = new ApiMachineServerModelMapper(); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; IMachineService service = testServer.Host.Services.GetService(typeof(IMachineService)) as IMachineService; ApiMachineServerResponseModel model = await service.Get(1); ApiMachineClientRequestModel request = mapper.MapServerResponseToClientRequest(model); request.SetProperties("B", "B", "B", Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), "B"); UpdateResponse <ApiMachineClientResponseModel> updateResponse = await client.MachineUpdateAsync(model.Id, request); context.Entry(context.Set <Machine>().ToList()[0]).Reload(); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); updateResponse.Record.Id.Should().Be(1); context.Set <Machine>().ToList()[0].Description.Should().Be("B"); context.Set <Machine>().ToList()[0].JwtKey.Should().Be("B"); context.Set <Machine>().ToList()[0].LastIpAddress.Should().Be("B"); context.Set <Machine>().ToList()[0].MachineGuid.Should().Be(Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b")); context.Set <Machine>().ToList()[0].Name.Should().Be("B"); updateResponse.Record.Id.Should().Be(1); updateResponse.Record.Description.Should().Be("B"); updateResponse.Record.JwtKey.Should().Be("B"); updateResponse.Record.LastIpAddress.Should().Be("B"); updateResponse.Record.MachineGuid.Should().Be(Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b")); updateResponse.Record.Name.Should().Be("B"); }
public IActionResult Get(string id) { return(Ok(_machineService.Get(id))); }