public void MapClientResponseToRequest() { var mapper = new ApiTestAllFieldTypeModelMapper(); var model = new ApiTestAllFieldTypeClientResponseModel(); model.SetProperties(1, 1, BitConverter.GetBytes(1), true, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), 1m, 1, BitConverter.GetBytes(1), 1m, "A", "A", 1m, "A", 1m, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1m, "A", TimeSpan.Parse("01:00:00"), BitConverter.GetBytes(1), 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), BitConverter.GetBytes(1), "A", "A"); ApiTestAllFieldTypeClientRequestModel response = mapper.MapClientResponseToRequest(model); response.Should().NotBeNull(); response.FieldBigInt.Should().Be(1); response.FieldBinary.Should().BeEquivalentTo(BitConverter.GetBytes(1)); response.FieldBit.Should().Be(true); response.FieldChar.Should().Be("A"); response.FieldDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.FieldDateTime.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.FieldDateTime2.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.FieldDateTimeOffset.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM")); response.FieldDecimal.Should().Be(1m); response.FieldFloat.Should().Be(1); response.FieldImage.Should().BeEquivalentTo(BitConverter.GetBytes(1)); response.FieldMoney.Should().Be(1m); response.FieldNChar.Should().Be("A"); response.FieldNText.Should().Be("A"); response.FieldNumeric.Should().Be(1m); response.FieldNVarchar.Should().Be("A"); response.FieldReal.Should().Be(1m); response.FieldSmallDateTime.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.FieldSmallInt.Should().Be(1); response.FieldSmallMoney.Should().Be(1m); response.FieldText.Should().Be("A"); response.FieldTime.Should().Be(TimeSpan.Parse("01:00:00")); response.FieldTimestamp.Should().BeEquivalentTo(BitConverter.GetBytes(1)); response.FieldTinyInt.Should().Be(1); response.FieldUniqueIdentifier.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.FieldVarBinary.Should().BeEquivalentTo(BitConverter.GetBytes(1)); response.FieldVarchar.Should().Be("A"); response.FieldXML.Should().Be("A"); }
public virtual ApiTestAllFieldTypeClientRequestModel MapServerResponseToClientRequest( ApiTestAllFieldTypeServerResponseModel response) { var request = new ApiTestAllFieldTypeClientRequestModel(); request.SetProperties( response.FieldBigInt, response.FieldBinary, response.FieldBit, response.FieldChar, response.FieldDate, response.FieldDateTime, response.FieldDateTime2, response.FieldDateTimeOffset, response.FieldDecimal, response.FieldFloat, response.FieldImage, response.FieldMoney, response.FieldNChar, response.FieldNText, response.FieldNumeric, response.FieldNVarchar, response.FieldReal, response.FieldSmallDateTime, response.FieldSmallInt, response.FieldSmallMoney, response.FieldText, response.FieldTime, response.FieldTimestamp, response.FieldTinyInt, response.FieldUniqueIdentifier, response.FieldVarBinary, response.FieldVarchar, response.FieldXML); return(request); }
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 ApiTestAllFieldTypeClientRequestModel(); model.SetProperties(2, BitConverter.GetBytes(2), true, "B", DateTime.Parse("1/1/1988 12:00:00 AM"), DateTime.Parse("1/1/1988 12:00:00 AM"), DateTime.Parse("1/1/1988 12:00:00 AM"), DateTimeOffset.Parse("1/1/1988 12:00:00 AM"), 2m, 2, BitConverter.GetBytes(2), 2m, "B", "B", 2m, "B", 2m, DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 2m, "B", TimeSpan.Parse("02:00:00"), BitConverter.GetBytes(2), 2, Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), BitConverter.GetBytes(2), "B", "B"); var model2 = new ApiTestAllFieldTypeClientRequestModel(); model2.SetProperties(3, BitConverter.GetBytes(3), true, "C", DateTime.Parse("1/1/1989 12:00:00 AM"), DateTime.Parse("1/1/1989 12:00:00 AM"), DateTime.Parse("1/1/1989 12:00:00 AM"), DateTimeOffset.Parse("1/1/1989 12:00:00 AM"), 3m, 3, BitConverter.GetBytes(3), 3m, "C", "C", 3m, "C", 3m, DateTime.Parse("1/1/1989 12:00:00 AM"), 3, 3m, "C", TimeSpan.Parse("03:00:00"), BitConverter.GetBytes(3), 3, Guid.Parse("8d721ec8-4c9d-632f-6f06-7f89cc14862c"), BitConverter.GetBytes(3), "C", "C"); var request = new List <ApiTestAllFieldTypeClientRequestModel>() { model, model2 }; CreateResponse <List <ApiTestAllFieldTypeClientResponseModel> > result = await client.TestAllFieldTypeBulkInsertAsync(request); result.Success.Should().BeTrue(); result.Record.Should().NotBeNull(); context.Set <TestAllFieldType>().ToList()[1].FieldBigInt.Should().Be(2); context.Set <TestAllFieldType>().ToList()[1].FieldBinary.Should().BeEquivalentTo(BitConverter.GetBytes(2)); context.Set <TestAllFieldType>().ToList()[1].FieldBit.Should().Be(true); context.Set <TestAllFieldType>().ToList()[1].FieldChar.Should().Be("B"); context.Set <TestAllFieldType>().ToList()[1].FieldDate.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); context.Set <TestAllFieldType>().ToList()[1].FieldDateTime.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); context.Set <TestAllFieldType>().ToList()[1].FieldDateTime2.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); context.Set <TestAllFieldType>().ToList()[1].FieldDateTimeOffset.Should().Be(DateTimeOffset.Parse("1/1/1988 12:00:00 AM")); context.Set <TestAllFieldType>().ToList()[1].FieldDecimal.Should().Be(2m); context.Set <TestAllFieldType>().ToList()[1].FieldFloat.Should().Be(2); context.Set <TestAllFieldType>().ToList()[1].FieldImage.Should().BeEquivalentTo(BitConverter.GetBytes(2)); context.Set <TestAllFieldType>().ToList()[1].FieldMoney.Should().Be(2m); context.Set <TestAllFieldType>().ToList()[1].FieldNChar.Should().Be("B"); context.Set <TestAllFieldType>().ToList()[1].FieldNText.Should().Be("B"); context.Set <TestAllFieldType>().ToList()[1].FieldNumeric.Should().Be(2m); context.Set <TestAllFieldType>().ToList()[1].FieldNVarchar.Should().Be("B"); context.Set <TestAllFieldType>().ToList()[1].FieldReal.Should().Be(2m); context.Set <TestAllFieldType>().ToList()[1].FieldSmallDateTime.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); context.Set <TestAllFieldType>().ToList()[1].FieldSmallInt.Should().Be(2); context.Set <TestAllFieldType>().ToList()[1].FieldSmallMoney.Should().Be(2m); context.Set <TestAllFieldType>().ToList()[1].FieldText.Should().Be("B"); context.Set <TestAllFieldType>().ToList()[1].FieldTime.Should().Be(TimeSpan.Parse("02:00:00")); context.Set <TestAllFieldType>().ToList()[1].FieldTimestamp.Should().BeEquivalentTo(BitConverter.GetBytes(2)); context.Set <TestAllFieldType>().ToList()[1].FieldTinyInt.Should().Be(2); context.Set <TestAllFieldType>().ToList()[1].FieldUniqueIdentifier.Should().Be(Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b")); context.Set <TestAllFieldType>().ToList()[1].FieldVarBinary.Should().BeEquivalentTo(BitConverter.GetBytes(2)); context.Set <TestAllFieldType>().ToList()[1].FieldVarchar.Should().Be("B"); context.Set <TestAllFieldType>().ToList()[1].FieldXML.Should().Be("B"); context.Set <TestAllFieldType>().ToList()[2].FieldBigInt.Should().Be(3); context.Set <TestAllFieldType>().ToList()[2].FieldBinary.Should().BeEquivalentTo(BitConverter.GetBytes(3)); context.Set <TestAllFieldType>().ToList()[2].FieldBit.Should().Be(true); context.Set <TestAllFieldType>().ToList()[2].FieldChar.Should().Be("C"); context.Set <TestAllFieldType>().ToList()[2].FieldDate.Should().Be(DateTime.Parse("1/1/1989 12:00:00 AM")); context.Set <TestAllFieldType>().ToList()[2].FieldDateTime.Should().Be(DateTime.Parse("1/1/1989 12:00:00 AM")); context.Set <TestAllFieldType>().ToList()[2].FieldDateTime2.Should().Be(DateTime.Parse("1/1/1989 12:00:00 AM")); context.Set <TestAllFieldType>().ToList()[2].FieldDateTimeOffset.Should().Be(DateTimeOffset.Parse("1/1/1989 12:00:00 AM")); context.Set <TestAllFieldType>().ToList()[2].FieldDecimal.Should().Be(3m); context.Set <TestAllFieldType>().ToList()[2].FieldFloat.Should().Be(3); context.Set <TestAllFieldType>().ToList()[2].FieldImage.Should().BeEquivalentTo(BitConverter.GetBytes(3)); context.Set <TestAllFieldType>().ToList()[2].FieldMoney.Should().Be(3m); context.Set <TestAllFieldType>().ToList()[2].FieldNChar.Should().Be("C"); context.Set <TestAllFieldType>().ToList()[2].FieldNText.Should().Be("C"); context.Set <TestAllFieldType>().ToList()[2].FieldNumeric.Should().Be(3m); context.Set <TestAllFieldType>().ToList()[2].FieldNVarchar.Should().Be("C"); context.Set <TestAllFieldType>().ToList()[2].FieldReal.Should().Be(3m); context.Set <TestAllFieldType>().ToList()[2].FieldSmallDateTime.Should().Be(DateTime.Parse("1/1/1989 12:00:00 AM")); context.Set <TestAllFieldType>().ToList()[2].FieldSmallInt.Should().Be(3); context.Set <TestAllFieldType>().ToList()[2].FieldSmallMoney.Should().Be(3m); context.Set <TestAllFieldType>().ToList()[2].FieldText.Should().Be("C"); context.Set <TestAllFieldType>().ToList()[2].FieldTime.Should().Be(TimeSpan.Parse("03:00:00")); context.Set <TestAllFieldType>().ToList()[2].FieldTimestamp.Should().BeEquivalentTo(BitConverter.GetBytes(3)); context.Set <TestAllFieldType>().ToList()[2].FieldTinyInt.Should().Be(3); context.Set <TestAllFieldType>().ToList()[2].FieldUniqueIdentifier.Should().Be(Guid.Parse("8d721ec8-4c9d-632f-6f06-7f89cc14862c")); context.Set <TestAllFieldType>().ToList()[2].FieldVarBinary.Should().BeEquivalentTo(BitConverter.GetBytes(3)); context.Set <TestAllFieldType>().ToList()[2].FieldVarchar.Should().Be("C"); context.Set <TestAllFieldType>().ToList()[2].FieldXML.Should().Be("C"); }
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 ApiTestAllFieldTypeServerModelMapper(); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; ITestAllFieldTypeService service = testServer.Host.Services.GetService(typeof(ITestAllFieldTypeService)) as ITestAllFieldTypeService; ApiTestAllFieldTypeServerResponseModel model = await service.Get(1); ApiTestAllFieldTypeClientRequestModel request = mapper.MapServerResponseToClientRequest(model); request.SetProperties(2, BitConverter.GetBytes(2), true, "B", DateTime.Parse("1/1/1988 12:00:00 AM"), DateTime.Parse("1/1/1988 12:00:00 AM"), DateTime.Parse("1/1/1988 12:00:00 AM"), DateTimeOffset.Parse("1/1/1988 12:00:00 AM"), 2m, 2, BitConverter.GetBytes(2), 2m, "B", "B", 2m, "B", 2m, DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 2m, "B", TimeSpan.Parse("02:00:00"), BitConverter.GetBytes(2), 2, Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), BitConverter.GetBytes(2), "B", "B"); UpdateResponse <ApiTestAllFieldTypeClientResponseModel> updateResponse = await client.TestAllFieldTypeUpdateAsync(model.Id, request); context.Entry(context.Set <TestAllFieldType>().ToList()[0]).Reload(); updateResponse.Record.Should().NotBeNull(); updateResponse.Success.Should().BeTrue(); updateResponse.Record.Id.Should().Be(1); context.Set <TestAllFieldType>().ToList()[0].FieldBigInt.Should().Be(2); context.Set <TestAllFieldType>().ToList()[0].FieldBinary.Should().BeEquivalentTo(BitConverter.GetBytes(2)); context.Set <TestAllFieldType>().ToList()[0].FieldBit.Should().Be(true); context.Set <TestAllFieldType>().ToList()[0].FieldChar.Should().Be("B"); context.Set <TestAllFieldType>().ToList()[0].FieldDate.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); context.Set <TestAllFieldType>().ToList()[0].FieldDateTime.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); context.Set <TestAllFieldType>().ToList()[0].FieldDateTime2.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); context.Set <TestAllFieldType>().ToList()[0].FieldDateTimeOffset.Should().Be(DateTimeOffset.Parse("1/1/1988 12:00:00 AM")); context.Set <TestAllFieldType>().ToList()[0].FieldDecimal.Should().Be(2m); context.Set <TestAllFieldType>().ToList()[0].FieldFloat.Should().Be(2); context.Set <TestAllFieldType>().ToList()[0].FieldImage.Should().BeEquivalentTo(BitConverter.GetBytes(2)); context.Set <TestAllFieldType>().ToList()[0].FieldMoney.Should().Be(2m); context.Set <TestAllFieldType>().ToList()[0].FieldNChar.Should().Be("B"); context.Set <TestAllFieldType>().ToList()[0].FieldNText.Should().Be("B"); context.Set <TestAllFieldType>().ToList()[0].FieldNumeric.Should().Be(2m); context.Set <TestAllFieldType>().ToList()[0].FieldNVarchar.Should().Be("B"); context.Set <TestAllFieldType>().ToList()[0].FieldReal.Should().Be(2m); context.Set <TestAllFieldType>().ToList()[0].FieldSmallDateTime.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); context.Set <TestAllFieldType>().ToList()[0].FieldSmallInt.Should().Be(2); context.Set <TestAllFieldType>().ToList()[0].FieldSmallMoney.Should().Be(2m); context.Set <TestAllFieldType>().ToList()[0].FieldText.Should().Be("B"); context.Set <TestAllFieldType>().ToList()[0].FieldTime.Should().Be(TimeSpan.Parse("02:00:00")); context.Set <TestAllFieldType>().ToList()[0].FieldTimestamp.Should().BeEquivalentTo(BitConverter.GetBytes(2)); context.Set <TestAllFieldType>().ToList()[0].FieldTinyInt.Should().Be(2); context.Set <TestAllFieldType>().ToList()[0].FieldUniqueIdentifier.Should().Be(Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b")); context.Set <TestAllFieldType>().ToList()[0].FieldVarBinary.Should().BeEquivalentTo(BitConverter.GetBytes(2)); context.Set <TestAllFieldType>().ToList()[0].FieldVarchar.Should().Be("B"); context.Set <TestAllFieldType>().ToList()[0].FieldXML.Should().Be("B"); updateResponse.Record.Id.Should().Be(1); updateResponse.Record.FieldBigInt.Should().Be(2); updateResponse.Record.FieldBinary.Should().BeEquivalentTo(BitConverter.GetBytes(2)); updateResponse.Record.FieldBit.Should().Be(true); updateResponse.Record.FieldChar.Should().Be("B"); updateResponse.Record.FieldDate.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); updateResponse.Record.FieldDateTime.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); updateResponse.Record.FieldDateTime2.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); updateResponse.Record.FieldDateTimeOffset.Should().Be(DateTimeOffset.Parse("1/1/1988 12:00:00 AM")); updateResponse.Record.FieldDecimal.Should().Be(2m); updateResponse.Record.FieldFloat.Should().Be(2); updateResponse.Record.FieldImage.Should().BeEquivalentTo(BitConverter.GetBytes(2)); updateResponse.Record.FieldMoney.Should().Be(2m); updateResponse.Record.FieldNChar.Should().Be("B"); updateResponse.Record.FieldNText.Should().Be("B"); updateResponse.Record.FieldNumeric.Should().Be(2m); updateResponse.Record.FieldNVarchar.Should().Be("B"); updateResponse.Record.FieldReal.Should().Be(2m); updateResponse.Record.FieldSmallDateTime.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM")); updateResponse.Record.FieldSmallInt.Should().Be(2); updateResponse.Record.FieldSmallMoney.Should().Be(2m); updateResponse.Record.FieldText.Should().Be("B"); updateResponse.Record.FieldTime.Should().Be(TimeSpan.Parse("02:00:00")); updateResponse.Record.FieldTimestamp.Should().BeEquivalentTo(BitConverter.GetBytes(2)); updateResponse.Record.FieldTinyInt.Should().Be(2); updateResponse.Record.FieldUniqueIdentifier.Should().Be(Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b")); updateResponse.Record.FieldVarBinary.Should().BeEquivalentTo(BitConverter.GetBytes(2)); updateResponse.Record.FieldVarchar.Should().Be("B"); updateResponse.Record.FieldXML.Should().Be("B"); }