public void WhenSplittedPropertiesThenRegister()
		{
			var inspector = new ExplicitlyDeclaredModel();
			var mapper = new ModelMapper(inspector);
			mapper.Class<MyClass>(map =>
														{
															map.Id(x => x.Id, idmap => { });
															map.Join("MyClassSplit1", mj=>
															{
																mj.Property(x => x.SomethingA1);
																mj.Property(x => x.SomethingA2);
															});
															map.Join("MyClassSplit2", mj =>
															{
																mj.Property(x => x.SomethingB1);
																mj.Property(x => x.SomethingB2);
															});
															map.Property(x => x.Something0);
														});

			Assert.That(inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit1", For<MyClass>.Property(x => x.Something0)), Is.False);
			Assert.That(inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit2", For<MyClass>.Property(x => x.Something0)), Is.False);

			Assert.That(inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit1", For<MyClass>.Property(x => x.SomethingA1)), Is.True);
			Assert.That(inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit1", For<MyClass>.Property(x => x.SomethingA2)), Is.True);
			Assert.That(inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit2", For<MyClass>.Property(x => x.SomethingB1)), Is.True);
			Assert.That(inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit2", For<MyClass>.Property(x => x.SomethingB2)), Is.True);
		}
		public void WhenRegisterJoinedSubclassWithNoRootThenCanAskForIsEntity()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsTablePerClassEntity(typeof(Inherited1));

			inspector.IsEntity(typeof(Inherited1)).Should().Be.True();
		}
		public void WhenRegisterUnionSubclassWithNoRootThenThrows()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsTablePerConcreteClassEntity(typeof(Inherited1));

			Assert.That(() => inspector.IsTablePerConcreteClass(typeof(Inherited1)), Throws.TypeOf<MappingException>());
		}		
		public void WhenRegisteredAsComponentThenIsRegistered()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsComponent(typeof(MyComponent));

			inspector.IsComponent(typeof(MyComponent)).Should().Be.True();
		}
		public void WhenRegisteredAsComponetThenCantRegisterAsRootEntity()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsComponent(typeof(MyComponent));

			inspector.Executing(x => x.AddAsRootEntity(typeof(MyComponent))).Throws<MappingException>();
		}
		public void WhenMapSplittedPropertiesThenEachPropertyIsInItsSplitGroup()
		{
			var inspector = new ExplicitlyDeclaredModel();
			var mapper = new ModelMapper(inspector);
			mapper.Class<MyClass>(map => map.Id(x => x.Id, idmap => { }));
			mapper.Subclass<Inherited>(map =>
			{
				map.Join("MyClassSplit1", mj =>
				{
					mj.Property(x => x.SomethingA1);
					mj.Property(x => x.SomethingA2);
				});
				map.Join("MyClassSplit2", mj =>
				{
					mj.Property(x => x.SomethingB1);
					mj.Property(x => x.SomethingB2);
				});
				map.Property(x => x.Something0);
			});
			var hbmDoc = mapper.CompileMappingFor(new[] { typeof(Inherited) });

			var hbmClass = hbmDoc.SubClasses[0];
			hbmClass.Joins.Select(j => j.table).Should().Have.SameValuesAs("MyClassSplit1", "MyClassSplit2");
			hbmClass.Properties.Single().Name.Should().Be("Something0");
			var hbmSplit1 = hbmClass.Joins.Single(j => "MyClassSplit1" == j.table);
			hbmSplit1.Properties.Select(p => p.Name).Should().Have.SameValuesAs("SomethingA1", "SomethingA2");
			var hbmSplit2 = hbmClass.Joins.Single(j => "MyClassSplit2" == j.table);
			hbmSplit2.Properties.Select(p => p.Name).Should().Have.SameValuesAs("SomethingB1", "SomethingB2");
		}
		public void WhenRegisterSubclassWithNoRootThenThrows()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsTablePerClassHierarchyEntity(typeof(Inherited1));

			inspector.Executing(x => x.IsTablePerClassHierarchy(typeof(Inherited1))).Throws<MappingException>();
		}
		public void WhenRegisteredAsComponentThenIsRegistered()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsComponent(typeof(MyComponent));

			Assert.That(inspector.IsComponent(typeof(MyComponent)), Is.True);
		}
		public void WhenSplittedPropertiesThenRegister()
		{
			var inspector = new ExplicitlyDeclaredModel();
			var mapper = new ModelMapper(inspector);
			mapper.Subclass<Inherited>(map =>
			{
				map.Join("MyClassSplit1", mj =>
				{
					mj.Property(x => x.SomethingA1);
					mj.Property(x => x.SomethingA2);
				});
				map.Join("MyClassSplit2", mj =>
				{
					mj.Property(x => x.SomethingB1);
					mj.Property(x => x.SomethingB2);
				});
				map.Property(x => x.Something0);
			});

			inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit1", For<Inherited>.Property(x => x.Something0)).Should().Be.False();
			inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit2", For<Inherited>.Property(x => x.Something0)).Should().Be.False();

			inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit1", For<Inherited>.Property(x => x.SomethingA1)).Should().Be.True();
			inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit1", For<Inherited>.Property(x => x.SomethingA2)).Should().Be.True();
			inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit2", For<Inherited>.Property(x => x.SomethingB1)).Should().Be.True();
			inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit2", For<Inherited>.Property(x => x.SomethingB2)).Should().Be.True();
		}
		public void WhenRegisteredAsComponetThenCantRegisterAsRootEntity()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsComponent(typeof(MyComponent));

			Assert.That(() => inspector.AddAsRootEntity(typeof(MyComponent)), Throws.TypeOf<MappingException>());
		}
		public void WhenMapSplittedPropertiesThenEachPropertyIsInItsSplitGroup()
		{
			var inspector = new ExplicitlyDeclaredModel();
			var mapper = new ModelMapper(inspector);
			mapper.Class<MyClass>(map =>
			{
				map.Id(x => x.Id, idmap => { });
				map.Join("MyClassSplit1", mj =>
				{
					mj.Property(x => x.SomethingA1);
					mj.Property(x => x.SomethingA2);
				});
				map.Join("MyClassSplit2", mj =>
				{
					mj.Property(x => x.SomethingB1);
					mj.Property(x => x.SomethingB2);
				});
				map.Property(x => x.Something0);
			});
			var hbmDoc = mapper.CompileMappingFor(new[] { typeof(MyClass) });

			var hbmClass = hbmDoc.RootClasses[0];
			Assert.That(hbmClass.Joins.Select(j => j.table), Is.EquivalentTo(new [] {"MyClassSplit1", "MyClassSplit2"}));
			Assert.That(hbmClass.Properties.Single().Name, Is.EqualTo("Something0"));
			var hbmSplit1 = hbmClass.Joins.Single(j => "MyClassSplit1" == j.table);
			Assert.That(hbmSplit1.Properties.Select(p => p.Name), Is.EquivalentTo(new [] {"SomethingA1", "SomethingA2"}));
			var hbmSplit2 = hbmClass.Joins.Single(j => "MyClassSplit2" == j.table);
			Assert.That(hbmSplit2.Properties.Select(p => p.Name), Is.EquivalentTo(new [] {"SomethingB1", "SomethingB2"}));
		}
		public void WhenRegisteredAsComponetThenCantRegisterAsUnionSubclass()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsComponent(typeof(MyComponent));

			inspector.Executing(x => x.AddAsTablePerConcreteClassEntity(typeof(MyComponent))).Throws<MappingException>();
		}
		public void WhenRegisteredAsRootThenDoesNotRegisterTheStrategy()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsRootEntity(typeof(MyClass));
			inspector.IsTablePerClass(typeof(MyClass)).Should().Be.False();
			inspector.IsTablePerClassHierarchy(typeof(MyClass)).Should().Be.False();
			inspector.IsTablePerConcreteClass(typeof(MyClass)).Should().Be.False();
		}
		public void WhenRegisteredAsSubclassThenIsEntity()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsRootEntity(typeof(MyClass));
			inspector.AddAsTablePerClassHierarchyEntity(typeof(Inherited1));

			Assert.That(inspector.IsEntity(typeof(Inherited1)), Is.True);
		}
		public void WhenRegisteredAsSubclassThenCantRegisterAsUnionSubclass()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsRootEntity(typeof(MyClass));
			inspector.AddAsTablePerClassHierarchyEntity(typeof(Inherited1));

			inspector.Executing(x => x.AddAsTablePerConcreteClassEntity(typeof(Inherited1))).Throws<MappingException>();
		}
		public void WhenRegisterUnionSubclassBeforeRootThenIsRegistered()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsTablePerConcreteClassEntity(typeof(Inherited1));

			inspector.AddAsRootEntity(typeof(MyClass));
			Assert.That(inspector.IsTablePerConcreteClass(typeof(Inherited1)), Is.True);
		}
Ejemplo n.º 17
0
		public void WhenPropertyUsedAsPoidThenRegister()
		{
			var inspector = new ExplicitlyDeclaredModel();
			var mapper = new ModelMapper(inspector);
			mapper.Class<MyClass>(map => map.Id(x => x.Id, idmap => { }));

			Assert.That(inspector.IsPersistentId(For<MyClass>.Property(x => x.Id)), Is.True);
		}
		public void WhenRegisteredAsJoinedSubclassThenIsEntity()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsRootEntity(typeof(MyClass));
			inspector.AddAsTablePerClassEntity(typeof(Inherited1));

			inspector.IsEntity(typeof(Inherited1)).Should().Be.True();
		}
		public void WhenRegisterSubclassBeforeRootThenIsRegistered()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsTablePerClassHierarchyEntity(typeof(Inherited1));

			inspector.AddAsRootEntity(typeof(MyClass));
			inspector.IsTablePerClassHierarchy(typeof(Inherited1)).Should().Be.True();
		}
		public void WhenRegisteredSubclassThenTheStrategyIsDefinedEvenForRoot()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsRootEntity(typeof(MyClass));
			inspector.AddAsTablePerClassHierarchyEntity(typeof(Inherited1));
			inspector.IsTablePerClass(typeof(MyClass)).Should().Be.False();
			inspector.IsTablePerClassHierarchy(typeof(MyClass)).Should().Be.True();
			inspector.IsTablePerConcreteClass(typeof(MyClass)).Should().Be.False();
		}
		public void WhenRegisteredJoinedDeepSubclassThenTheStrategyIsDefinedEvenForRoot()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsRootEntity(typeof(MyClass));
			inspector.AddAsTablePerClassEntity(typeof(Inherited2));
			Assert.That(inspector.IsTablePerClass(typeof(MyClass)), Is.True);
			Assert.That(inspector.IsTablePerClassHierarchy(typeof(MyClass)), Is.False);
			Assert.That(inspector.IsTablePerConcreteClass(typeof(MyClass)), Is.False);
		}
		public void WhenRegisterPropertySplitsThenTypeHasSplitGroups()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsPropertySplit(new SplitDefinition(typeof(MyClass), "group", For<MyClass>.Property(x => x.Something)));
			inspector.AddAsPropertySplit(new SplitDefinition(typeof(Inherited), "group1", For<Inherited>.Property(x => x.SomethingElse)));

			inspector.GetSplitGroupsFor(typeof(MyClass)).Should().Have.SameValuesAs("group");
			inspector.GetSplitGroupsFor(typeof(Inherited)).Should().Have.SameValuesAs("group1");
		}
		public void WhenRegisterPropertySplitsThenTypeHasSplitGroups()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsPropertySplit(new SplitDefinition(typeof(MyClass), "group", For<MyClass>.Property(x => x.Something)));
			inspector.AddAsPropertySplit(new SplitDefinition(typeof(Inherited), "group1", For<Inherited>.Property(x => x.SomethingElse)));

			Assert.That(inspector.GetSplitGroupsFor(typeof(MyClass)), Is.EquivalentTo(new [] {"group"}));
			Assert.That(inspector.GetSplitGroupsFor(typeof(Inherited)), Is.EquivalentTo(new [] {"group1"}));
		}
		public void WhenRegisteredAsDeppJoinedSubclassThenIsRegistered()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsRootEntity(typeof(MyClass));
			inspector.AddAsTablePerClassEntity(typeof(Inherited2));

			inspector.IsTablePerClass(typeof(Inherited2)).Should().Be.True();
			inspector.IsTablePerClassHierarchy(typeof(Inherited2)).Should().Be.False();
			inspector.IsTablePerConcreteClass(typeof(Inherited2)).Should().Be.False();
		}
		public void WhenPropertyUsedAsComposedIdThenRegister()
		{
			var inspector = new ExplicitlyDeclaredModel();
			var mapper = new ModelMapper(inspector);
			mapper.Class<MyClass>(map => map.ComponentAsId(x => x.Id));

			inspector.IsPersistentId(For<MyClass>.Property(x => x.Id)).Should().Be.True();
			inspector.IsPersistentProperty(For<MyClass>.Property(x => x.Id)).Should().Be.True();
			inspector.IsComponent(typeof(IMyCompo)).Should().Be.True();
		}
		public void WhenRegisteredAsDeepUnionSubclassThenIsRegistered()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsRootEntity(typeof(MyClass));
			inspector.AddAsTablePerConcreteClassEntity(typeof(Inherited2));

			Assert.That(inspector.IsTablePerClass(typeof(Inherited2)), Is.False);
			Assert.That(inspector.IsTablePerClassHierarchy(typeof(Inherited2)), Is.False);
			Assert.That(inspector.IsTablePerConcreteClass(typeof(Inherited2)), Is.True);
		}
		public void WhenRegisteredAsComponetThenCantRegisterAsUnionSubclass()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsComponent(typeof (MyComponent));

			Assert.That(() =>
			{
				inspector.AddAsTablePerConcreteClassEntity(typeof (MyComponent));
				inspector.IsTablePerConcreteClass(typeof (MyComponent));
			}, Throws.TypeOf<MappingException>());
		}
		public void WhenRegisteredAsComponetThenCantRegisterAsUnionSubclass()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsComponent(typeof (MyComponent));

			Executing.This(() =>
			               {
			               	inspector.AddAsTablePerConcreteClassEntity(typeof (MyComponent));
			               	inspector.IsTablePerConcreteClass(typeof (MyComponent));
			               }).Should().Throw<MappingException>();
		}
		public void WhenRegisteredAsJoinedSubclassThenCantRegisterAsUnionSubclass()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsRootEntity(typeof (MyClass));
			inspector.AddAsTablePerClassEntity(typeof (Inherited1));

			Executing.This(() =>
			               {
			               	inspector.AddAsTablePerConcreteClassEntity(typeof (Inherited1));
			               	inspector.IsTablePerClass(typeof (Inherited1));
			               }).Should().Throw<MappingException>();
		}
		public void WhenRegisteredAsJoinedSubclassThenCantRegisterAsUnionSubclass()
		{
			var inspector = new ExplicitlyDeclaredModel();
			inspector.AddAsRootEntity(typeof (MyClass));
			inspector.AddAsTablePerClassEntity(typeof (Inherited1));

			Assert.That(() =>
			{
				inspector.AddAsTablePerConcreteClassEntity(typeof (Inherited1));
				inspector.IsTablePerClass(typeof (Inherited1));
			}, Throws.TypeOf<MappingException>());
		}