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 ApiVideoServerModelMapper(); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; IVideoService service = testServer.Host.Services.GetService(typeof(IVideoService)) as IVideoService; ApiVideoServerResponseModel model = await service.Get(1); ApiVideoClientRequestModel request = mapper.MapServerResponseToClientRequest(model); request.SetProperties("B", "B", "B"); UpdateResponse <ApiVideoClientResponseModel> updateResponse = await client.VideoUpdateAsync(model.Id, request); context.Entry(context.Set <Video>().ToList()[0]).Reload(); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); updateResponse.Record.Id.Should().Be(1); context.Set <Video>().ToList()[0].Description.Should().Be("B"); context.Set <Video>().ToList()[0].Title.Should().Be("B"); context.Set <Video>().ToList()[0].Url.Should().Be("B"); updateResponse.Record.Id.Should().Be(1); updateResponse.Record.Description.Should().Be("B"); updateResponse.Record.Title.Should().Be("B"); updateResponse.Record.Url.Should().Be("B"); }
public virtual async void TestCreate() { 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; var model = new ApiVideoClientRequestModel(); model.SetProperties("B", "B", "B"); CreateResponse <ApiVideoClientResponseModel> result = await client.VideoCreateAsync(model); result.Success.Should().BeTrue(); result.Record.Should().NotBeNull(); context.Set <Video>().ToList()[1].Description.Should().Be("B"); context.Set <Video>().ToList()[1].Title.Should().Be("B"); context.Set <Video>().ToList()[1].Url.Should().Be("B"); result.Record.Description.Should().Be("B"); result.Record.Title.Should().Be("B"); result.Record.Url.Should().Be("B"); }
public virtual ApiVideoClientRequestModel MapServerResponseToClientRequest( ApiVideoServerResponseModel response) { var request = new ApiVideoClientRequestModel(); request.SetProperties( response.Description, response.Title, response.Url); return(request); }
public void MapClientRequestToResponse() { var mapper = new ApiVideoModelMapper(); var model = new ApiVideoClientRequestModel(); model.SetProperties("A", "A", "A"); ApiVideoClientResponseModel response = mapper.MapClientRequestToResponse(1, model); response.Should().NotBeNull(); response.Description.Should().Be("A"); response.Title.Should().Be("A"); response.Url.Should().Be("A"); }