Example #1
0
        public void StringDictionary()
        {
            // Arrange
            var expected = new RecursiveData { Array = new[] { 1, 2, 3, } };
            var dict = new Dictionary<string, string>() { { "Array", string.Join(";", expected.Array) } };

            // Act
            var actual = dict.ToObjectSafe<RecursiveData>();

            // Assert
            CollectionAssert.AreEqual(expected.Array, actual.Array);
        }
        public void JustObject()
        {
            // Arrange
            var expected = new Dictionary<string, object>()
            {
                { "Id", new Guid("366f4bd3-6717-4b14-9c79-70515296df7e") },
                { "Date", new DateTime(1999, 1, 1) },
                { "Enum", Enumeration.One },
                { "Text", "eleven" },
                { "Array", new[] { 1, 2, 3, } },
            };

            // Act
            var actual = expected.ToObjectSafe<JustObject>();

            // Assert
            Assert.AreEqual(expected["Id"], actual.Id);
            Assert.AreEqual(expected["Date"], actual.Date);
            Assert.AreEqual(expected["Enum"], actual.Enum);
            Assert.AreEqual(expected["Text"], actual.Text);
            CollectionAssert.AreEqual((int[])expected["Array"], (int[])actual.Array);
        }
        public void MissingPropertySafe()
        {
            // Arrange
            var dict = new Dictionary<string, object>()
            {
                { "Id", new Guid("366f4bd3-6717-4b14-9c79-70515296df7e") },
                { "Date", new DateTime(1999, 1, 1) },
                { "Enum", Enumeration.One },
                { "Text", "eleven" },
                { "Array", new[] { 1, 2, 3, } },
                { "Integer", 11 }, // There's no Integer
            };

            // Act
            dict.ToObjectSafe<RecursiveData>();
        }
        public void MissingPropertySafe()
        {
            // Arrange
            var dict = new Dictionary<string, string>()
            {
                { "Id", "366f4bd3-6717-4b14-9c79-70515296df7e" },
                { "Date", "1999-01-01" },
                { "Enum", "One" },
                { "Text", "eleven" },
                { "Integer", "11" }, // There's no Integer
            };

            // Act
            dict.ToObjectSafe<RecursiveData>();
        }