public void MapServerResponseToRequest() { var mapper = new ApiMachineServerModelMapper(); var model = new ApiMachineServerResponseModel(); model.SetProperties(1, "A", "A", "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), "A"); ApiMachineServerRequestModel response = mapper.MapServerResponseToRequest(model); response.Should().NotBeNull(); response.Description.Should().Be("A"); response.JwtKey.Should().Be("A"); response.LastIpAddress.Should().Be("A"); response.MachineGuid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.Name.Should().Be("A"); }
public void CreatePatch() { var mapper = new ApiMachineServerModelMapper(); var model = new ApiMachineServerRequestModel(); model.SetProperties("A", "A", "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), "A"); JsonPatchDocument <ApiMachineServerRequestModel> patch = mapper.CreatePatch(model); var response = new ApiMachineServerRequestModel(); patch.ApplyTo(response); response.Description.Should().Be("A"); response.JwtKey.Should().Be("A"); response.LastIpAddress.Should().Be("A"); response.MachineGuid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.Name.Should().Be("A"); }
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"); }