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 ApiStudentClientRequestModel(); model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B", true, 1, "B", true, "B", "B", true, 1); var model2 = new ApiStudentClientRequestModel(); model2.SetProperties(DateTime.Parse("1/1/1989 12:00:00 AM"), "C", true, 1, "C", true, "C", "C", true, 1); var request = new List <ApiStudentClientRequestModel>() { model, model2 }; CreateResponse <List <ApiStudentClientResponseModel> > result = await client.StudentBulkInsertAsync(request); result.Success.Should().BeTrue(); result.Record.Should().NotBeNull(); context.Set <Student>().ToList()[1].Birthday.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); context.Set <Student>().ToList()[1].Email.Should().Be("B"); context.Set <Student>().ToList()[1].EmailRemindersEnabled.Should().Be(true); context.Set <Student>().ToList()[1].FamilyId.Should().Be(1); context.Set <Student>().ToList()[1].FirstName.Should().Be("B"); context.Set <Student>().ToList()[1].IsAdult.Should().Be(true); context.Set <Student>().ToList()[1].LastName.Should().Be("B"); context.Set <Student>().ToList()[1].Phone.Should().Be("B"); context.Set <Student>().ToList()[1].SmsRemindersEnabled.Should().Be(true); context.Set <Student>().ToList()[1].UserId.Should().Be(1); context.Set <Student>().ToList()[2].Birthday.Should().Be(DateTime.Parse("1/1/1989 12:00:00 AM")); context.Set <Student>().ToList()[2].Email.Should().Be("C"); context.Set <Student>().ToList()[2].EmailRemindersEnabled.Should().Be(true); context.Set <Student>().ToList()[2].FamilyId.Should().Be(1); context.Set <Student>().ToList()[2].FirstName.Should().Be("C"); context.Set <Student>().ToList()[2].IsAdult.Should().Be(true); context.Set <Student>().ToList()[2].LastName.Should().Be("C"); context.Set <Student>().ToList()[2].Phone.Should().Be("C"); context.Set <Student>().ToList()[2].SmsRemindersEnabled.Should().Be(true); context.Set <Student>().ToList()[2].UserId.Should().Be(1); }
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 ApiStudentServerModelMapper(); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; IStudentService service = testServer.Host.Services.GetService(typeof(IStudentService)) as IStudentService; ApiStudentServerResponseModel model = await service.Get(1); ApiStudentClientRequestModel request = mapper.MapServerResponseToClientRequest(model); request.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B", true, 1, "B", true, "B", "B", true, 1); UpdateResponse <ApiStudentClientResponseModel> updateResponse = await client.StudentUpdateAsync(model.Id, request); context.Entry(context.Set <Student>().ToList()[0]).Reload(); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); updateResponse.Record.Id.Should().Be(1); context.Set <Student>().ToList()[0].Birthday.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); context.Set <Student>().ToList()[0].Email.Should().Be("B"); context.Set <Student>().ToList()[0].EmailRemindersEnabled.Should().Be(true); context.Set <Student>().ToList()[0].FamilyId.Should().Be(1); context.Set <Student>().ToList()[0].FirstName.Should().Be("B"); context.Set <Student>().ToList()[0].IsAdult.Should().Be(true); context.Set <Student>().ToList()[0].LastName.Should().Be("B"); context.Set <Student>().ToList()[0].Phone.Should().Be("B"); context.Set <Student>().ToList()[0].SmsRemindersEnabled.Should().Be(true); context.Set <Student>().ToList()[0].UserId.Should().Be(1); updateResponse.Record.Id.Should().Be(1); updateResponse.Record.Birthday.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); updateResponse.Record.Email.Should().Be("B"); updateResponse.Record.EmailRemindersEnabled.Should().Be(true); updateResponse.Record.FamilyId.Should().Be(1); updateResponse.Record.FirstName.Should().Be("B"); updateResponse.Record.IsAdult.Should().Be(true); updateResponse.Record.LastName.Should().Be("B"); updateResponse.Record.Phone.Should().Be("B"); updateResponse.Record.SmsRemindersEnabled.Should().Be(true); updateResponse.Record.UserId.Should().Be(1); }
public virtual ApiStudentClientRequestModel MapServerResponseToClientRequest( ApiStudentServerResponseModel response) { var request = new ApiStudentClientRequestModel(); request.SetProperties( response.Birthday, response.Email, response.EmailRemindersEnabled, response.FamilyId, response.FirstName, response.IsAdult, response.LastName, response.Phone, response.SmsRemindersEnabled, response.UserId); return(request); }
public void MapClientResponseToRequest() { var mapper = new ApiStudentModelMapper(); var model = new ApiStudentClientResponseModel(); model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", true, 1, "A", true, "A", "A", true, 1); ApiStudentClientRequestModel response = mapper.MapClientResponseToRequest(model); response.Should().NotBeNull(); response.Birthday.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Email.Should().Be("A"); response.EmailRemindersEnabled.Should().Be(true); response.FamilyId.Should().Be(1); response.FirstName.Should().Be("A"); response.IsAdult.Should().Be(true); response.LastName.Should().Be("A"); response.Phone.Should().Be("A"); response.SmsRemindersEnabled.Should().Be(true); response.UserId.Should().Be(1); }