public void CreatePropertyInfoPropertyValueGetter_PropertyDoesNotExistOnInstnace_NullGetterCreated()
        {
            var fakeName = new FakeName {First = "Thor", Last = "Jenkins"};
            var getter = PropertyInfoPropertyValueGetter.CreatePropertyInfoPropertyValueGetter(fakeName, "DoesNotExist");

            Assert.Null(getter);
        }
        public void CreatePropertyInfoPropertyValueGetter_NullProperty_NullGetter()
        {
            var fakeName = new FakeName {First = "Firstie", Last = "Lastly"};
            var getter = PropertyInfoPropertyValueGetter.CreatePropertyInfoPropertyValueGetter(fakeName, null);

            Assert.Null(getter);
        }
        public void GetPartialResponse_FlatObject_ResultContainsOnlySelectedFields()
        {
            const string uriField = "Uri";
            const string salaryField = "Salary";
            const string homepageField = "HomePage";
            const string nameField = "Name";

            const string janeDoeHomepageUri = "http://janedoe.com/";
            const string deeDoeFirstName = "Dee";
            const string deeDoeLastName = "Doe";
            const decimal janeDoeSalary = 100000000581.00m;

            var homepage = new FakeLink {Rel = "homepage", Uri = janeDoeHomepageUri};
            var name = new FakeName {First = deeDoeFirstName, Last = deeDoeLastName};

            var propertyValues = new Dictionary<string, object>();
            propertyValues[uriField] = janeDoeHomepageUri;
            propertyValues[salaryField] = janeDoeSalary;
            propertyValues[homepageField] = homepage;
            propertyValues[nameField] = name;
     
            var fakeDto =
                new FakeFlatDto
                {
                    HomePage = homepage,
                    Name = name,
                    Salary = janeDoeSalary
                };

            var partialFieldSelectors = new List<FieldSelectorTreeNode>
            {
                new FieldSelectorTreeNode("Salary"),
                new FieldSelectorTreeNode("Name"),
                new FieldSelectorTreeNode("HomePage")
                {
                    Children = new List<FieldSelectorTreeNode>
                    {
                        new FieldSelectorTreeNode("Uri")
                    }
                }
            };

            var factory = MockRepository.GenerateStub<IPropertyValueGetterFactory>();
            factory.Stub(x => x.CreatePropertyValueGetter(null, null)).IgnoreArguments().Return(null).WhenCalled(x =>
            {
                var getter = MockRepository.GenerateStub<IPropertyValueGetter>();
                getter.Stub(g => g.PropertyName).Return((string)x.Arguments[1]);
                getter.Stub(g => g.GetPropertyValue(null)).IgnoreArguments().Return(propertyValues[(string)x.Arguments[1]]);
                x.ReturnValue = getter;
            });

            var responsinator = new PartialResponsinator(partialFieldSelectors, factory);
            dynamic responsible = responsinator.GetPartialResponse(fakeDto);

            Assert.Equal(deeDoeFirstName, responsible.Name.First);
            Assert.Equal(deeDoeLastName, responsible.Name.Last);
            Assert.Equal(janeDoeHomepageUri, responsible.HomePage.Uri);
            var homePage = responsible.HomePage as IDictionary<string, object>;
            Assert.False(homePage.ContainsKey("Rel"));
        }
Exemple #4
0
        public void CreatePropertyInfoPropertyValueGetter_NullProperty_NullGetter()
        {
            var fakeName = new FakeName {
                First = "Firstie", Last = "Lastly"
            };
            var getter = PropertyInfoPropertyValueGetter.CreatePropertyInfoPropertyValueGetter(fakeName, null);

            Assert.Null(getter);
        }
        public void CreatePropertyValueGetter_NonDynamic_PropertyInfoPropertyGetter()
        {
            var fakeName = new FakeName {First = "Joe", Last = "Dirt"};
            var factory = new PropertyValueGetterFactory();
            var getter = factory.CreatePropertyValueGetter(fakeName, "First");

            Assert.True(getter is PropertyInfoPropertyValueGetter);

        }
Exemple #6
0
        public void CreatePropertyInfoPropertyValueGetter_PropertyDoesNotExistOnInstnace_NullGetterCreated()
        {
            var fakeName = new FakeName {
                First = "Thor", Last = "Jenkins"
            };
            var getter = PropertyInfoPropertyValueGetter.CreatePropertyInfoPropertyValueGetter(fakeName, "DoesNotExist");

            Assert.Null(getter);
        }
        public void CreateDynamicObjectValueGetter_NonDynamicInstance_NullGetter()
        {
            var fakeName = new FakeName {
                First = "John", Last = "Doe"
            };
            var getter = DynamicPropertyValueGetter.CreateDynamicObjectValueGetter(fakeName, "First");

            Assert.Null(getter);
        }
        public void CreatePropertyValueGetter_NonDynamic_PropertyInfoPropertyGetter()
        {
            var fakeName = new FakeName {
                First = "Joe", Last = "Dirt"
            };
            var factory = new PropertyValueGetterFactory();
            var getter  = factory.CreatePropertyValueGetter(fakeName, "First");

            Assert.True(getter is PropertyInfoPropertyValueGetter);
        }
        public void CreatePropertyInfoPropertyValueGetter_EmptyStringProperty_NullGetter()
        {
            const string propertyName = "";

            var fakeName = new FakeName {First = "Firstie", Last = "Lastly"};

            var getter = PropertyInfoPropertyValueGetter.CreatePropertyInfoPropertyValueGetter(fakeName, propertyName.ToLower());

            Assert.Null(getter);
        }
        public void CreatePropertyInfoPropertyValueGetter_NonDynamicInstance_ValidGetterCreated()
        {
            const string firstProperty = "First";
            const string firstName = "John";

            var fakeName = new FakeName { First = firstName, Last = "Doe" };
            var getter = PropertyInfoPropertyValueGetter.CreatePropertyInfoPropertyValueGetter(fakeName, firstProperty);

            Assert.Equal(firstProperty, getter.PropertyName);
            Assert.Equal(firstName, getter.GetPropertyValue(fakeName));
        }
        public void CreatePropertyInfoPropertyValueGetter_PropertyCaseDoesNotMatch_ValidGetterCreated()
        {
            const string firstProperty = "fIRsT";
            const string firstName = "John";

            var fakeName = new FakeName { First = firstName, Last = "Doe" };

            var getter = PropertyInfoPropertyValueGetter.CreatePropertyInfoPropertyValueGetter(fakeName, firstProperty);

            Assert.Equal("First", getter.PropertyName);
            Assert.Equal(firstName, getter.GetPropertyValue(fakeName));
        }
Exemple #12
0
        public void CreatePropertyInfoPropertyValueGetter_EmptyStringProperty_NullGetter()
        {
            const string propertyName = "";

            var fakeName = new FakeName {
                First = "Firstie", Last = "Lastly"
            };

            var getter = PropertyInfoPropertyValueGetter.CreatePropertyInfoPropertyValueGetter(fakeName, propertyName.ToLower());

            Assert.Null(getter);
        }
Exemple #13
0
        public void CreatePropertyInfoPropertyValueGetter_NonDynamicInstance_ValidGetterCreated()
        {
            const string firstProperty = "First";
            const string firstName     = "John";

            var fakeName = new FakeName {
                First = firstName, Last = "Doe"
            };
            var getter = PropertyInfoPropertyValueGetter.CreatePropertyInfoPropertyValueGetter(fakeName, firstProperty);

            Assert.Equal(firstProperty, getter.PropertyName);
            Assert.Equal(firstName, getter.GetPropertyValue(fakeName));
        }
Exemple #14
0
        public void CreatePropertyInfoPropertyValueGetter_PropertyCaseDoesNotMatch_ValidGetterCreated()
        {
            const string firstProperty = "fIRsT";
            const string firstName     = "John";

            var fakeName = new FakeName {
                First = firstName, Last = "Doe"
            };

            var getter = PropertyInfoPropertyValueGetter.CreatePropertyInfoPropertyValueGetter(fakeName, firstProperty);

            Assert.Equal("First", getter.PropertyName);
            Assert.Equal(firstName, getter.GetPropertyValue(fakeName));
        }
Exemple #15
0
        public void GetPropertyValue_NullInstance_RuntimeBinderException()
        {
            const string propertyName = "First";

            var fakeName = new FakeName {
                First = "Hank", Last = "The Tank"
            };

            var getter = PropertyInfoPropertyValueGetter.CreatePropertyInfoPropertyValueGetter(fakeName, propertyName);

            Assert.Throws <ArgumentNullException>(
                () =>
                getter.GetPropertyValue(null)
                );
        }
Exemple #16
0
        public void GetPropertyValue_PropertyDoesNotExistOnInstance_TargetException()
        {
            const string propertyName = "First";

            var fakeName = new FakeName {
                First = "Thor", Last = "Jenkins"
            };

            var getter = PropertyInfoPropertyValueGetter.CreatePropertyInfoPropertyValueGetter(fakeName, propertyName);

            var fakeLink = new FakeLink {
                Rel = "self", Uri = "http://localhost/"
            };

            Assert.Throws <TargetException>(
                () =>
                getter.GetPropertyValue(fakeLink)
                );
        }
Exemple #17
0
        public void GetPartialResponse_InvalidFieldSelectionOnFlatObj_ReturnsEmptyDynamic()
        {
            const string Person0FirstName = "Thor";
            var          myDto            = new FakeName {
                First = Person0FirstName, Last = string.Empty
            };

            var partialFieldSelectors = new List <FieldSelectorTreeNode>
            {
                new FieldSelectorTreeNode("DoesNotExist"),
            };

            var     partialResponsinator = new PartialResponsinator(partialFieldSelectors, MockRepository.GenerateStub <IPropertyValueGetterFactory>());
            dynamic partialResp          = partialResponsinator.GetPartialResponse(myDto);

            Assert.NotNull(partialResp);

            var asDict = partialResp as IDictionary <string, object>;

            Assert.Equal(0, asDict.Count);
        }
        public void GetPropertyValue_PropertyDoesNotExistOnInstance_TargetException()
        {
            const string propertyName = "First";
            
            var fakeName = new FakeName { First = "Thor", Last = "Jenkins" };

            var getter = PropertyInfoPropertyValueGetter.CreatePropertyInfoPropertyValueGetter(fakeName, propertyName);

            var fakeLink = new FakeLink {Rel = "self", Uri = "http://localhost/"};
            Assert.Throws<TargetException>(
                () =>
                    getter.GetPropertyValue(fakeLink)
                );
        }
        public void GetPartialResponse_InvalidFieldSelectionOnFlatObj_ReturnsEmptyDynamic()
        {
            const string Person0FirstName = "Thor";
            var myDto = new FakeName {First = Person0FirstName, Last = string.Empty};

            var partialFieldSelectors = new List<FieldSelectorTreeNode>
            {
                new FieldSelectorTreeNode("DoesNotExist"),
            };

            var partialResponsinator = new PartialResponsinator(partialFieldSelectors, MockRepository.GenerateStub<IPropertyValueGetterFactory>());
            dynamic partialResp = partialResponsinator.GetPartialResponse(myDto);

            Assert.NotNull(partialResp);

            var asDict = partialResp as IDictionary<string, object>;

            Assert.Equal(0, asDict.Count);
        }
Exemple #20
0
        public void GetPartialResponse_FlatObject_ResultContainsOnlySelectedFields()
        {
            const string uriField      = "Uri";
            const string salaryField   = "Salary";
            const string homepageField = "HomePage";
            const string nameField     = "Name";

            const string  janeDoeHomepageUri = "http://janedoe.com/";
            const string  deeDoeFirstName    = "Dee";
            const string  deeDoeLastName     = "Doe";
            const decimal janeDoeSalary      = 100000000581.00m;

            var homepage = new FakeLink {
                Rel = "homepage", Uri = janeDoeHomepageUri
            };
            var name = new FakeName {
                First = deeDoeFirstName, Last = deeDoeLastName
            };

            var propertyValues = new Dictionary <string, object>();

            propertyValues[uriField]      = janeDoeHomepageUri;
            propertyValues[salaryField]   = janeDoeSalary;
            propertyValues[homepageField] = homepage;
            propertyValues[nameField]     = name;

            var fakeDto =
                new FakeFlatDto
            {
                HomePage = homepage,
                Name     = name,
                Salary   = janeDoeSalary
            };

            var partialFieldSelectors = new List <FieldSelectorTreeNode>
            {
                new FieldSelectorTreeNode("Salary"),
                new FieldSelectorTreeNode("Name"),
                new FieldSelectorTreeNode("HomePage")
                {
                    Children = new List <FieldSelectorTreeNode>
                    {
                        new FieldSelectorTreeNode("Uri")
                    }
                }
            };

            var factory = MockRepository.GenerateStub <IPropertyValueGetterFactory>();

            factory.Stub(x => x.CreatePropertyValueGetter(null, null)).IgnoreArguments().Return(null).WhenCalled(x =>
            {
                var getter = MockRepository.GenerateStub <IPropertyValueGetter>();
                getter.Stub(g => g.PropertyName).Return((string)x.Arguments[1]);
                getter.Stub(g => g.GetPropertyValue(null)).IgnoreArguments().Return(propertyValues[(string)x.Arguments[1]]);
                x.ReturnValue = getter;
            });

            var     responsinator = new PartialResponsinator(partialFieldSelectors, factory);
            dynamic responsible   = responsinator.GetPartialResponse(fakeDto);

            Assert.Equal(deeDoeFirstName, responsible.Name.First);
            Assert.Equal(deeDoeLastName, responsible.Name.Last);
            Assert.Equal(janeDoeHomepageUri, responsible.HomePage.Uri);
            var homePage = responsible.HomePage as IDictionary <string, object>;

            Assert.False(homePage.ContainsKey("Rel"));
        }
        public void GetPropertyValue_NullInstance_RuntimeBinderException()
        {
            const string propertyName = "First";

            var fakeName = new FakeName {First = "Hank", Last = "The Tank"};

            var getter = PropertyInfoPropertyValueGetter.CreatePropertyInfoPropertyValueGetter(fakeName, propertyName);

            Assert.Throws<ArgumentNullException>(
                () =>
                    getter.GetPropertyValue(null)
                );
        }