PropertyMapping IPropertyMappingProvider.GetPropertyMapping() { var mapping = new PropertyMapping(attributes.Clone()) { ContainingEntityType = parentType, Member = member }; if (columns.Count() == 0 && !mapping.IsSpecified("Formula")) { var columnMapping = new ColumnMapping(columnAttributes.Clone()); columnMapping.Set(x => x.Name, Layer.Defaults, member.Name); mapping.AddColumn(Layer.Defaults, columnMapping); } foreach (var column in columns) { mapping.AddColumn(Layer.UserSupplied, column); } foreach (var column in mapping.Columns) { if (member.PropertyType.IsNullable() && member.PropertyType.IsEnum()) { column.Set(x => x.NotNull, Layer.Defaults, false); } column.MergeAttributes(columnAttributes); } mapping.Set(x => x.Name, Layer.Defaults, mapping.Member.Name); mapping.Set(x => x.Type, Layer.Defaults, GetDefaultType()); return(mapping); }
public void ShouldUseInheritedOppositeCriteria() { acceptance .OppositeOf <AnotherConvention>(); 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 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 MultipleExpectNotSetsShouldValidateToFalseIfNoneMatch() { acceptance .Expect(x => x.Insert, Is.Not.Set) .Expect(x => x.Update, Is.Not.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)) .ShouldBeFalse(); }
protected virtual NaturalIdPart <T> Property(Member member, string columnName) { var key = new PropertyMapping(); key.Set(x => x.Name, Layer.Defaults, member.Name); key.Set(x => x.Type, Layer.Defaults, new TypeReference(member.PropertyType)); var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, columnName); key.AddColumn(Layer.UserSupplied, columnMapping); properties.Add(key); return(this); }
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(); }
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()); } }
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 ExpectNotEqualShouldValidateToTrueIfGivenMatchingModel() { acceptance.Expect(x => x.Insert != true); var propertyMapping = new PropertyMapping(); propertyMapping.Set(x => x.Insert, Layer.Defaults, false); acceptance .Matches(new PropertyInspector(propertyMapping)) .ShouldBeTrue(); }
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 ExpectNotSetShouldValidateToFalseIfNotGivenMatchingModel() { acceptance.Expect(x => x.Insert, Is.Not.Set); 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(); }
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(); }
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 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 CanPassSubCriteriaToEither() { 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.Either(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(); }
/// <inheritdoc /> public new void Insert() { mapping.Set(x => x.Insert, layer, nextBool); nextBool = true; }