public void TestLoadSimpleKey() { IKeyDef def = _xmlKeyLoader.LoadKey(@"<key><prop name=""TestProp"" /></key>", _propDefCol); Assert.AreEqual(1, def.Count); Assert.IsFalse(def.IgnoreIfNull); }
public void Test_CreateClassDef_WithUniqueConstraint_WithKeyName_ShouldBuildKeyDefWithKeyName() { //---------------Set up test pack------------------- string propertyName1 = "A" + GetRandomString(); string propertyName2 = "B" + GetRandomString(); string keyName = "K" + GetRandomString(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var classDefBuilder = GetClassDefBuilderForTypeOf_Car(); var classDef = classDefBuilder .WithPrimaryKey(car => car.VehicleID) .WithProperties() .Property <int>(propertyName1).EndProperty() .Property(propertyName2).EndProperty() .EndProperties() .WithUniqueConstraints() .UniqueConstraint(keyName).EndUniqueConstraint() .EndUniqueConstraints() .Build(); //---------------Test Result ----------------------- Assert.AreEqual(1, classDef.PrimaryKeyDef.Count); //PrimaryKey is required Assert.AreEqual(1, classDef.KeysCol.Count); //Should Be Empty IKeyDef keyDef = classDef.KeysCol.FirstOrDefault(); Assert.AreEqual(keyName, keyDef.KeyName); }
public void TestLoadKeyWithIgnoreNulls() { IKeyDef def = _xmlKeyLoader.LoadKey(@"<key name=""Key1"" ignoreIfNull=""true""><prop name=""TestProp"" /></key>", _propDefCol); Assert.IsTrue(def.IgnoreIfNull); }
public virtual void TestLoadKeyWithMultipleProps_WithNoKeyName_UsesPropertyNames() { _propDefCol.Add(GetDefClassFactory().CreatePropDef("TestProp2", "System", "String", PropReadWriteRule.ReadWrite, null, null, false, false, 255, null, null, false)); IKeyDef def = _xmlKeyLoader.LoadKey( @"<key><prop name=""TestProp"" /><prop name=""TestProp2"" /></key>", _propDefCol); Assert.AreEqual("TestProp_TestProp2", def.KeyName); }
public void TestLoadKeyWithMultipleProps() { _propDefCol.Add(GetDefClassFactory().CreatePropDef("TestProp2", "System", "String", PropReadWriteRule.ReadWrite, null, null, false, false, 255, null, null, false)); IKeyDef def = _xmlKeyLoader.LoadKey( @"<key name=""Key1""><prop name=""TestProp"" /><prop name=""TestProp2"" /></key>", _propDefCol); Assert.AreEqual(2, def.Count); }
public void TestPropElementForNonExistingProp() { //This test was changed to not expect an exception anymore because the // prop could come from an inherited class. IKeyDef keyDef = _xmlKeyLoader.LoadKey(@" <key name=""Key1""> <prop name=""doesntexist"" /> </key>", _propDefCol); Assert.AreEqual(1, keyDef.Count); Assert.IsFalse(_propDefCol.Contains(keyDef["doesntexist"]), "A temporary propDef should have been created for this prop. This will be clarified later."); }
public void Test_Map_WhenOneUniqueConstraintOnRelationship_ShouldCreateConstraintOnRelationshipProperty() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Add(typeof(FakeBOWithNoRelationship).MapClass()); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var classDef = typeof(FakeBOWithUniqueConstraint_Relationship).MapClass(); //---------------Test Result ----------------------- Assert.AreEqual(1, classDef.KeysCol.Count); IKeyDef keyDef1 = classDef.KeysCol["UC"]; Assert.AreEqual(1, keyDef1.Count); Assert.AreSame(classDef.GetPropDef("RelatedObjectID"), keyDef1[0]); }
public void Test_Map_WhenHasUniqueConstraint_OneProp() { //---------------Set up test pack------------------- var type = typeof(FakeBOWithUniqueConstraint_OneProp); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var classDef = type.MapClass(); //---------------Test Result ----------------------- Assert.AreEqual(1, classDef.KeysCol.Count); IKeyDef keyDef = classDef.KeysCol["UC"]; Assert.IsNotNull(keyDef); Assert.AreEqual(1, keyDef.Count); Assert.AreEqual("UCProp", keyDef[0].PropertyName); }
public void Test_Map_WhenHasTwoUniqueConstraint_OnePropEach() { //---------------Set up test pack------------------- var type = typeof(FakeBOWithTwoUniqueConstraints_OnePropEach); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var classDef = type.MapClass(); //---------------Test Result ----------------------- Assert.AreEqual(2, classDef.KeysCol.Count); IKeyDef keyDef1 = classDef.KeysCol["UC1"]; IKeyDef keyDef2 = classDef.KeysCol["UC2"]; Assert.IsNotNull(keyDef1); Assert.IsNotNull(keyDef2); Assert.AreEqual(1, keyDef1.Count); Assert.AreEqual(1, keyDef2.Count); Assert.AreEqual("UCProp1", keyDef1[0].PropertyName); Assert.AreEqual("UCProp2", keyDef2[0].PropertyName); }
/// <summary> /// Loads the key name /// </summary> private void LoadKeyName() { string name = _reader.GetAttribute("name"); _keyDef = _defClassFactory.CreateKeyDef(name); }
public void CallRemove(IKeyDef keyDef) { Remove(keyDef); }