Ejemplo n.º 1
0
        public void ShouldThrowNotSupportedException_WhenMemberTypeIsNotSupported()
        {
            var controller             = new MemberConfigurationAccessController();
            var notSupportedMemberType = NotSupportedMemberType;

            Assert.Throws <NotSupportedException>(() => controller.CreateMemberConfigurationForType("member",
                                                                                                    notSupportedMemberType,
                                                                                                    new TypeResolvingConfiguration(typeof(object))));
            Assert.Throws <NotSupportedException>(() => controller.GetMemberConfigurationType("member",
                                                                                              notSupportedMemberType,
                                                                                              new TypeResolvingConfiguration(typeof(object))));
            Assert.Throws <NotSupportedException>(() => controller.HasMemberConfigurationType("member",
                                                                                              notSupportedMemberType,
                                                                                              new TypeResolvingConfiguration(typeof(object))));
        }
Ejemplo n.º 2
0
        public void ShouldSupportSupportedMemberTypes()
        {
            var supportConsultant = new MemberTypeSupportConsultant();
            var controller        = new MemberConfigurationAccessController();

            foreach (var supportedMemberType in supportConsultant.SupportedTypes)
            {
                // absence of NotSupportedExceptions means type is supported
                controller.CreateMemberConfigurationForType("member", supportedMemberType,
                                                            new TypeResolvingConfiguration(typeof(object)));
                controller.GetMemberConfigurationType("member", supportedMemberType,
                                                      new TypeResolvingConfiguration(typeof(object)));
                controller.HasMemberConfigurationType("member", supportedMemberType,
                                                      new TypeResolvingConfiguration(typeof(object)));
            }
        }
        /// <inheritdoc />
        void IMemberConfigurationHandler.HandleMemberConfiguration(MemberInfo member, JsonProperty property, TypeResolvingConfiguration configuration)
        {
            if (_memberConfigurationAccessController.HasMemberConfigurationType(member.Name,
                                                                                member.MemberType,
                                                                                configuration))
            {
                var memberConfiguration = _memberConfigurationAccessController.GetMemberConfigurationType(member.Name,
                                                                                                          member.MemberType,
                                                                                                          configuration);
                property.PropertyName = memberConfiguration.JsonBinding;
                if (memberConfiguration.Ignored)
                {
                    // PropertyName cannot be null
                    property.Ignored      = true;
                    property.PropertyName = string.Empty;
                }

                HandleMemberConfiguration(member, property, memberConfiguration as TMemberConfiguration);
            }
        }