public async Task Inity() { //1、声明一个调度工厂 //2、通过调度工厂获得调度器 Scheduler = await schedulerFactory.GetScheduler(); DBConnectionManager.Instance.AddConnectionProvider("default", new DbProvider("SQLite-Microsoft", SqliteHelper.dataSource)); var serializer = new JsonObjectSerializer(); serializer.Initialize(); var jobStore = new JobStoreTX { DataSource = "default", TablePrefix = "QRTZ_", InstanceId = "AUTO", //DriverDelegateType = typeof(MySQLDelegate).AssemblyQualifiedName, //MySql存储 DriverDelegateType = typeof(SQLiteDelegate).AssemblyQualifiedName, //SQLite存储 ObjectSerializer = serializer }; DirectSchedulerFactory.Instance.CreateScheduler("benny" + "Scheduler", "AUTO", new DefaultThreadPool(), jobStore); Scheduler = SchedulerRepository.Instance.Lookup("benny" + "Scheduler").Result; //scheduler.Start(); //默认开始调度器 await Scheduler.Start(); //return await Task.FromResult("将触发器和任务器绑定到调度器中完成"); }
public async Task SendJsonBodyMessage() { await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: false, enableSession: false)) { var client = new ServiceBusClient(TestEnvironment.ServiceBusConnectionString); var sender = client.CreateSender(scope.QueueName); var serializer = new JsonObjectSerializer(); var testBody = new TestBody { A = "text", B = 5, C = false }; var body = serializer.Serialize(testBody); var msg = new ServiceBusMessage(body); await sender.SendMessageAsync(msg); var receiver = client.CreateReceiver(scope.QueueName); var received = await receiver.ReceiveMessageAsync(); var receivedBody = received.Body.ToObject <TestBody>(serializer); Assert.AreEqual(testBody.A, receivedBody.A); Assert.AreEqual(testBody.B, receivedBody.B); Assert.AreEqual(testBody.C, receivedBody.C); } }
public async Task CanCreateBinaryDataFromCustomType() { var payload = new TestModel { A = "value", B = 5, C = true }; var serializer = new JsonObjectSerializer(); await AssertData(BinaryData.Serialize(payload, serializer)); await AssertData(await BinaryData.SerializeAsync(payload, serializer)); await AssertData(BinaryData.Serialize(payload)); await AssertData(await BinaryData.SerializeAsync(payload)); async Task AssertData(BinaryData data) { Assert.AreEqual(payload.A, data.Deserialize <TestModel>(serializer).A); Assert.AreEqual(payload.B, data.Deserialize <TestModel>(serializer).B); Assert.AreEqual(payload.C, data.Deserialize <TestModel>(serializer).C); Assert.AreEqual(payload.A, (await data.DeserializeAsync <TestModel>(serializer)).A); Assert.AreEqual(payload.B, (await data.DeserializeAsync <TestModel>(serializer)).B); Assert.AreEqual(payload.C, (await data.DeserializeAsync <TestModel>(serializer)).C); Assert.AreEqual(payload.A, data.Deserialize <TestModel>().A); Assert.AreEqual(payload.B, data.Deserialize <TestModel>().B); Assert.AreEqual(payload.C, data.Deserialize <TestModel>().C); Assert.AreEqual(payload.A, (await data.DeserializeAsync <TestModel>()).A); Assert.AreEqual(payload.B, (await data.DeserializeAsync <TestModel>()).B); Assert.AreEqual(payload.C, (await data.DeserializeAsync <TestModel>()).C); } }
public void ShouldSerialize() { // Given var date1 = DateTime.Today.AddDays(1); var date2 = DateTime.Today.AddDays(2); var date3 = DateTime.Today.AddDays(3); var serializer = new JsonObjectSerializer(false, converters: new[] { new XmlDateMemberValueConverter() }); var instance = new XmlDateClass { DateProperty = date1, NullableDateProperty = date2, ComplexProperty = new XmlDateClass { DateProperty = date3 } }; var expectedJson = @"{" + "\"DateProperty\":" + ((Date)date1).UnixTime + "," + "\"NullableDateProperty\":" + ((Date)date2).UnixTime + "," + "\"ComplexProperty\":{" + "\"DateProperty\":" + ((Date)date3).UnixTime + "}" + "}"; // When var actualJson = serializer.ConvertToString(instance); // Then Assert.AreEqual(expectedJson, actualJson); }
public void ByteArraySerializationTest2() { JsonObjectSerializer serializer = new JsonObjectSerializer(); ByteArrayTest2 byteArrayTest = new ByteArrayTest2(); byteArrayTest.SomePreData = 3823; int length = 2048; byte[] data = new byte[length]; for (int i = 0; i < length; i++) { data[i] = (byte)(i % 250); } byteArrayTest.Data = data; byteArrayTest.SomePostData = "test string"; string json = serializer.Serialize(byteArrayTest, null); ByteArrayTest2 deserializedObj = (ByteArrayTest2)serializer.Deserialize(json, typeof(ByteArrayTest2), null); Assert.Equal(byteArrayTest.Data, deserializedObj.Data); Assert.Equal(byteArrayTest.SomePreData, deserializedObj.SomePreData); Assert.Equal(byteArrayTest.SomePostData, deserializedObj.SomePostData); }
public async Task CanPublishCloudEventWithCustomObjectPayloadAndCustomSerializer() { EventGridPublisherClientOptions options = InstrumentClientOptions(new EventGridPublisherClientOptions()); EventGridPublisherClient client = InstrumentClient( new EventGridPublisherClient( new Uri(TestEnvironment.CloudEventTopicHost), new AzureKeyCredential(TestEnvironment.CloudEventTopicKey), options)); var serializer = new JsonObjectSerializer( new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); List <CloudEvent> eventsList = new List <CloudEvent>(); for (int i = 0; i < 10; i++) { CloudEvent cloudEvent = new CloudEvent( "record", "Microsoft.MockPublisher.TestEvent", serializer.Serialize(new TestPayload("name", i)), "application/json", dataFormat: CloudEventDataFormat.Json) { Id = Recording.Random.NewGuid().ToString(), Subject = $"Subject-{i}", Time = Recording.Now }; eventsList.Add(cloudEvent); } await client.SendEventsAsync(eventsList); }
public void ShouldDeserialize() { // Given var date1 = DateTime.Today.AddDays(1); var date2 = DateTime.Today.AddDays(2); var date3 = DateTime.Today.AddDays(3); var serializer = new JsonObjectSerializer(false, converters: new[] { new XmlDateMemberValueConverter() }); var instanceJson = @"{" + "\"DateProperty\":" + ((Date)date1).UnixTime + "," + "\"NullableDateProperty\":" + ((Date)date2).UnixTime + "," + "\"ComplexProperty\":{" + "\"DateProperty\":" + ((Date)date3).UnixTime + "}" + "}"; // When var instance = serializer.Deserialize <XmlDateClass>(instanceJson); // Then Assert.IsNotNull(instance); Assert.AreEqual(date1, instance.DateProperty); Assert.AreEqual(date2, instance.NullableDateProperty); Assert.IsNotNull(instance.ComplexProperty); Assert.AreEqual(date3, instance.ComplexProperty.DateProperty); Assert.IsNull(instance.ComplexProperty.NullableDateProperty); }
public void CanParseMissingType(bool skipValidation) { BinaryData requestContent = new BinaryData("{ \"specversion\": \"1.0\", \"id\":\"id\", \"source\":\"source\", \"subject\": \"Subject-0\", \"data\": null}"); if (!skipValidation) { Assert.That( () => CloudEvent.Parse(requestContent, skipValidation), Throws.InstanceOf <ArgumentException>()); } else { var cloudEvent = CloudEvent.Parse(requestContent, skipValidation); Assert.IsNull(cloudEvent.Type); Assert.AreEqual("source", cloudEvent.Source); Assert.AreEqual("id", cloudEvent.Id); Assert.AreEqual("Subject-0", cloudEvent.Subject); Assert.AreEqual("1.0", cloudEvent.SpecVersion); var serializer = new JsonObjectSerializer(); BinaryData bd = serializer.Serialize(cloudEvent); cloudEvent = CloudEvent.Parse(bd, skipValidation); Assert.IsNull(cloudEvent.Type); Assert.AreEqual("source", cloudEvent.Source); Assert.AreEqual("id", cloudEvent.Id); Assert.AreEqual("Subject-0", cloudEvent.Subject); } }
public void CanRoundTripStream() { var data = new byte[] { 1, 2, 3 }; var stream = new MemoryStream(data); stream.Position = 0; var time = DateTimeOffset.Now; var cloudEvent = new CloudEvent("source", "type", BinaryData.FromStream(stream), "application/octet-stream") { Subject = "subject", DataSchema = "schema", Id = "id", Time = time, }; var serializer = new JsonObjectSerializer(); BinaryData serialized = serializer.Serialize(cloudEvent); CloudEvent deserialized = CloudEvent.ParseMany(serialized)[0]; Assert.AreEqual("source", deserialized.Source); Assert.AreEqual("type", deserialized.Type); Assert.AreEqual(data, deserialized.Data.ToArray()); Assert.AreEqual("subject", deserialized.Subject); Assert.AreEqual("schema", deserialized.DataSchema); Assert.AreEqual("id", deserialized.Id); Assert.AreEqual(time, deserialized.Time); }
private async Task <IScheduler> GetScheduler() { //MySql存储 DBConnectionManager.Instance.AddConnectionProvider("default", new DbProvider("MySql", "server=127.0.0.1;user id=root;password=123456;database=quartz")); SimpleInstanceIdGenerator idGenerator = new SimpleInstanceIdGenerator(); var instanceId = await idGenerator.GenerateInstanceId(); var instancename = "SystemScheduler"; var serializer = new JsonObjectSerializer(); serializer.Initialize(); var jobStore = new JobStoreTX { DataSource = "default", TablePrefix = "QRTZ_", InstanceId = instanceId, InstanceName = instancename, DriverDelegateType = typeof(MySQLDelegate).AssemblyQualifiedName, //MySql存储 ObjectSerializer = serializer, Clustered = true }; DirectSchedulerFactory.Instance.CreateScheduler(instancename, instanceId, new DefaultThreadPool(), jobStore); var scheduler = await SchedulerRepository.Instance.Lookup(instancename); await scheduler.Start(); //默认开始调度器 return(scheduler); }
public async Task CustomizeSerializedJSONPropertiesToCamelCase() { EventGridPublisherClientOptions options = InstrumentClientOptions(new EventGridPublisherClientOptions()); var serializer = new JsonObjectSerializer( new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); EventGridPublisherClient client = InstrumentClient( new EventGridPublisherClient( new Uri(TestEnvironment.CustomEventTopicHost), new AzureKeyCredential(TestEnvironment.CustomEventTopicKey), options)); List <BinaryData> eventsList = new List <BinaryData>(); for (int i = 0; i < 10; i++) { eventsList.Add(serializer.Serialize( new TestEvent() { DataVersion = "1.0", EventTime = Recording.Now, EventType = "Microsoft.MockPublisher.TestEvent", Id = Recording.Random.NewGuid().ToString(), Subject = $"Subject-{i}", Topic = $"Topic-{i}" })); } await client.SendEventsAsync(eventsList); }
public ResultsApi(IMapper mapper, JsonSerializerOptions jsonOptions, JsonObjectSerializer jsonSerializer, IPlayerResultTable playerResultTable) : base(jsonOptions, jsonSerializer) { this.mapper = mapper; this.playerResultTable = playerResultTable; }
public void BatchSerializerTest() { List <BatchItemRequest> batchRequests = new List <BatchItemRequest>(); BatchItemRequest batchItem = new BatchItemRequest(); batchItem.AnyIntuitObject = new Account() { Id = "1" }; batchItem.bId = "bid"; batchItem.operation = OperationEnum.create; batchItem.operationSpecified = true; batchRequests.Add(batchItem); IntuitBatchRequest intuitBatchRequest = new IntuitBatchRequest(); intuitBatchRequest.BatchItemRequest = batchRequests.ToArray(); JsonObjectSerializer serializer = new JsonObjectSerializer(); string serializedJson = serializer.Serialize(intuitBatchRequest); string expectedserializedJson = "{\"BatchItemRequest\":[{\"Account\":{\"Id\":\"1\"},\"bId\":\"bid\",\"operation\":\"create\"}]}"; Assert.AreEqual(expectedserializedJson, serializedJson); }
public void CanParseMissingId(bool skipValidation) { BinaryData requestContent = new BinaryData("{ \"type\": \"type\", \"specversion\":\"1.0\", \"source\":\"source\", \"subject\": \"Subject-0\", \"data\": { \"itemSku\": \"512d38b6-c7b8-40c8-89fe-f46f9e9622b6\", \"itemUri\": \"https://rp-eastus2.eventgrid.azure.net:553/eventsubscriptions/estest/validate?id=B2E34264-7D71-453A-B5FB-B62D0FDC85EE&t=2018-04-26T20:30:54.4538837Z&apiVersion=2018-05-01-preview&token=1BNqCxBBSSE9OnNSfZM4%2b5H9zDegKMY6uJ%2fO2DFRkwQ%3d\" }}"); if (!skipValidation) { Assert.That( () => CloudEvent.Parse(requestContent, skipValidation), Throws.InstanceOf <ArgumentException>()); } else { var cloudEvent = CloudEvent.Parse(requestContent, skipValidation); Assert.IsNull(cloudEvent.Id); Assert.AreEqual("source", cloudEvent.Source); Assert.AreEqual("type", cloudEvent.Type); Assert.AreEqual("Subject-0", cloudEvent.Subject); var serializer = new JsonObjectSerializer(); BinaryData bd = serializer.Serialize(cloudEvent); cloudEvent = CloudEvent.Parse(bd, skipValidation); Assert.AreEqual("source", cloudEvent.Source); Assert.AreEqual("type", cloudEvent.Type); Assert.AreEqual("Subject-0", cloudEvent.Subject); } }
public void TestMethodMissingProperties() { JsonObjectSerializer serializer = new JsonObjectSerializer(); serializer.IsMissingFieldDataAllowed = true; FullFeaturedObject fullFeaturedObj = new FullFeaturedObject(); fullFeaturedObj.Property1 = 3; fullFeaturedObj.Property2 = "2sdfjsalf32p3sdf"; fullFeaturedObj.Property3 = 4.67; fullFeaturedObj.Property4 = "Test"; fullFeaturedObj.Property5 = 7; string json = serializer.Serialize(fullFeaturedObj, null); FeaturedObject deserializedObj = (FeaturedObject)serializer.Deserialize(json, typeof(FeaturedObject), null); Assert.Equal <int>(fullFeaturedObj.Property1, deserializedObj.Property1); Assert.Equal(fullFeaturedObj.Property2, deserializedObj.Property2); Assert.Equal <double>(fullFeaturedObj.Property3, deserializedObj.Property3); // do the same with different property order json = "{\"Property1\":3,\"Property2\":\"2sdfjsalf32p3sdf\",\"Property3\":4.67,\"Property4\":\"Test\",\"Property5\":7}"; deserializedObj = (FeaturedObject)serializer.Deserialize(json, typeof(FeaturedObject), null); Assert.Equal <int>(fullFeaturedObj.Property1, deserializedObj.Property1); Assert.Equal(fullFeaturedObj.Property2, deserializedObj.Property2); Assert.Equal <double>(fullFeaturedObj.Property3, deserializedObj.Property3); }
public void TestMethodOutOfOrderDeserialization2() { JsonObjectSerializer serializer = new JsonObjectSerializer(); { string outOfOrderJson = "{\"SubDe\":\"Test String\",\"SubId\":2}"; SubObjectEx subObj = (SubObjectEx)serializer.Deserialize(outOfOrderJson, typeof(SubObjectEx), null); Assert.Equal <int>(2, subObj.SubId); Assert.Equal("Test String", subObj.SubDe); } { string outOfOrderJson = "{\"Flag\":true,\"Number\":3.5,\"SubDe\":\"Test String\",\"SubId\":2}"; SubObjectEx subObj = (SubObjectEx)serializer.Deserialize(outOfOrderJson, typeof(SubObjectEx), null); Assert.Equal <int>(2, subObj.SubId); Assert.Equal("Test String", subObj.SubDe); Assert.True(subObj.Flag); Assert.Equal(3.5m, subObj.Number); SubObjectEx subObj2 = (SubObjectEx)serializer.Deserialize(outOfOrderJson, typeof(SubObjectEx), null); Assert.Equal <int>(2, subObj2.SubId); Assert.Equal("Test String", subObj2.SubDe); Assert.True(subObj2.Flag); Assert.Equal(3.5m, subObj2.Number); } }
public void TestMethodEmptyObjectArraySerialization() { JsonObjectSerializer serializer = new JsonObjectSerializer(UnknownTypeResolverOjectArray, SpecialTypeResolver); TestObject testObj = new TestObject(); testObj.ObjectArray = new object[] { 1, 10, 100005, new object[0] }; testObj.AnyObject = testObj.ObjectArray; string json = serializer.Serialize(testObj, null); TestObject deserializedObj = (TestObject)serializer.Deserialize(json, typeof(TestObject), null); { Assert.Equal <int>(testObj.ObjectArray.Length, deserializedObj.ObjectArray.Length); object[] targetArr = (object[])deserializedObj.ObjectArray[3]; Assert.Empty(targetArr); } // any object check { Assert.Equal <int>(((object[])testObj.AnyObject).Length, ((object[])deserializedObj.AnyObject).Length); object[] targetArr = (object[])((object[])deserializedObj.AnyObject)[3]; Assert.Empty(targetArr); } }
public void TestMethodInterfaceInheritanceSerialization() { JsonObjectSerializer serializer = new JsonObjectSerializer(UnknownTypeResolver, SpecialTypeResolver); TestInterfaceImpl1 testObj1 = new TestInterfaceImpl1(); testObj1.TestBaseProperty = "TEST"; testObj1.AdditionalProperty = "Some data"; testObj1.DeepTestProperty1 = "Inherited interface property 1"; testObj1.DeepTestProperty2 = "Inherited interface property 2"; InterfRefObject interfRef = new InterfRefObject(); interfRef.BaseObjectInstance = testObj1; string json = serializer.Serialize(interfRef, null); InterfRefObject deserializedObj = (InterfRefObject)serializer.Deserialize(json, typeof(InterfRefObject), null); Assert.Equal(((ITestInterfaceBase)interfRef.BaseObjectInstance).TestBaseProperty, ((ITestInterfaceBase)deserializedObj.BaseObjectInstance).TestBaseProperty); TestInterfaceImpl1 implObj = (TestInterfaceImpl1)deserializedObj.BaseObjectInstance; Assert.Null(implObj.AdditionalProperty); Assert.Equal(testObj1.DeepTestProperty1, implObj.DeepTestProperty1); Assert.Equal(testObj1.DeepTestProperty2, implObj.DeepTestProperty2); }
public UsersApi(IUsersTable usersTable, IMapper mapper, JsonSerializerOptions jsonOptions, JsonObjectSerializer jsonSerializer, IAuthorize authorize) : base(jsonOptions, jsonSerializer) { this.usersTable = usersTable; this.mapper = mapper; this.authorize = authorize; }
public void TimeActivityEntitySerializerTest() { //Term serializableEntity = SerializerTestHelper.CreateTermEntity(); JsonObjectSerializer serializer = new JsonObjectSerializer(); //string serializedJson = serializer.Serialize(serializableEntity); string serializedJson = "{\"QueryResponse\":{\"TimeActivity\":[{\"TxnDate\":\"2013-08-06\",\"NameOf\":\"Employee\",\"EmployeeRef\":{\"value\":\"19\",\"name\":\"DisplayName037e5835\"},\"CustomerRef\":{\"value\":\"57\",\"name\":\"06d3bd51-0f3c-43d6-9\"},\"ItemRef\":{\"value\":\"2\",\"name\":\"Hours\"},\"BillableStatus\":\"NotBillable\",\"Taxable\":false,\"HourlyRate\":0,\"Hours\":10,\"Minutes\":0,\"Description\":\"UpdatedDesca8a\",\"domain\":\"QBO\",\"sparse\":false,\"Id\":\"5\",\"SyncToken\":\"5\",\"MetaData\":{\"CreateTime\":\"2013-08-06T02:07:43-07:00\",\"LastUpdatedTime\":\"2013-08-06T02:23:26-07:00\"}},{\"TxnDate\":\"2013-08-06\",\"NameOf\":\"Employee\",\"EmployeeRef\":{\"value\":\"19\",\"name\":\"DisplayName037e5835\"},\"CustomerRef\":{\"value\":\"57\",\"name\":\"06d3bd51-0f3c-43d6-9\"},\"ItemRef\":{\"value\":\"2\",\"name\":\"Hours\"},\"BillableStatus\":\"NotBillable\",\"Taxable\":false,\"HourlyRate\":0,\"Hours\":10,\"Minutes\":0,\"Description\":\"asdca\",\"domain\":\"QBO\",\"sparse\":false,\"Id\":\"4\",\"SyncToken\":\"0\",\"MetaData\":{\"CreateTime\":\"2013-08-06T02:06:34-07:00\",\"LastUpdatedTime\":\"2013-08-06T02:06:34-07:00\"}},{\"TxnDate\":\"2013-08-06\",\"NameOf\":\"Vendor\",\"VendorRef\":{\"value\":\"34\",\"name\":\"DisplayName_07cc1ef917b54e34accf87300dd2261f\"},\"ItemRef\":{\"value\":\"2\",\"name\":\"Hours\"},\"BillableStatus\":\"NotBillable\",\"Taxable\":false,\"HourlyRate\":0,\"Hours\":13,\"Minutes\":0,\"Description\":\"Updating Employee Time Activity a143d\",\"domain\":\"QBO\",\"sparse\":false,\"Id\":\"3\",\"SyncToken\":\"1\",\"MetaData\":{\"CreateTime\":\"2013-08-05T23:39:15-07:00\",\"LastUpdatedTime\":\"2013-08-05T23:39:43-07:00\"}}],\"startPosition\":1,\"maxResults\":3},\"time\":\"2013-08-06T03:04:31.099-07:00\"}"; IntuitResponse deserializedEntity = (IntuitResponse)serializer.Deserialize <IntuitResponse>(serializedJson); }
public void PreferenceDeSerializerTest() { string serializedJson = "{\"QueryResponse\":{\"Preferences\":[{\"AccountingInfoPrefs\":{\"CustomerTerminology\":\"client\"},\"ProductAndServicesPrefs\":{\"ForSales\":true,\"ForPurchase\":true,\"QuantityWithPriceAndRate\":true,\"QuantityOnHand\":true},\"SalesFormsPrefs\":{\"CustomField\":[{\"CustomField\":[{\"Name\":\"SalesFormsPrefs.UseSalesCustom3\",\"Type\":\"BooleanType\",\"BooleanValue\":false},{\"Name\":\"SalesFormsPrefs.UseSalesCustom2\",\"Type\":\"BooleanType\",\"BooleanValue\":false},{\"Name\":\"SalesFormsPrefs.UseSalesCustom1\",\"Type\":\"BooleanType\",\"BooleanValue\":false}]}],\"CustomTxnNumbers\":false,\"AllowDeposit\":false,\"AllowDiscount\":false,\"AllowEstimates\":false,\"IPNSupportEnabled\":false,\"AllowServiceDate\":false,\"AllowShipping\":false,\"DefaultTerms\":{\"value\":\"3\"}},\"VendorAndPurchasesPrefs\":{\"TrackingByCustomer\":false,\"BillableExpenseTracking\":false,\"POCustomField\":[{\"CustomField\":[{\"Name\":\"PurchasePrefs.UsePurchaseCustom3\",\"Type\":\"BooleanType\",\"BooleanValue\":false},{\"Name\":\"PurchasePrefs.UsePurchaseCustom2\",\"Type\":\"BooleanType\",\"BooleanValue\":false},{\"Name\":\"PurchasePrefs.UsePurchaseCustom1\",\"Type\":\"BooleanType\",\"BooleanValue\":false}]}]},\"TimeTrackingPrefs\":{\"UseServices\":false,\"BillCustomers\":false,\"ShowBillRateToAll\":false,\"MarkTimeEntriesBillable\":false},\"TaxPrefs\":{\"UsingSalesTax\":true},\"CurrencyPrefs\":{\"MultiCurrencyEnabled\":false,\"HomeCurrency\":{\"value\":\"USD\"}},\"OtherPrefs\":{\"NameValue\":[{\"Name\":\"SalesFormsPrefs.DefaultCustomerMessage\"},{\"Name\":\"SalesFormsPrefs.DefaultItem\",\"Value\":\"1\"}]},\"domain\":\"QBO\",\"sparse\":false,\"Id\":\"1\",\"SyncToken\":\"0\",\"MetaData\":{\"CreateTime\":\"2013-07-02T04:37:24-07:00\",\"LastUpdatedTime\":\"2013-07-03T01:24:38-07:00\"}}],\"maxResults\":1},\"time\":\"2013-07-03T01:35:04.566-07:00\"}"; JsonObjectSerializer serializer = new JsonObjectSerializer(); IntuitResponse deserializedEntity = serializer.Deserialize <IntuitResponse>(serializedJson) as IntuitResponse; Assert.IsNotNull(deserializedEntity.AnyIntuitObject); }
private DynamicJsonSerializer(bool encrypt, JsonMappings mappings) { _jsonObjectSerializer = new JsonObjectSerializer(this); _jsonArraySerializer = new JsonArraySerializer(this); _encrypt = encrypt; _mappings = mappings; }
public DefaultInputConversionFeatureTests() { // Test overriding serialization settings. var serializer = new JsonObjectSerializer(new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); _defaultInputConversionFeature = TestUtility.GetDefaultInputConversionFeature(o => o.Serializer = serializer); }
public ResultsApi(JsonSerializerOptions jsonOptions, JsonObjectSerializer jsonSerializer, IPlayerResultTable playerResultTable, IUsersTable usersTable, IPlayerTable playerTable) : base(jsonOptions, jsonSerializer) { this.playerResultTable = playerResultTable; this.usersTable = usersTable; this.playerTable = playerTable; }
private DynamicJsonSerializer(bool encrypt, JsonMappings mappings, bool shouldUseAttributeDefinedInInterface) { _jsonObjectSerializer = new JsonObjectSerializer(this); _jsonArraySerializer = new JsonArraySerializer(this); _encrypt = encrypt; _mappings = mappings; _shouldUseAttributeDefinedInInterface = shouldUseAttributeDefinedInInterface; }
public void PreferenceSerializerTest() { Preferences serializableEntity = SerializerTestHelper.CreatePreferenceEntity(); JsonObjectSerializer serializer = new JsonObjectSerializer(); string serializedJson = serializer.Serialize(serializableEntity); string expectedserializedJson = "{\"OtherPrefs\":{\"NameValue\":[{\"Name\":\"SalesFormsPrefs.DefaultCustomerMessage\"},{\"Name\":\"SalesFormsPrefs.DefaultItem\",\"Value\":\"1\"}]},\"Id\":\"1\"}"; Assert.AreEqual(expectedserializedJson, serializedJson); }
/// <summary> /// .ctor /// </summary> /// <param name="uri">Uri to Elastictsearch service.</param> public ElasticsearchMessageRepository(string uri) { if (string.IsNullOrEmpty(uri)) { throw new ArgumentNullException(nameof(uri)); } this.uri = uri.TrimEnd('/'); this.serializer = new JsonObjectSerializer(); }
public DefaultBinderTests() { // Test overriding serialization settings. var serializer = new JsonObjectSerializer(new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); _paramConverterManager = TestUtility.GetDefaultBindingFeature(o => o.Serializer = serializer); }
public async Task SendCloudEventsToTopic() { string topicEndpoint = TestEnvironment.CloudEventTopicHost; string topicAccessKey = TestEnvironment.CloudEventTopicKey; // Create the publisher client using an AzureKeyCredential // Custom topic should be configured to accept events of the CloudEvents 1.0 schema #region Snippet:CreateClientWithOptions EventGridPublisherClient client = new EventGridPublisherClient( new Uri(topicEndpoint), new AzureKeyCredential(topicAccessKey)); #endregion #region Snippet:SendCloudEventsToTopic // Example of a custom ObjectSerializer used to serialize the event payload to JSON var myCustomDataSerializer = new JsonObjectSerializer( new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); // Add CloudEvents to a list to publish to the topic List <CloudEvent> eventsList = new List <CloudEvent> { // CloudEvent with custom model serialized to JSON new CloudEvent( "/cloudevents/example/source", "Example.EventType", new CustomModel() { A = 5, B = true }), // CloudEvent with custom model serialized to JSON using a custom serializer new CloudEvent( "/cloudevents/example/source", "Example.EventType", myCustomDataSerializer.Serialize(new CustomModel() { A = 5, B = true }), "application/json"), // CloudEvents also supports sending binary-valued data new CloudEvent( "/cloudevents/example/binarydata", "Example.EventType", new BinaryData(Encoding.UTF8.GetBytes("This is treated as binary data")), "application/octet-stream") }; // Send the events await client.SendEventsAsync(eventsList); #endregion }
public void Serialize_Should_Include_Query_Type_To_Result() { IObjectSerializer SerializerTested = new JsonObjectSerializer(); string expectedJson = "TestQuery"; TestQuery query = new TestQuery(); string json = SerializerTested.Serialize(query); json.Should().StartWith(expectedJson); }
private Task<IScheduler> CreateScheduler(string name, int threadPoolSize) { DBConnectionManager.Instance.AddConnectionProvider("default", new DbProvider("SqlServer-20", "Server=(local);Database=quartz;Trusted_Connection=True;")); var serializer = new JsonObjectSerializer(); serializer.Initialize(); var jobStore = new JobStoreTX { DataSource = "default", TablePrefix = "QRTZ_", InstanceId = "AUTO", DriverDelegateType = typeof(SqlServerDelegate).AssemblyQualifiedName, ObjectSerializer = serializer }; DirectSchedulerFactory.Instance.CreateScheduler(name + "Scheduler", "AUTO", new DefaultThreadPool(), jobStore); return SchedulerRepository.Instance.Lookup(name + "Scheduler"); }