コード例 #1
0
        public void GivenPageWithPropertyValueAndPropertyGroups_CreateAndPopulateTypedInstance_ReturnsTypedInstanceWithPropertyValues()
        {
            PageData sourcePage = new PageData();

            sourcePage.Property.Add("LongStringProperty", new PropertyString());
            sourcePage.SetValue("LongStringProperty", "one");
            sourcePage.Property.Add("ImageOne-ImageUrl", new PropertyString());
            sourcePage.SetValue("ImageOne-ImageUrl", "two");
            sourcePage.Property.Add("ImageOne-AltText", new PropertyString());
            sourcePage.SetValue("ImageOne-AltText", "three");
            sourcePage.Property.Add("ImageTwo-ImageUrl", new PropertyString());
            sourcePage.SetValue("ImageTwo-ImageUrl", "four");
            sourcePage.Property.Add("ImageTwo-AltText", new PropertyString());
            sourcePage.SetValue("ImageTwo-AltText", "five");
            sourcePage.Property.Add("ImageThree-ImageUrl", new PropertyString());
            sourcePage.SetValue("ImageThree-ImageUrl", "six");
            sourcePage.Property.Add("ImageThree-AltText", new PropertyString());
            sourcePage.SetValue("ImageThree-AltText", "seven");

            TypedPageActivator activator = new TypedPageActivator();

            TestPageTypeWithPropertyGroups page = activator.CreateAndPopulateTypedInstance(sourcePage, typeof(TestPageTypeWithPropertyGroups)) as TestPageTypeWithPropertyGroups;

            Assert.Equal("one", page.LongStringProperty);
            Assert.Equal("two", page.ImageOne.ImageUrl);
            Assert.Equal("three", page.ImageOne.AltText);
            Assert.Equal("four", page.ImageTwo.ImageUrl);
            Assert.Equal("five", page.ImageTwo.AltText);
            Assert.Equal("six", page.ImageThree.ImageUrl);
            Assert.Equal("seven", page.ImageThree.AltText);

        }
        public void GivenPropertyIsNullableTypeAndNull_GetPropertyGroupPropertyValue_ReturnsNullValue()
        {
            TestPageTypeWithPropertyGroups typedPageData = new TestPageTypeWithPropertyGroups();
            typedPageData = new TypedPageActivator().CreateAndPopulateTypedInstance(typedPageData, typeof(TestPageTypeWithPropertyGroups)) as TestPageTypeWithPropertyGroups;
            string propertyName = typedPageData.ImageOne.GetPropertyGroupPropertyName(propertyGroup => propertyGroup.NullableTestIntProperty);
            typedPageData.Property.Add(propertyName, new PropertyNumber());

            int? returnedValue = typedPageData.ImageOne.GetPropertyGroupPropertyValue(propertyGroup => propertyGroup.NullableTestIntProperty);

            Assert.False(returnedValue.HasValue);
        }
        public void GivenPropertyIsReferenceTypeAndNull_GetPropertyGroupPropertyValue_ReturnsNull()
        {
            TestPageTypeWithPropertyGroups typedPageData = new TestPageTypeWithPropertyGroups();
            typedPageData = new TypedPageActivator().CreateAndPopulateTypedInstance(typedPageData, typeof(TestPageTypeWithPropertyGroups)) as TestPageTypeWithPropertyGroups;
            string propertyName = typedPageData.ImageOne.GetPropertyGroupPropertyName(propertyGroup => propertyGroup.ImageUrl);
            typedPageData.Property.Add(propertyName, new PropertyString());

            string returnedValue = typedPageData.ImageOne.GetPropertyGroupPropertyValue(propertyGroup => propertyGroup.ImageUrl);

            Assert.Null(returnedValue);
        }
コード例 #4
0
        public void GivenPageFromCreateAndPopulateTypedInstance_CompilerGeneratedPropertySetter_IsAutoImplemented()
        {
            TypedPageActivator activator = new TypedPageActivator();
            TestPageType page = (TestPageType)activator.CreateAndPopulateTypedInstance(new PageData(), typeof(TestPageType));
            page.Property.Add("CompilerGeneratedProperty", new PropertyString());
            string propertyValue = TestValueUtility.CreateRandomString();
            
            page.CompilerGeneratedProperty = propertyValue;

            Assert.Equal<string>(propertyValue, page["CompilerGeneratedProperty"] as string);
        }
        public void GetPropertyGroupPropertyValue_ReturnsPropertyValue()
        {
            TestPageTypeWithPropertyGroups typedPageData = new TestPageTypeWithPropertyGroups();
            typedPageData = new TypedPageActivator().CreateAndPopulateTypedInstance(typedPageData, typeof(TestPageTypeWithPropertyGroups)) as TestPageTypeWithPropertyGroups;
            string propertyName = typedPageData.ImageOne.GetPropertyGroupPropertyName(propertyGroup => propertyGroup.ImageUrl);
            string propertyValue = "Test";
            typedPageData.Property.Add(propertyName, new PropertyString(propertyValue));

            string returnedValue = typedPageData.ImageOne.GetPropertyGroupPropertyValue(propertyGroup => propertyGroup.ImageUrl);

            Assert.Equal<string>(propertyValue, returnedValue);
        }
        public void GivenValue_SetPropertyGroupPropertyValue_SetsPropertyValue()
        {
            TestPageTypeWithPropertyGroups typedPageData = new TestPageTypeWithPropertyGroups();
            typedPageData = new TypedPageActivator().CreateAndPopulateTypedInstance(typedPageData, typeof(TestPageTypeWithPropertyGroups)) as TestPageTypeWithPropertyGroups;
            string propertyName = typedPageData.ImageOne.GetPropertyGroupPropertyName(propertyGroup => propertyGroup.ImageUrl);

            typedPageData.Property.Add(propertyName, new PropertyString(""));
            string valueToSet = "Test";

            typedPageData.ImageOne.SetPropertyGroupPropertyValue(propertyGroup => propertyGroup.ImageUrl, valueToSet);

            Assert.Equal<string>(valueToSet, typedPageData.ImageOne.ImageUrl as string);
        }
コード例 #7
0
        public void GivenPageWithPropertyValue_CreateAndPopulateTypedInstance_ReturnsTypedInstanceWithPropertyValue()
        {
            PageData sourcePage = new PageData();
            string propertyName = TestValueUtility.CreateRandomString();
            sourcePage.Property.Add(propertyName, new PropertyString());
            string propertyValue = TestValueUtility.CreateRandomString();
            sourcePage.SetValue(propertyName, propertyValue);
            TypedPageActivator activator = new TypedPageActivator();

            TestPageType page = (TestPageType)activator.CreateAndPopulateTypedInstance(sourcePage, typeof(TestPageType));

            Assert.Equal<string>(propertyValue, page.GetValue(propertyName) as string);
        }
コード例 #8
0
 protected internal PageTypeResolver()
 {
     Activator = new TypedPageActivator();
 }
        public void GivenPropertyIsValueTypeAndNull_GetPropertyGroupPropertyValue_ThrowsException()
        {
            TestPageTypeWithPropertyGroups typedPageData = new TestPageTypeWithPropertyGroups();
            typedPageData = new TypedPageActivator().CreateAndPopulateTypedInstance(typedPageData, typeof(TestPageTypeWithPropertyGroups)) as TestPageTypeWithPropertyGroups;
            string propertyName = typedPageData.ImageOne.GetPropertyGroupPropertyName(propertyGroup => propertyGroup.IntTestProperty);
            typedPageData.Property.Add(propertyName, new PropertyNumber());

            Exception exception = Record.Exception(() => typedPageData.ImageOne.GetPropertyGroupPropertyValue(propertyGroup => propertyGroup.IntTestProperty));

            Assert.NotNull(exception);
        }
        public void GivenExpressionWithProperty_GetPropertyGroupPropertyName_ReturnsThePropertysName()
        {
            TestPageTypeWithPropertyGroups typedPageData = new TestPageTypeWithPropertyGroups();
            typedPageData = new TypedPageActivator().CreateAndPopulateTypedInstance(typedPageData, typeof(TestPageTypeWithPropertyGroups)) as TestPageTypeWithPropertyGroups;
            string propertyName = typedPageData.ImageOne.GetPropertyGroupPropertyName(propertyGroup => propertyGroup.IntTestProperty);

            string returnedValue = typedPageData.ImageOne.GetPropertyGroupPropertyName(propertyGroup => propertyGroup.IntTestProperty);

            Assert.Equal<string>(propertyName, returnedValue);
        }
        public void GivenExpressionThatIsNotUnaryOrMember_SetPropertyGroupPropertyValue_ThrowsException()
        {
            TestPageTypeWithPropertyGroups typedPageData = new TestPageTypeWithPropertyGroups();
            typedPageData = new TypedPageActivator().CreateAndPopulateTypedInstance(typedPageData, typeof(TestPageTypeWithPropertyGroups)) as TestPageTypeWithPropertyGroups;

            Exception exception = Record.Exception(() => typedPageData.ImageOne.SetPropertyGroupPropertyValue(propertyGroup => propertyGroup.IntTestProperty + 1, 1));

            Assert.NotNull(exception);
        }
        public void GivenValueOfValueType_SetPropertyGroupPropertyValue_SetsPropertyValue()
        {
            TestPageTypeWithPropertyGroups typedPageData = new TestPageTypeWithPropertyGroups();
            typedPageData = new TypedPageActivator().CreateAndPopulateTypedInstance(typedPageData, typeof(TestPageTypeWithPropertyGroups)) as TestPageTypeWithPropertyGroups;
            string propertyName = typedPageData.ImageOne.GetPropertyGroupPropertyName(propertyGroup => propertyGroup.IntTestProperty);

            typedPageData.Property.Add(propertyName, new PropertyNumber());
            int valueToSet = 1;

            typedPageData.ImageOne.SetPropertyGroupPropertyValue(propertyGroup => propertyGroup.IntTestProperty, valueToSet);

            Assert.Equal<int>(valueToSet, (int)typedPageData[propertyName]);
        }
        public void GivenPropertyValueIsValueType_GetPropertyGroupPropertyValue_ReturnsPropertyValue()
        {
            TestPageTypeWithPropertyGroups typedPageData = new TestPageTypeWithPropertyGroups();
            typedPageData = new TypedPageActivator().CreateAndPopulateTypedInstance(typedPageData, typeof(TestPageTypeWithPropertyGroups)) as TestPageTypeWithPropertyGroups;
            string propertyName = typedPageData.ImageOne.GetPropertyGroupPropertyName(propertyGroup => propertyGroup.IntTestProperty);
            int propertyValue = 1;
            typedPageData.Property.Add(propertyName, new PropertyNumber(propertyValue));

            int returnedValue = typedPageData.ImageOne.GetPropertyGroupPropertyValue(propertyGroup => propertyGroup.IntTestProperty);

            Assert.Equal<int>(propertyValue, returnedValue);
        }
        public void GivenOtherReturnTypeThanPropertyTypeAndValueExistsAndIncludeDynamicIsTrue_GetPropertyGroupPropertyValue_ReturnsPropertyValue1()
        {
            TestPageTypeWithPropertyGroups typedPageData = new TestPageTypeWithPropertyGroups();
            typedPageData = new TypedPageActivator().CreateAndPopulateTypedInstance(typedPageData, typeof(TestPageTypeWithPropertyGroups)) as TestPageTypeWithPropertyGroups;
            string propertyName = typedPageData.ImageOne.GetPropertyGroupPropertyName(propertyGroup => propertyGroup.NullableTestIntProperty);
            int? propertyValue = 1;
            typedPageData.Property.Add(propertyName, new PropertyNumber(propertyValue.Value));


            int returnedValue = typedPageData.ImageOne.GetPropertyGroupPropertyValue<Image, int>(propertyGroup => propertyGroup.NullableTestIntProperty, true);

            Assert.Equal<int>(propertyValue.Value, returnedValue);
        }