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 ApiRateServerModelMapper(); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; IRateService service = testServer.Host.Services.GetService(typeof(IRateService)) as IRateService; ApiRateServerResponseModel model = await service.Get(1); ApiRateClientRequestModel request = mapper.MapServerResponseToClientRequest(model); request.SetProperties(2m, 1, 1); UpdateResponse <ApiRateClientResponseModel> updateResponse = await client.RateUpdateAsync(model.Id, request); context.Entry(context.Set <Rate>().ToList()[0]).Reload(); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); updateResponse.Record.Id.Should().Be(1); context.Set <Rate>().ToList()[0].AmountPerMinute.Should().Be(2m); context.Set <Rate>().ToList()[0].TeacherId.Should().Be(1); context.Set <Rate>().ToList()[0].TeacherSkillId.Should().Be(1); updateResponse.Record.Id.Should().Be(1); updateResponse.Record.AmountPerMinute.Should().Be(2m); updateResponse.Record.TeacherId.Should().Be(1); updateResponse.Record.TeacherSkillId.Should().Be(1); }
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 ApiRateClientRequestModel(); model.SetProperties(2m, 1, 1); CreateResponse <ApiRateClientResponseModel> result = await client.RateCreateAsync(model); result.Success.Should().BeTrue(); result.Record.Should().NotBeNull(); context.Set <Rate>().ToList()[1].AmountPerMinute.Should().Be(2m); context.Set <Rate>().ToList()[1].TeacherId.Should().Be(1); context.Set <Rate>().ToList()[1].TeacherSkillId.Should().Be(1); result.Record.AmountPerMinute.Should().Be(2m); result.Record.TeacherId.Should().Be(1); result.Record.TeacherSkillId.Should().Be(1); }
public virtual ApiRateClientRequestModel MapServerResponseToClientRequest( ApiRateServerResponseModel response) { var request = new ApiRateClientRequestModel(); request.SetProperties( response.AmountPerMinute, response.TeacherId, response.TeacherSkillId); return(request); }
public void MapClientResponseToRequest() { var mapper = new ApiRateModelMapper(); var model = new ApiRateClientResponseModel(); model.SetProperties(1, 1m, 1, 1); ApiRateClientRequestModel response = mapper.MapClientResponseToRequest(model); response.Should().NotBeNull(); response.AmountPerMinute.Should().Be(1m); response.TeacherId.Should().Be(1); response.TeacherSkillId.Should().Be(1); }