public void ValidateRoleConstraint_SuccessTest() { var husbandCanBePersonOnly = new PartyRoleConstraint(typeof(Person)); var husbandType = new PartyRoleType("Husband"); husbandType.AddConstraint(husbandCanBePersonOnly); var husbandRole = new PartyRole(husbandType); var whifeCanBePersonOnly = new PartyRoleConstraint(typeof(Person)); var whifeType = new PartyRoleType("Whife"); whifeType.AddConstraint(whifeCanBePersonOnly); var whifeRole = new PartyRole(whifeType); var familyRelationshipTyp = new PartyRelationshipType("Family"); var famalyCanHasHusband = new PartyRelationshipConstraint(husbandType); familyRelationshipTyp.AddConstraint(famalyCanHasHusband); var famalyCanHasWhife = new PartyRelationshipConstraint(whifeType); familyRelationshipTyp.AddConstraint(famalyCanHasWhife); var familyRelationship = new PartyRelationship(familyRelationshipTyp); familyRelationship.AddRole(husbandRole); familyRelationship.AddRole(whifeRole); Assert.AreEqual(2, familyRelationship.Roles.Count()); Assert.AreEqual(1, husbandRole.Type.RoleConstraints.Count()); Assert.AreEqual(0, husbandRole.Type.Rules.Count()); Assert.AreEqual(2, familyRelationship.Roles.Count()); Assert.AreEqual(1, whifeRole.Type.RoleConstraints.Count()); Assert.AreEqual(0, whifeRole.Type.Rules.Count()); var john = new Person() { Birthdate = new DateTime(1972, 11, 4) }; familyRelationship.Assign(husbandRole, john); var marry = new Person() { Birthdate = new DateTime(1976, 4, 16) }; familyRelationship.Assign(whifeRole, marry); Assert.AreEqual(2, familyRelationship.Roles.Count()); Assert.AreEqual(1, familyRelationship.GetRoles(john).Count()); Assert.AreEqual(1, familyRelationship.GetRoles(marry).Count()); }
public void AddRightRoleIntoRelationship_FailTest() { var husbandType = new PartyRoleType("Husband"); var husbandRole = new PartyRole(husbandType); var whifeType = new PartyRoleType("Whife"); var whifeRole = new PartyRole(whifeType); var familyRelationshipTyp = new PartyRelationshipType("Family"); var famalyCanHasHusband = new PartyRelationshipConstraint(husbandType); familyRelationshipTyp.AddConstraint(famalyCanHasHusband); var famalyCanHasWhife = new PartyRelationshipConstraint(whifeType); familyRelationshipTyp.AddConstraint(famalyCanHasWhife); var familyRelationship = new PartyRelationship(familyRelationshipTyp); familyRelationship.AddRole(husbandRole); familyRelationship.AddRole(whifeRole); var john = new Person() { Birthdate = new DateTime(1972, 11, 4) }; familyRelationship.Assign(husbandRole, john); var marry = new Person() { Birthdate = new DateTime(1976, 4, 16) }; familyRelationship.Assign(whifeRole, marry); Assert.AreEqual(2, familyRelationship.Roles.Count()); Assert.AreEqual(1, familyRelationship.GetRoles(john).Count()); Assert.AreEqual(1, familyRelationship.GetRoles(marry).Count()); }
public void ValidateEntityValueConstraine_SuccessTest() { var husbandType = new PartyRoleType("Husband"); var husbendMustBeOlderThen18 = new RuleSet(new Func <object, bool>((x) => { var person = x as Person; if (person.Age > 18) { return(true); } else { return(false); } })); husbandType.AddRule(husbendMustBeOlderThen18); var husbandRole = new PartyRole(husbandType); var whifeType = new PartyRoleType("Whife"); var whifeMustBeOlderThen16 = new RuleSet(new Func <object, bool>((x) => { var person = x as Person; if (person.Age > 16) { return(true); } else { return(false); } })); whifeType.AddRule(whifeMustBeOlderThen16); var whifeRole = new PartyRole(whifeType); var childrenType = new PartyRoleType("Children"); var childrenMustBeYangerThenParents = new RuleSet(new Func <object, bool>((x) => { return(true); })); childrenType.AddRule(childrenMustBeYangerThenParents); var childrenRole = new PartyRole(childrenType); var familyRelationshipTyp = new PartyRelationshipType("Family"); var famalyCanHasHusband = new PartyRelationshipConstraint(husbandType); familyRelationshipTyp.AddConstraint(famalyCanHasHusband); var famalyCanHasWhife = new PartyRelationshipConstraint(whifeType); familyRelationshipTyp.AddConstraint(famalyCanHasWhife); var famalyCanHasChildren = new PartyRelationshipConstraint(childrenType); familyRelationshipTyp.AddConstraint(famalyCanHasChildren); var familyRelationship = new PartyRelationship(familyRelationshipTyp); familyRelationship.AddRole(husbandRole); familyRelationship.AddRole(whifeRole); familyRelationship.AddRole(childrenRole); Assert.AreEqual(3, familyRelationship.Roles.Count()); Assert.AreEqual(1, husbandRole.Type.Rules.Count()); Assert.AreEqual(3, familyRelationship.Roles.Count()); Assert.AreEqual(1, whifeRole.Type.Rules.Count()); Assert.AreEqual(3, familyRelationship.Roles.Count()); Assert.AreEqual(1, childrenRole.Type.Rules.Count()); var john = new Person() { Birthdate = new DateTime(1972, 11, 4) }; familyRelationship.Assign(husbandRole, john); var marry = new Person() { Birthdate = new DateTime(1976, 4, 16) }; familyRelationship.Assign(whifeRole, marry); var gimmy = new Person() { Birthdate = new DateTime(1996, 4, 16) }; familyRelationship.Assign(childrenRole, gimmy); Assert.AreEqual(3, familyRelationship.Roles.Count()); Assert.AreEqual(1, familyRelationship.GetRoles(john).Count()); Assert.AreEqual(1, familyRelationship.GetRoles(marry).Count()); Assert.AreEqual(1, familyRelationship.GetRoles(gimmy).Count()); }