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 ApiMessageServerModelMapper(); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; IMessageService service = testServer.Host.Services.GetService(typeof(IMessageService)) as IMessageService; ApiMessageServerResponseModel model = await service.Get(1); ApiMessageClientRequestModel request = mapper.MapServerResponseToClientRequest(model); request.SetProperties("B", 1); UpdateResponse <ApiMessageClientResponseModel> updateResponse = await client.MessageUpdateAsync(model.MessageId, request); context.Entry(context.Set <Message>().ToList()[0]).Reload(); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); updateResponse.Record.MessageId.Should().Be(1); context.Set <Message>().ToList()[0].Content.Should().Be("B"); context.Set <Message>().ToList()[0].SenderUserId.Should().Be(1); updateResponse.Record.MessageId.Should().Be(1); updateResponse.Record.Content.Should().Be("B"); updateResponse.Record.SenderUserId.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 ApiMessageClientRequestModel(); model.SetProperties("B", 1); var model2 = new ApiMessageClientRequestModel(); model2.SetProperties("C", 1); var request = new List <ApiMessageClientRequestModel>() { model, model2 }; CreateResponse <List <ApiMessageClientResponseModel> > result = await client.MessageBulkInsertAsync(request); result.Success.Should().BeTrue(); result.Record.Should().NotBeNull(); context.Set <Message>().ToList()[1].Content.Should().Be("B"); context.Set <Message>().ToList()[1].SenderUserId.Should().Be(1); context.Set <Message>().ToList()[2].Content.Should().Be("C"); context.Set <Message>().ToList()[2].SenderUserId.Should().Be(1); }
public virtual ApiMessageClientRequestModel MapServerResponseToClientRequest( ApiMessageServerResponseModel response) { var request = new ApiMessageClientRequestModel(); request.SetProperties( response.Content, response.SenderUserId); return(request); }
public void MapClientResponseToRequest() { var mapper = new ApiMessageModelMapper(); var model = new ApiMessageClientResponseModel(); model.SetProperties(1, "A", 1); ApiMessageClientRequestModel response = mapper.MapClientResponseToRequest(model); response.Should().NotBeNull(); response.Content.Should().Be("A"); response.SenderUserId.Should().Be(1); }