Exemplo n.º 1
0
        public void CanConvertInt()
        {
            var    target      = new ConfigSettingSerializer();
            string stringValue = target.Serialize(typeof(int), 99);

            var conversionResult = target.Deserialize(typeof(int), stringValue);

            Assert.AreEqual(99, conversionResult);
        }
Exemplo n.º 2
0
        public void CanConvertString()
        {
            var    target      = new ConfigSettingSerializer();
            string stringValue = target.Serialize(typeof(string), "Blurp");

            var conversionResult = target.Deserialize(typeof(string), stringValue);

            Assert.AreEqual("Blurp", conversionResult);
        }
Exemplo n.º 3
0
        public void CanConvertType()
        {
            var    target      = new ConfigSettingSerializer();
            Type   expected    = typeof(ConfigSettingSerializer);
            string stringValue = target.Serialize(typeof(Type), expected);

            var conversionResult = target.Deserialize(typeof(Type), stringValue);

            Assert.AreEqual(expected, conversionResult);
        }
Exemplo n.º 4
0
        public void CanConvertDateTime()
        {
            var    target      = new ConfigSettingSerializer();
            var    expected    = new DateTime(2000, 1, 1, 1, 1, 1, 1);
            string stringValue = target.Serialize(typeof(DateTime), expected);

            var conversionResult = target.Deserialize(typeof(DateTime), stringValue);

            Assert.AreEqual(expected, conversionResult);
        }
Exemplo n.º 5
0
        public void CanConvertComplexObject()
        {
            var target   = new ConfigSettingSerializer();
            var expected = new MockSerializableObject()
            {
                Address = "adress", Age = 1, Name = "Name"
            };
            string stringValue = target.Serialize(typeof(MockSerializableObject), expected);

            var conversionResult = target.Deserialize(typeof(MockSerializableObject), stringValue) as MockSerializableObject;

            Assert.AreEqual(expected.Age, conversionResult.Age);
        }
Exemplo n.º 6
0
        public void Serialize_CanSerializeDeserializeFloat()
        {
            // Arrange
            float expected = 12345;

            // Act
            var    target           = new ConfigSettingSerializer();
            string stringValue      = target.Serialize(typeof(float), expected);
            float  conversionResult = (float)target.Deserialize(typeof(float), stringValue);

            // Assert
            Assert.IsTrue(expected == conversionResult);
        }
Exemplo n.º 7
0
        public void Serialize_CanSerializeDeserializeByte()
        {
            // Arrange
            byte expected = 34;

            // Act
            var    target           = new ConfigSettingSerializer();
            string stringValue      = target.Serialize(typeof(byte), expected);
            var    conversionResult = target.Deserialize(typeof(byte), stringValue);

            // Assert
            Assert.AreEqual(expected, conversionResult);
        }
Exemplo n.º 8
0
        public void Serialize_CanSerializeEnum()
        {
            //Arrange
            var expected = ConfigLevel.CurrentSPWeb;

            // Act
            var    target           = new ConfigSettingSerializer();
            string stringValue      = target.Serialize(typeof(ConfigLevel), expected);
            var    conversionResult = target.Deserialize(typeof(ConfigLevel), stringValue);

            // Assert
            Assert.AreEqual(expected, conversionResult);
        }
Exemplo n.º 9
0
        public void Serialize_CanSerializeDeserializeUint()
        {
            // Arrange
            uint expected = 12345;

            // Act
            var    target           = new ConfigSettingSerializer();
            string stringValue      = target.Serialize(typeof(uint), expected);
            var    conversionResult = target.Deserialize(typeof(uint), stringValue);

            // Assert
            Assert.AreEqual(expected, conversionResult);
        }
Exemplo n.º 10
0
        public void Serialize_CanSerializeDeserializeSingle()
        {
            // Arrange
            Single expected = 12.4321f;

            // Act
            var    target           = new ConfigSettingSerializer();
            string stringValue      = target.Serialize(typeof(Single), expected);
            Single conversionResult = (Single)target.Deserialize(typeof(Single), stringValue);

            // Assert
            Assert.IsTrue(expected == conversionResult);
        }
Exemplo n.º 11
0
        public void Serialize_CanSerializeDeserializeDouble()
        {
            // Arrange
            double expected = 0.0123458191232112;

            // Act
            var    target           = new ConfigSettingSerializer();
            string stringValue      = target.Serialize(typeof(double), expected);
            double conversionResult = (double)target.Deserialize(typeof(double), stringValue);

            // Assert
            Assert.IsTrue(expected == conversionResult);
        }
Exemplo n.º 12
0
        public void Serialize_CanSerializeDeserializeComplexObject()
        {
            //Arrange
            var expected = new MockSerializableObject()
            {
                Address = "address", Age = 1, Name = "Name"
            };

            //Act
            var    target           = new ConfigSettingSerializer();
            string stringValue      = target.Serialize(typeof(MockSerializableObject), expected);
            var    conversionResult = target.Deserialize(typeof(MockSerializableObject), stringValue) as MockSerializableObject;

            //Assert
            Assert.AreEqual(expected.Age, conversionResult.Age);
            Assert.AreEqual(expected.Address, conversionResult.Address);
            Assert.AreEqual(expected.Name, conversionResult.Name);
        }
        public override object Execute(SPProxyOperationArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            try
            {
                var    proxyArgs         = args as ConfigDeserializeArgs;
                var    configSerializer  = new ConfigSettingSerializer();
                object deserializedValue = configSerializer.Deserialize(proxyArgs.TypeToDeserialize, proxyArgs.DeserializedData);
                return(deserializedValue);
            }
            catch (Exception excpt)
            {
                return(excpt);
            }
        }
Exemplo n.º 14
0
        public void Deerialize_XmlSerializerFailure_ThrowsConfigurationException()
        {
            //Arrange
            MXmlSerializerFactory.AllInstances.CreateSerializerType = (instance, type) => { throw new TypeLoadException("error"); };
            var  target     = new ConfigSettingSerializer();
            var  testConfig = new ServiceLocationConfigData();
            bool expectedExceptionThrown = false;

            //Act
            try
            {
                target.Deserialize(typeof(ServiceLocationConfigData), "foobar");
            }
            catch (ConfigurationException)
            {
                expectedExceptionThrown = true;
            }

            //Assert caught by expected exception
            Assert.IsTrue(expectedExceptionThrown);
        }
        public void SerializeDeserialize_WithAreasAndCategories()
        {
            //Arrange
            var target   = new ConfigSettingSerializer();
            var expected = new DiagnosticsAreaCollection();


            var area1 = new DiagnosticsArea(TestArea1Name);

            area1.DiagnosticsCategories.Add(new DiagnosticsCategory(TestCategory11Name, EventSeverity.ErrorCritical, TraceSeverity.Medium));
            area1.DiagnosticsCategories.Add(new DiagnosticsCategory(TestCategory12Name, EventSeverity.Information, TraceSeverity.Verbose));
            var area2 = new DiagnosticsArea(TestArea2Name);

            area2.DiagnosticsCategories.Add(new DiagnosticsCategory(TestCategory21Name, EventSeverity.Information, TraceSeverity.Monitorable));
            area2.DiagnosticsCategories.Add(new DiagnosticsCategory(TestCategory22Name, EventSeverity.Warning, TraceSeverity.Medium));
            expected.Add(area1);
            expected.Add(area2);

            //Act
            string stringValue      = target.Serialize(expected.GetType(), expected);
            var    conversionResult = target.Deserialize(expected.GetType(), stringValue) as DiagnosticsAreaCollection;

            //Assert
            Assert.AreEqual(expected.Count, conversionResult.Count);
            Assert.AreEqual(expected[0].DiagnosticsCategories.Count, conversionResult[0].DiagnosticsCategories.Count);
            Assert.AreEqual(expected[0].DiagnosticsCategories[0].Name, conversionResult[0].DiagnosticsCategories[0].Name);
            Assert.AreEqual(expected[0].DiagnosticsCategories[1].Name, conversionResult[0].DiagnosticsCategories[1].Name);
            Assert.AreEqual(expected[0].DiagnosticsCategories[0].EventSeverity, conversionResult[0].DiagnosticsCategories[0].EventSeverity);
            Assert.AreEqual(expected[0].DiagnosticsCategories[0].TraceSeverity, conversionResult[0].DiagnosticsCategories[0].TraceSeverity);
            Assert.AreEqual(expected[0].DiagnosticsCategories[1].EventSeverity, conversionResult[0].DiagnosticsCategories[1].EventSeverity);
            Assert.AreEqual(expected[0].DiagnosticsCategories[1].TraceSeverity, conversionResult[0].DiagnosticsCategories[1].TraceSeverity);
            Assert.AreEqual(expected[1].DiagnosticsCategories.Count, conversionResult[1].DiagnosticsCategories.Count);
            Assert.AreEqual(expected[1].DiagnosticsCategories[0].Name, conversionResult[1].DiagnosticsCategories[0].Name);
            Assert.AreEqual(expected[1].DiagnosticsCategories[1].Name, conversionResult[1].DiagnosticsCategories[1].Name);
            Assert.AreEqual(expected[1].DiagnosticsCategories[0].EventSeverity, conversionResult[1].DiagnosticsCategories[0].EventSeverity);
            Assert.AreEqual(expected[1].DiagnosticsCategories[0].TraceSeverity, conversionResult[1].DiagnosticsCategories[0].TraceSeverity);
            Assert.AreEqual(expected[1].DiagnosticsCategories[1].EventSeverity, conversionResult[1].DiagnosticsCategories[1].EventSeverity);
            Assert.AreEqual(expected[1].DiagnosticsCategories[1].TraceSeverity, conversionResult[1].DiagnosticsCategories[1].TraceSeverity);
        }
Exemplo n.º 16
0
        public void Serialize_DeserializeWrongEnum_ThrowsException()
        {
            //Arrange
            var  expected = ConfigLevel.CurrentSPWeb;
            bool expectedExceptionThrown = false;

            // Act
            var    target      = new ConfigSettingSerializer();
            string stringValue = target.Serialize(typeof(ConfigLevel), expected);

            try
            {
                var conversionResult = target.Deserialize(typeof(SandboxTraceSeverity), stringValue);
            }
            catch (ArgumentException)
            {
                expectedExceptionThrown = true;
            }

            // Assert
            Assert.IsTrue(expectedExceptionThrown);
        }