Exemple #1
0
        public void GetPolicy_Returns_SpecifiedPolicy()
        {
            PropertyInfo propInfo = typeof(AttributeWithResolutionPolicy).GetProperty(nameof(AttributeWithResolutionPolicy.PropWithPolicy));

            IResolutionPolicy policy = AttributeCloner <AttributeWithResolutionPolicy> .GetPolicy(propInfo);

            Assert.IsType <TestResolutionPolicy>(policy);
        }
        public void GetPolicy_ReturnsDefault_WhenNoSpecifiedPolicy()
        {
            PropertyInfo         propInfo = typeof(AttributeWithResolutionPolicy).GetProperty(nameof(AttributeWithResolutionPolicy.PropWithoutPolicy));
            AutoResolveAttribute attr     = propInfo.GetCustomAttribute <AutoResolveAttribute>();
            IResolutionPolicy    policy   = AttributeCloner <AttributeWithResolutionPolicy> .GetPolicy(attr.ResolutionPolicyType, propInfo);

            Assert.IsType <DefaultResolutionPolicy>(policy);
        }
Exemple #3
0
        public void GetPolicy_ReturnsODataFilterPolicy_ForMarkerType()
        {
            // This is a special-case marker type to handle TableAttribute.Filter. We cannot directly list ODataFilterResolutionPolicy
            // because BindingTemplate doesn't exist in the core assembly.
            PropertyInfo propInfo = typeof(AttributeWithResolutionPolicy).GetProperty(nameof(AttributeWithResolutionPolicy.PropWithMarkerPolicy));

            IResolutionPolicy policy = AttributeCloner <AttributeWithResolutionPolicy> .GetPolicy(propInfo);

            Assert.IsType <Host.Bindings.ODataFilterResolutionPolicy>(policy);
        }
Exemple #4
0
        public void GetPolicy_Throws_IfPolicyHasNoDefaultConstructor()
        {
            PropertyInfo propInfo = typeof(AttributeWithResolutionPolicy).GetProperty(nameof(AttributeWithResolutionPolicy.PropWithConstructorlessPolicy));

            InvalidOperationException ex = Assert.Throws <InvalidOperationException>(() => AttributeCloner <AttributeWithResolutionPolicy> .GetPolicy(propInfo));

            Assert.Equal($"The {nameof(AutoResolveAttribute.ResolutionPolicyType)} on {nameof(AttributeWithResolutionPolicy.PropWithConstructorlessPolicy)} must derive from {typeof(IResolutionPolicy).Name} and have a default constructor.", ex.Message);
        }
Exemple #5
0
        public void GetPolicy_Throws_IfPolicyDoesNotImplementInterface()
        {
            PropertyInfo propInfo = typeof(AttributeWithResolutionPolicy).GetProperty(nameof(AttributeWithResolutionPolicy.PropWithInvalidPolicy));

            InvalidOperationException ex = Assert.Throws <InvalidOperationException>(() => AttributeCloner <AttributeWithResolutionPolicy> .GetPolicy(propInfo));

            Assert.Equal($"The {nameof(AutoResolveAttribute.ResolutionPolicyType)} on {nameof(AttributeWithResolutionPolicy.PropWithInvalidPolicy)} must derive from {typeof(IResolutionPolicy).Name}.", ex.Message);
        }