public void CanSetAccessor()
		{
			var mapdoc = new HbmMapping();
			var component = new HbmDynamicComponent();
			var mapper = new DynamicComponentMapper(component, For<Person>.Property(p => p.Info), mapdoc);

			mapper.Access(Accessor.Field);
			Assert.That(component.access, Is.EqualTo("field.camelcase"));
		}
		public void CanSetInsert()
		{
			var mapdoc = new HbmMapping();
			var component = new HbmDynamicComponent();
			var mapper = new DynamicComponentMapper(component, For<Person>.Property(p => p.Info), mapdoc);

			mapper.Insert(false);
			component.insert.Should().Be.False();
		}
		public void CanSetOptimisticLock()
		{
			var mapdoc = new HbmMapping();
			var component = new HbmDynamicComponent();
			var mapper = new DynamicComponentMapper(component, For<Person>.Property(p => p.Info), mapdoc);

			mapper.OptimisticLock(false);
			Assert.That(component.OptimisticLock, Is.False);
		}
		public void CanSetAccessor()
		{
			var mapdoc = new HbmMapping();
			var component = new HbmDynamicComponent();
			var mapper = new DynamicComponentMapper(component, For<Person>.Property(p => p.Info), mapdoc);

			mapper.Access(Accessor.Field);
			component.access.Should().Be("field.camelcase");
		}
		public void CanSetUpdate()
		{
			var mapdoc = new HbmMapping();
			var component = new HbmDynamicComponent();
			var mapper = new DynamicComponentMapper(component, For<Person>.Property(p => p.Info), mapdoc);

			mapper.Update(false);
			Assert.That(component.update, Is.False);
		}
		public void CanAddSimpleProperty()
		{
			var mapdoc = new HbmMapping();
			var component = new HbmDynamicComponent();
			var mapper = new DynamicComponentMapper(component, For<Person>.Property(p => p.Info), mapdoc);
			var dynObject = new { Pizza = 5 };
			mapper.Property(dynObject.GetType().GetProperty("Pizza"), x => { });

			component.Properties.Single().Should().Be.OfType<HbmProperty>().And.ValueOf.Name.Should().Be.EqualTo("Pizza");
		}
		public void CanAddSimpleProperty()
		{
			var mapdoc = new HbmMapping();
			var component = new HbmDynamicComponent();
			var mapper = new DynamicComponentMapper(component, For<Person>.Property(p => p.Info), mapdoc);
			var dynObject = new { Pizza = 5 };
			mapper.Property(dynObject.GetType().GetProperty("Pizza"), x => { });

			Assert.That(component.Properties.Single(), Is.TypeOf<HbmProperty>().And.Property("Name").EqualTo("Pizza"));
		}
		public virtual void Component(MemberInfo property, Action<IDynamicComponentMapper> mapping)
		{
			if (!IsMemberSupportedByMappedContainer(property))
			{
				throw new ArgumentOutOfRangeException("property", "Can't add a property of another graph");
			}
			var hbm = new HbmDynamicComponent { name = property.Name };
			mapping(new DynamicComponentMapper(hbm, property, MapDoc));
			AddProperty(hbm);
		}
		public void WhenCustomizeAccessorThenIgnore()
		{
			var mapdoc = new HbmMapping();
			var component = new HbmDynamicComponent();
			var mapper = new DynamicComponentMapper(component, For<Person>.Property(p => p.Info), mapdoc);
			var propertyInfo = (new { A = (object)null }).GetType().GetProperty("A");

			mapper.Any(propertyInfo, typeof(int), x => x.Access(Accessor.Field));

			Assert.That(component.Properties.OfType<HbmAny>().Single().Access, Is.Null.Or.Empty);
		}
		public void WhenCustomizeAccessorThenIgnore()
		{
			var mapdoc = new HbmMapping();
			var component = new HbmDynamicComponent();
			var mapper = new DynamicComponentMapper(component, For<Person>.Property(p => p.Info), mapdoc);
			var propertyInfo = For<Person>.Property(p => p.Info);//just as another dyn-compo

			mapper.Component(propertyInfo, (IDynamicComponentMapper x) => x.Access(Accessor.Field));

			component.Properties.OfType<HbmDynamicComponent>().Single().Access.Should().Be.NullOrEmpty();
		}
		public void WhenCustomizeAccessorThenIgnore()
		{
			var mapdoc = new HbmMapping();
			var component = new HbmDynamicComponent();
			var mapper = new DynamicComponentMapper(component, For<Person>.Property(p => p.Info), mapdoc);
			var propertyInfo = (new { A = (IEnumerable<int>)null }).GetType().GetProperty("A");

			mapper.IdBag(propertyInfo, x => x.Access(Accessor.Field), rel => { });

			component.Properties.OfType<HbmIdbag>().Single().Access.Should().Be.NullOrEmpty();
		}		
		public void WhenAddThenHas()
		{
			var mapdoc = new HbmMapping();
			var component = new HbmDynamicComponent();
			var mapper = new DynamicComponentMapper(component, For<Person>.Property(p => p.Info), mapdoc);
			var propertyInfo = (new { A = (IEnumerable<int>)null }).GetType().GetProperty("A");

			mapper.IdBag(propertyInfo, x => { }, rel => { });

			component.Properties.Select(x => x.Name).Should().Have.SameSequenceAs("A");
		}
		public void WhenAddThenHas()
		{
			var mapdoc = new HbmMapping();
			var component = new HbmDynamicComponent();
			var mapper = new DynamicComponentMapper(component, For<Person>.Property(p => p.Info), mapdoc);
			var propertyInfo = For<Person>.Property(p => p.Info);//just as another dyn-compo

			mapper.Component(propertyInfo, (IDynamicComponentMapper x) => { });

			Assert.That(component.Properties.Select(x => x.Name), Is.EquivalentTo(new[] { "Info" }));
		}
		public void WhenCustomizeAccessorThenIgnore()
		{
			var mapdoc = new HbmMapping();
			var component = new HbmDynamicComponent();
			var mapper = new DynamicComponentMapper(component, For<Person>.Property(p => p.Info), mapdoc);
			var propertyInfo = (new { A = (IDictionary<int, int>)null }).GetType().GetProperty("A");

			mapper.Map(propertyInfo, x => x.Access(Accessor.Field), km => { }, rel => { });

			Assert.That(component.Properties.OfType<HbmMap>().Single().Access, Is.Null.Or.Empty);
		}		
		public void WhenCustomizeThenCallCustomizer()
		{
			var mapdoc = new HbmMapping();
			var component = new HbmDynamicComponent();
			var mapper = new DynamicComponentMapper(component, For<Person>.Property(p => p.Info), mapdoc);
			var propertyInfo = (new { A = 5 }).GetType().GetProperty("A");
			var called = false;
			mapper.Property(propertyInfo, x => called = true);

			called.Should().Be.True();
		}
		public void WhenCustomizeAccessorThenIgnore()
		{
			var mapdoc = new HbmMapping();
			var component = new HbmDynamicComponent();
			var mapper = new DynamicComponentMapper(component, For<Person>.Property(p => p.Info), mapdoc);
			var propertyInfo = (new { A = (MyClass)null }).GetType().GetProperty("A");

			mapper.ManyToOne(propertyInfo, x => x.Access(Accessor.Field));

			component.Properties.OfType<HbmManyToOne>().Single().Access.Should().Be.NullOrEmpty();
		}
		public void WhenAddThenHas()
		{
			var mapdoc = new HbmMapping();
			var component = new HbmDynamicComponent();
			var mapper = new DynamicComponentMapper(component, For<Person>.Property(p => p.Info), mapdoc);
			var propertyInfo = (new { A = (IDictionary<int, int>)null }).GetType().GetProperty("A");

			mapper.Map(propertyInfo, x => { }, km => { }, rel => { });

			Assert.That(component.Properties.Select(x => x.Name), Is.EquivalentTo(new[] { "A" }));
		}
		public void WhenAddThenHas()
		{
			var mapdoc = new HbmMapping();
			var component = new HbmDynamicComponent();
			var mapper = new DynamicComponentMapper(component, For<Person>.Property(p => p.Info), mapdoc);
			var propertyInfo = For<Person>.Property(p => p.Info);//just as another dyn-compo

			mapper.Component(propertyInfo, (IDynamicComponentMapper x) => { });

			component.Properties.Select(x => x.Name).Should().Have.SameSequenceAs("Info");
		}
		public void WhenCustomizeThenCallCustomizer()
		{
			var mapdoc = new HbmMapping();
			var component = new HbmDynamicComponent();
			var mapper = new DynamicComponentMapper(component, For<Person>.Property(p => p.Info), mapdoc);
			var propertyInfo = (new { A = (IDictionary<int, int>)null }).GetType().GetProperty("A");

			var called = false;
			mapper.Map(propertyInfo, x => called = true, km => { }, rel => { });

			Assert.That(called, Is.True);
		}
		private DynamicComponentMapper(HbmDynamicComponent component, MemberInfo declaringTypeMember, IAccessorPropertyMapper accessorMapper, HbmMapping mapDoc)
		{
			if (mapDoc == null)
			{
				throw new ArgumentNullException("mapDoc");
			}
			Container = declaringTypeMember.DeclaringType;
			MapDoc = mapDoc;

			this.component = component;
			accessorPropertyMapper = accessorMapper;
		}
		public void WhenCustomizeThenCallCustomizer()
		{
			var mapdoc = new HbmMapping();
			var component = new HbmDynamicComponent();
			var mapper = new DynamicComponentMapper(component, For<Person>.Property(p => p.Info), mapdoc);
			var propertyInfo = For<Person>.Property(p => p.Info);//just as another dyn-compo

			var called = false;
			mapper.Component(propertyInfo, (IDynamicComponentMapper x) => called = true);

			called.Should().Be.True();
		}
		public void WhenCustomizeThenCallCustomizer()
		{
			var mapdoc = new HbmMapping();
			var component = new HbmDynamicComponent();
			var mapper = new DynamicComponentMapper(component, For<Person>.Property(p => p.Info), mapdoc);
			var propertyInfo = (new { A = (MyClass)null }).GetType().GetProperty("A");

			var called = false;
			mapper.ManyToOne(propertyInfo, x => called = true);

			Assert.That(called, Is.True);
		}
		private void BindComponentProperty(HbmDynamicComponent dynamicComponentMapping, Property property)
		{
			property.IsUpdateable = dynamicComponentMapping.update;
			property.IsInsertable = dynamicComponentMapping.insert;
		}
		private void BindComponentProperty(HbmDynamicComponent dynamicComponentMapping, Property property, Component model)
		{
			property.IsUpdateable = dynamicComponentMapping.update;
			property.IsInsertable = dynamicComponentMapping.insert;
			if (dynamicComponentMapping.unique)
			{
				model.Owner.Table.CreateUniqueKey(model.ColumnIterator.OfType<Column>().ToList());
			}
		}
		public void Component(MemberInfo property, Action<IDynamicComponentMapper> mapping)
		{
			var hbm = new HbmDynamicComponent { name = property.Name };
			mapping(new DynamicComponentMapper(hbm, property, new NoMemberPropertyMapper(), MapDoc));
			AddProperty(hbm);
		}
		public DynamicComponentMapper(HbmDynamicComponent component, MemberInfo declaringTypeMember, HbmMapping mapDoc)
			: this(component, declaringTypeMember, new AccessorPropertyMapper(declaringTypeMember.DeclaringType, declaringTypeMember.Name, x => component.access = x), mapDoc) {}