public void Participant_FromJson() { var json = @"{ ""id"":""7a3c51e00a004917a8f5db807180fcc5"", ""first_name"":""Test"", ""last_name"":""Participant"", ""email"":""*****@*****.**"", ""type"":""guest"", ""role"":""guest"", ""guest_options"":{ ""company_name"":""Test Company"", ""locked"":false, ""bounced_email"":false, ""failed_login_attempts"":0, ""verified"":true, ""created_at"":""2017-05-26T19:27:27.798Z"", ""updated_at"":""2017-05-24T14:45:35.062Z"", ""contact_methods"":[ {""id"":1, ""destination_type"":""home_phone"", ""destination"":""5145550001"", ""verified"":true, ""created_at"":""2017-05-26T19:27:27.798Z"", ""updated_at"":""2017-05-24T14:45:35.062Z""} ] } }"; Helpers.Participant participant = Helpers.Participant.FromJson(json); Assert.AreEqual("7a3c51e00a004917a8f5db807180fcc5", participant.Id); Assert.IsInstanceOfType(participant.GuestOptions, typeof(Helpers.GuestOptions)); Assert.AreEqual(1, participant.GuestOptions.ContactMethods.Count); Assert.IsInstanceOfType(participant.GuestOptions.ContactMethods[0], typeof(Helpers.ContactMethod)); Assert.AreEqual(1, participant.GuestOptions.ContactMethods[0].Id); }
public void Safebox_ToJson() { var safebox = new Helpers.Safebox("*****@*****.**", 1, "test_message", "test_subject"); safebox.Guid = "dc6f21e0f02c4112874f8b5653b795e4"; var participant1 = new Helpers.Participant("*****@*****.**", "Test", "Participant1", "Test Company"); participant1.GuestOptions.ContactMethods.Add(new Helpers.ContactMethod { DestinationType = Helpers.ContactMethod.DestinationTypeT.HomePhone, Destination = "5145550001" }); safebox.Participants.Add(participant1); safebox.Participants.Add(new Helpers.Participant("*****@*****.**", "Test", "Participant2", "Test Company")); safebox.SecurityOptions.EncryptMessage = true; safebox.SecurityOptions.DoubleEncryption = false; safebox.PublicEncryptionKey = "Public Encryption Key"; safebox.Attachments.Add(new Helpers.Attachment(new MemoryStream(new byte[0]), "testFile.txt", 0)); safebox.Attachments[0].Guid = "97334293-23c2-4c94-8cee-369ddfabb678"; string expectedJson = @"{""safebox"":{ ""guid"":""dc6f21e0f02c4112874f8b5653b795e4"", ""subject"":""test_subject"", ""notification_language"":""en"", ""message"":""test_message"", ""security_profile_id"":1, ""public_encryption_key"":""Public Encryption Key"", ""user_email"":""*****@*****.**"", ""recipients"":[ {""email"":""*****@*****.**"", ""first_name"":""Test"", ""last_name"":""Participant1"", ""company_name"":""Test Company"", ""contact_methods"":[ {""destination_type"":""home_phone"", ""destination"":""5145550001""} ]}, {""email"":""*****@*****.**"", ""first_name"":""Test"", ""last_name"":""Participant2"", ""company_name"":""Test Company"", ""contact_methods"":[]} ], ""encrypt_message"":true, ""double_encryption"":false, ""document_ids"":[""97334293-23c2-4c94-8cee-369ddfabb678""] } }"; Assert.AreEqual(JToken.Parse(expectedJson).ToString(Newtonsoft.Json.Formatting.None), safebox.ToJson()); }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { WriteCount++; JsonSerializer s = new JsonSerializer { Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore }; JObject jo = JObject.FromObject(value, s); Helpers.Participant p = (Helpers.Participant)value; jo.Merge(JObject.FromObject(p.GuestOptions, s)); jo.WriteTo(writer); WriteCount--; }