public virtual async void TestGetFound() { 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; ApiPenClientResponseModel response = await client.PenGetAsync(1); response.Should().NotBeNull(); response.Id.Should().Be(1); response.Name.Should().Be("A"); }
public virtual async void TestAll() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); client.SetBearerToken(JWTTestHelper.GenerateBearerToken()); List <ApiPetClientResponseModel> response = await client.PetAllAsync(); response.Count.Should().BeGreaterThan(0); response[0].AcquiredDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response[0].BreedId.Should().Be(1); response[0].Description.Should().Be("A"); response[0].Id.Should().Be(1); response[0].PenId.Should().Be(1); response[0].Price.Should().Be(1m); }
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 ApiSaleClientRequestModel(); model.SetProperties(2m, "B", "B", 1, 1, "B"); var model2 = new ApiSaleClientRequestModel(); model2.SetProperties(3m, "C", "C", 1, 1, "C"); var request = new List <ApiSaleClientRequestModel>() { model, model2 }; CreateResponse <List <ApiSaleClientResponseModel> > result = await client.SaleBulkInsertAsync(request); result.Success.Should().BeTrue(); result.Record.Should().NotBeNull(); context.Set <Sale>().ToList()[1].Amount.Should().Be(2m); context.Set <Sale>().ToList()[1].FirstName.Should().Be("B"); context.Set <Sale>().ToList()[1].LastName.Should().Be("B"); context.Set <Sale>().ToList()[1].PaymentTypeId.Should().Be(1); context.Set <Sale>().ToList()[1].PetId.Should().Be(1); context.Set <Sale>().ToList()[1].Phone.Should().Be("B"); context.Set <Sale>().ToList()[2].Amount.Should().Be(3m); context.Set <Sale>().ToList()[2].FirstName.Should().Be("C"); context.Set <Sale>().ToList()[2].LastName.Should().Be("C"); context.Set <Sale>().ToList()[2].PaymentTypeId.Should().Be(1); context.Set <Sale>().ToList()[2].PetId.Should().Be(1); context.Set <Sale>().ToList()[2].Phone.Should().Be("C"); }
public virtual async void TestAll() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); client.SetBearerToken(JWTTestHelper.GenerateBearerToken()); List <ApiSaleClientResponseModel> response = await client.SaleAllAsync(); response.Count.Should().BeGreaterThan(0); response[0].Amount.Should().Be(1m); response[0].FirstName.Should().Be("A"); response[0].Id.Should().Be(1); response[0].LastName.Should().Be("A"); response[0].PaymentTypeId.Should().Be(1); response[0].PetId.Should().Be(1); response[0].Phone.Should().Be("A"); }
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 ApiSaleServerModelMapper(); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; ISaleService service = testServer.Host.Services.GetService(typeof(ISaleService)) as ISaleService; ApiSaleServerResponseModel model = await service.Get(1); ApiSaleClientRequestModel request = mapper.MapServerResponseToClientRequest(model); request.SetProperties(2m, "B", "B", 1, 1, "B"); UpdateResponse <ApiSaleClientResponseModel> updateResponse = await client.SaleUpdateAsync(model.Id, request); context.Entry(context.Set <Sale>().ToList()[0]).Reload(); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); updateResponse.Record.Id.Should().Be(1); context.Set <Sale>().ToList()[0].Amount.Should().Be(2m); context.Set <Sale>().ToList()[0].FirstName.Should().Be("B"); context.Set <Sale>().ToList()[0].LastName.Should().Be("B"); context.Set <Sale>().ToList()[0].PaymentTypeId.Should().Be(1); context.Set <Sale>().ToList()[0].PetId.Should().Be(1); context.Set <Sale>().ToList()[0].Phone.Should().Be("B"); updateResponse.Record.Id.Should().Be(1); updateResponse.Record.Amount.Should().Be(2m); updateResponse.Record.FirstName.Should().Be("B"); updateResponse.Record.LastName.Should().Be("B"); updateResponse.Record.PaymentTypeId.Should().Be(1); updateResponse.Record.PetId.Should().Be(1); updateResponse.Record.Phone.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 ApiPenClientRequestModel(); model.SetProperties("B"); CreateResponse <ApiPenClientResponseModel> result = await client.PenCreateAsync(model); result.Success.Should().BeTrue(); result.Record.Should().NotBeNull(); context.Set <Pen>().ToList()[1].Name.Should().Be("B"); result.Record.Name.Should().Be("B"); }
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 ApiPetClientRequestModel(); model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), 1, "B", 1, 2m); var model2 = new ApiPetClientRequestModel(); model2.SetProperties(DateTime.Parse("1/1/1989 12:00:00 AM"), 1, "C", 1, 3m); var request = new List <ApiPetClientRequestModel>() { model, model2 }; CreateResponse <List <ApiPetClientResponseModel> > result = await client.PetBulkInsertAsync(request); result.Success.Should().BeTrue(); result.Record.Should().NotBeNull(); context.Set <Pet>().ToList()[1].AcquiredDate.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); context.Set <Pet>().ToList()[1].BreedId.Should().Be(1); context.Set <Pet>().ToList()[1].Description.Should().Be("B"); context.Set <Pet>().ToList()[1].PenId.Should().Be(1); context.Set <Pet>().ToList()[1].Price.Should().Be(2m); context.Set <Pet>().ToList()[2].AcquiredDate.Should().Be(DateTime.Parse("1/1/1989 12:00:00 AM")); context.Set <Pet>().ToList()[2].BreedId.Should().Be(1); context.Set <Pet>().ToList()[2].Description.Should().Be("C"); context.Set <Pet>().ToList()[2].PenId.Should().Be(1); context.Set <Pet>().ToList()[2].Price.Should().Be(3m); }
public virtual async void TestGetFound() { 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; ApiPetClientResponseModel response = await client.PetGetAsync(1); response.Should().NotBeNull(); response.AcquiredDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.BreedId.Should().Be(1); response.Description.Should().Be("A"); response.Id.Should().Be(1); response.PenId.Should().Be(1); response.Price.Should().Be(1m); }
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 ApiPetServerModelMapper(); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; IPetService service = testServer.Host.Services.GetService(typeof(IPetService)) as IPetService; ApiPetServerResponseModel model = await service.Get(1); ApiPetClientRequestModel request = mapper.MapServerResponseToClientRequest(model); request.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), 1, "B", 1, 2m); UpdateResponse <ApiPetClientResponseModel> updateResponse = await client.PetUpdateAsync(model.Id, request); context.Entry(context.Set <Pet>().ToList()[0]).Reload(); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); updateResponse.Record.Id.Should().Be(1); context.Set <Pet>().ToList()[0].AcquiredDate.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); context.Set <Pet>().ToList()[0].BreedId.Should().Be(1); context.Set <Pet>().ToList()[0].Description.Should().Be("B"); context.Set <Pet>().ToList()[0].PenId.Should().Be(1); context.Set <Pet>().ToList()[0].Price.Should().Be(2m); updateResponse.Record.Id.Should().Be(1); updateResponse.Record.AcquiredDate.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); updateResponse.Record.BreedId.Should().Be(1); updateResponse.Record.Description.Should().Be("B"); updateResponse.Record.PenId.Should().Be(1); updateResponse.Record.Price.Should().Be(2m); }