public void MultipleExpectsShouldValidateToTrueIfGivenMatchingModel()
        {
            acceptance.Expect(x => x.Insert, Is.Set);
            acceptance.Expect(x => x.Update, Is.Set);

            var propertyMapping = new PropertyMapping();
            propertyMapping.Set(x => x.Insert, Layer.Defaults, true);
            propertyMapping.Set(x => x.Update, Layer.Defaults, true);
            acceptance
                .Matches(new PropertyInspector(propertyMapping))
                .ShouldBeTrue();
        }
        public void AnyShouldValidateToTrueIfAllMatch()
        {
            acceptance
                .Any(c => c.Expect(x => x.Name, Is.Set), 
                     c => c.Expect(x => x.Type, Is.Set), 
                     c => c.Expect(x => x.Insert, Is.Set));

            var propertyMapping = new PropertyMapping();
            propertyMapping.Set(x => x.Name, Layer.Defaults, "Property1");
            propertyMapping.Set(x => x.Type, Layer.Defaults, new TypeReference(typeof(string)));
            propertyMapping.Set(x => x.Insert, Layer.Defaults, true);
            acceptance
               .Matches(new PropertyInspector(propertyMapping))
               .ShouldBeTrue();
        }
예제 #3
0
        private bool HasExplicitTypeConvention(Member property)
        {
            // todo: clean this up!
            //        What it's doing is finding if there are any IUserType conventions
            //        that would be applied to this property, if there are then we should
            //        definitely automap it. The nasty part is that right now we don't have
            //        a model, so we're having to create a fake one so the convention will
            //        apply to it.
            var conventions = conventionFinder
                .Find<IPropertyConvention>()
                .Where(c =>
                {
                    if (!typeof(IUserTypeConvention).IsAssignableFrom(c.GetType()))
                        return false;

                    var criteria = new ConcreteAcceptanceCriteria<IPropertyInspector>();
                    var acceptance = c as IConventionAcceptance<IPropertyInspector>;
                    
                    if (acceptance != null)
                        acceptance.Accept(criteria);

                    var propertyMapping = new PropertyMapping
                    {
                        Member = property
                    };
                    propertyMapping.Set(x => x.Type, Layer.Defaults, new TypeReference(property.PropertyType));
                    return criteria.Matches(new PropertyInspector(propertyMapping));
                });

            return conventions.FirstOrDefault() != null;
        }
        public void CanAddProperty()
        {
            var property = new PropertyMapping();
            property.Set(x => x.Name, Layer.Defaults, "Property1");
            mapping.AddProperty(property);

            mapping.Properties.ShouldContain(property);
        }
        public void IsNotAnySucceedsIfNoValuesMatch()
        {
            acceptance.Expect(x => x.Access.IsNotAny(Access.Property, Access.Field));

            var propertyMapping = new PropertyMapping();
            propertyMapping.Set(x => x.Access, Layer.Defaults, Access.CamelCaseField().ToString());
            acceptance
                .Matches(new PropertyInspector(propertyMapping))
                .ShouldBeTrue();
        }
        public void ExpectNotEqualShouldValidateToFalseIfNotGivenMatchingModel()
        {
            acceptance.Expect(x => x.Insert != true);

            var propertyMapping = new PropertyMapping();
            propertyMapping.Set(x => x.Insert, Layer.Defaults, true);
            acceptance
                .Matches(new PropertyInspector(propertyMapping))
                .ShouldBeFalse();
        }
        public void ExpectNotEqualShouldValidateToFalseIfNotGivenMatchingModel()
        {
            acceptance.Expect(x => x.Access != Access.Field);

            var propertyMapping = new PropertyMapping();
            propertyMapping.Set(x => x.Access, Layer.Defaults, "field");
            acceptance
                .Matches(new PropertyInspector(propertyMapping))
                .ShouldBeFalse();
        }
예제 #8
0
        private PropertyMapping GetPropertyMapping(Type type, Member property)
        {
            var mapping = new PropertyMapping
            {
                ContainingEntityType = type,
                Member = property
            };

            var columnMapping = new ColumnMapping();
            columnMapping.Set(x => x.Name, Layer.Defaults, property.Name);
            mapping.AddColumn(Layer.Defaults, columnMapping);

            mapping.Set(x => x.Name, Layer.Defaults, mapping.Member.Name);
            mapping.Set(x => x.Type, Layer.Defaults, GetDefaultType(property));

            SetDefaultAccess(property, mapping);

            return mapping;
        }
        public void MultipleExpectsShouldValidateToFalseIfOnlyOneMatches()
        {
            acceptance.Expect(x => x.Insert, Is.Set);
            acceptance.Expect(x => x.Update, Is.Set);

            var propertyMapping = new PropertyMapping();
            propertyMapping.Set(x => x.Insert, Layer.Defaults, true);
            acceptance
                .Matches(new PropertyInspector(propertyMapping))
                .ShouldBeFalse();
        }
        public void ExpectShouldEvaluateSubPropertyWithEvaluation()
        {
            acceptance.Expect(x =>
                x.Type.Name == typeof(Record).Name);

            var propertyMapping = new PropertyMapping
            {
                Member = ReflectionHelper.GetMember<Record>(x => x.Age),
            };
            propertyMapping.Set(x => x.Type, Layer.Defaults, new TypeReference(typeof(Record)));
            acceptance.Matches(new PropertyInspector(propertyMapping))
                .ShouldBeTrue();
        }
        public void CanPassSubCriteriaToAny()
        {
            var subCriteria1 = new ConcreteAcceptanceCriteria<IPropertyInspector>();
            subCriteria1.Expect(x => x.Name, Is.Set);

            var subCriteria2 = new ConcreteAcceptanceCriteria<IPropertyInspector>();
            subCriteria2.Expect(x => x.Type, Is.Set);

            acceptance.Any(subCriteria1, subCriteria2);

            var propertyMapping = new PropertyMapping();
            propertyMapping.Set(x => x.Name, Layer.Defaults, "Property1");
            acceptance
                .Matches(new PropertyInspector(propertyMapping))
                .ShouldBeTrue();
        }
        public void IsNotAnyFailsIfAnyOfTheSuppliedValuesMatch()
        {
            acceptance.Expect(x => x.Access.IsNotAny(Access.Property, Access.Field));

            var propertyMapping = new PropertyMapping();
            propertyMapping.Set(x => x.Access, Layer.Defaults, Access.Field.ToString());

            var propertyMapping2 = new PropertyMapping();
            propertyMapping2.Set(x => x.Access, Layer.Defaults, Access.Property.ToString());

            acceptance
                .Matches(new PropertyInspector(propertyMapping))
                .ShouldBeFalse();

            acceptance
                .Matches(new PropertyInspector(propertyMapping2))
                .ShouldBeFalse();
        }
예제 #13
0
        void SetDefaultAccess(Member member, PropertyMapping mapping)
        {
            var resolvedAccess = MemberAccessResolver.Resolve(member);

            if (resolvedAccess != Access.Property && resolvedAccess != Access.Unset)
            {
                // if it's a property or unset then we'll just let NH deal with it, otherwise
                // set the access to be whatever we determined it might be
                mapping.Set(x => x.Access, Layer.Defaults, resolvedAccess.ToString());
            }

            if (member.IsProperty && !member.CanWrite)
            {
                mapping.Set(x => x.Access, Layer.Defaults, cfg.GetAccessStrategyForReadOnlyProperty(member).ToString());
            }
        }
        public void CombinationOfSetAndNotSetShouldValidateToFalseWhenNoneMatch()
        {
            acceptance
                .Expect(x => x.Insert, Is.Not.Set)
                .Expect(x => x.Update, Is.Set);

            var propertyMapping = new PropertyMapping();
            propertyMapping.Set(x => x.Insert, Layer.Defaults, true);
            acceptance
                .Matches(new PropertyInspector(propertyMapping))
                .ShouldBeFalse();
        }
        public void EitherIsAnyWithTwoParameters()
        {
            acceptance
                .Either(c => c.Expect(x => x.Name, Is.Set), 
                        c => c.Expect(x => x.Type, Is.Set));

            var propertyMapping = new PropertyMapping();
            propertyMapping.Set(x => x.Name, Layer.Defaults, "Property1");
            acceptance
               .Matches(new PropertyInspector(propertyMapping))
               .ShouldBeTrue();
        }