Exemple #1
0
        public void New_Deserializes_PhoneColumn_For_No_Type_Json()
        {
            PhoneColumn phone = new PhoneColumn(jsonPhoneNoType);

            Assert.AreEqual(phoneNumber, phone.PhoneNumber);
            Assert.AreEqual(PhoneColumnType.Undefined, phone.PhoneType);
        }
Exemple #2
0
        public void New_Deserializes_PhoneColumn_For_Valid_Type_Json()
        {
            PhoneColumn phone = new PhoneColumn(jsonPhoneCellType);

            Assert.AreEqual(phoneNumber, phone.PhoneNumber);
            Assert.AreEqual(PhoneColumnType.Cell, phone.PhoneType);
        }
Exemple #3
0
        public void OnSerializingMethod_Sets_PhoneTypeString_Member_From_PhoneType_Member_None()
        {
            var phoneColumn = new PhoneColumn()
            {
                PhoneNumber = phoneNumber
            };

            Assert.AreEqual(PhoneColumnType.Undefined, phoneColumn.PhoneType);
            Assert.IsNull(phoneColumn.PhoneTypeString);

            phoneColumn.OnSerializingMethod(new StreamingContext());

            Assert.IsNull(phoneColumn.PhoneTypeString);
        }
Exemple #4
0
        public void OnSerializingMethod_Sets_PhoneTypeString_Member_From_PhoneType_Member()
        {
            var phoneColumn = new PhoneColumn()
            {
                PhoneNumber = phoneNumber,
                PhoneType = PhoneColumnType.Work
            };

            Assert.IsNull(phoneColumn.PhoneTypeString);

            phoneColumn.OnSerializingMethod(new StreamingContext());

            Assert.AreEqual("Work", phoneColumn.PhoneTypeString);
        }
Exemple #5
0
        /// <summary>
        /// Initialize a new PhoneColumn object from its JSON string representation.
        /// </summary>
        public PhoneColumn(string phoneJson)
        {
            PhoneColumn phone = null;

            try
            {
                phone = JsonConvert.DeserializeObject <PhoneColumn>(phoneJson);
            }
            catch
            {
                throw new ArgumentOutOfRangeException("phoneJson", "The provided data was not parsable to a PhoneColumn object.");
            }
            if (phone != null && phone.PhoneNumber == null && phone.PhoneTypeString == null)
            {
                throw new ArgumentOutOfRangeException("phoneJson", "The provided data was not parsable to a PhoneColumn object.");
            }

            PhoneNumber     = phone.PhoneNumber;
            PhoneType       = phone.PhoneType;
            PhoneTypeString = phone.PhoneTypeString;
        }