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 ApiEventStudentServerModelMapper(); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; IEventStudentService service = testServer.Host.Services.GetService(typeof(IEventStudentService)) as IEventStudentService; ApiEventStudentServerResponseModel model = await service.Get(1); ApiEventStudentClientRequestModel request = mapper.MapServerResponseToClientRequest(model); request.SetProperties(1, 1); UpdateResponse <ApiEventStudentClientResponseModel> updateResponse = await client.EventStudentUpdateAsync(model.Id, request); context.Entry(context.Set <EventStudent>().ToList()[0]).Reload(); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); updateResponse.Record.Id.Should().Be(1); context.Set <EventStudent>().ToList()[0].EventId.Should().Be(1); context.Set <EventStudent>().ToList()[0].StudentId.Should().Be(1); updateResponse.Record.Id.Should().Be(1); updateResponse.Record.EventId.Should().Be(1); updateResponse.Record.StudentId.Should().Be(1); }
public virtual async void TestBulkInsert() { 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 ApiEventStudentClientRequestModel(); model.SetProperties(1, 1); var model2 = new ApiEventStudentClientRequestModel(); model2.SetProperties(1, 1); var request = new List <ApiEventStudentClientRequestModel>() { model, model2 }; CreateResponse <List <ApiEventStudentClientResponseModel> > result = await client.EventStudentBulkInsertAsync(request); result.Success.Should().BeTrue(); result.Record.Should().NotBeNull(); context.Set <EventStudent>().ToList()[1].EventId.Should().Be(1); context.Set <EventStudent>().ToList()[1].StudentId.Should().Be(1); context.Set <EventStudent>().ToList()[2].EventId.Should().Be(1); context.Set <EventStudent>().ToList()[2].StudentId.Should().Be(1); }
public virtual ApiEventStudentClientRequestModel MapServerResponseToClientRequest( ApiEventStudentServerResponseModel response) { var request = new ApiEventStudentClientRequestModel(); request.SetProperties( response.EventId, response.StudentId); return(request); }
public void MapClientResponseToRequest() { var mapper = new ApiEventStudentModelMapper(); var model = new ApiEventStudentClientResponseModel(); model.SetProperties(1, 1, 1); ApiEventStudentClientRequestModel response = mapper.MapClientResponseToRequest(model); response.Should().NotBeNull(); response.EventId.Should().Be(1); response.StudentId.Should().Be(1); }