Exemple #1
0
        public void GetValue_NothingToStringify_ReturnsUnmodifiedDataItem()
        {
            var transformed = new StringifiedFieldsDataItem(
                new DictionaryDataItem(new Dictionary <string, object>
            {
                { "FirstNumber", 100 },
                { "SecondNumber", 42 },
                { "Nested", new Dictionary <string, object>
                  {
                      { "SecondNumber", 50 }
                  } }
            }),
                new[] { "NonExisting" });

            CollectionAssert.AreEquivalent(new[] { "FirstNumber", "SecondNumber", "Nested" }, transformed.GetFieldNames().ToArray(),
                                           TestResources.InvalidFieldNames);

            Assert.AreEqual(100, transformed.GetValue("FirstNumber"), TestResources.InvalidFieldValue);
            Assert.AreEqual(42, transformed.GetValue("SecondNumber"), TestResources.InvalidFieldValue);

            var nested = transformed.GetValue("Nested") as IDataItem;

            Assert.IsNotNull(nested, TestResources.NullNestedDataItem);

            CollectionAssert.AreEquivalent(new[] { "SecondNumber" }, nested.GetFieldNames().ToArray(),
                                           TestResources.InvalidFieldNames);

            Assert.AreEqual(50, nested.GetValue("SecondNumber"), TestResources.InvalidFieldValue);
        }
Exemple #2
0
        public void GetValue_SpecificIntegerField_Stringified()
        {
            var transformed = new StringifiedFieldsDataItem(
                new DictionaryDataItem(new Dictionary <string, object>
            {
                { "FirstNumber", 10 },
                { "SecondNumber", 42 },
                { "Nested", new Dictionary <string, object>
                  {
                      { "SecondNumber", 50 }
                  } }
            }),
                new[] { "SecondNumber" });

            CollectionAssert.AreEquivalent(new[] { "FirstNumber", "SecondNumber", "Nested" }, transformed.GetFieldNames().ToArray(),
                                           TestResources.InvalidFieldNames);

            Assert.AreEqual(10, transformed.GetValue("FirstNumber"), TestResources.InvalidFieldValue);
            Assert.AreEqual("42", transformed.GetValue("SecondNumber"), TestResources.InvalidFieldValue);

            var nested = transformed.GetValue("Nested") as IDataItem;

            Assert.IsNotNull(nested, TestResources.NullNestedDataItem);

            CollectionAssert.AreEquivalent(new[] { "SecondNumber" }, nested.GetFieldNames().ToArray(),
                                           TestResources.InvalidFieldNames);

            Assert.AreEqual(50, nested.GetValue("SecondNumber"), TestResources.InvalidFieldValue);
        }