public void AddSameRoleIntoRelationship_FailTest() { var husbandType = new PartyRoleType("Husband"); var husbandRole = new PartyRole(husbandType); var familyRelationshipType = new PartyRelationshipType("Family"); var famalyCanHasHusband = new PartyRelationshipConstraint(husbandType); familyRelationshipType.AddConstraint(famalyCanHasHusband); var familyCanHaveOnlyOneHusband = new PartyRelationshipConstraint(familyRelationshipType, new Func <PartyRelationship, PartyRole, bool>((relationship, role) => { var c = relationship.Roles.Count(r => r.Id == role.Id); if (c == 0) { return(true); } else { return(false); } })); familyRelationshipType.AddConstraint(familyCanHaveOnlyOneHusband); var familyRelationship = new PartyRelationship(familyRelationshipType); familyRelationship.AddRole(husbandRole); familyRelationship.AddRole(husbandRole); }
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 AddCustomer_SuccessTest() { var customerRoleType = new PartyRoleType("Customer"); var customerRole = new PartyRole(customerRoleType); var customerRelationshipType = new PartyRelationshipType("Customers relationship"); var customerRelationship = new PartyRelationship(customerRelationshipType); customerRelationship.AddRole(customerRole); var vlad = new Person(); customerRelationship.Assign(customerRole, vlad); var ilona = new Person(); customerRelationship.Assign(customerRole, ilona); }
public void AddWrongRoleIntoRelationship_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); var familyRelationshipType2 = new PartyRelationshipType("Family2"); var familyRelationship2 = new PartyRelationship(familyRelationshipType2); familyRelationship2.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); }
public void AddCommunications_SuccessTest() { var customerRoleType = new PartyRoleType("Customer"); var customerRole = new PartyRole(customerRoleType); var customerRelationshipType = new PartyRelationshipType("Customers relationship"); var customerRelationship = new PartyRelationship(customerRelationshipType); customerRelationship.AddRole(customerRole); var vlad = new Person(); customerRelationship.Assign(customerRole, vlad); var ilona = new Person(); customerRelationship.Assign(customerRole, ilona); var customerServiceRepresentativeRoleType = new PartyRoleType("CustomerServiceRepresentative"); var customerServiceRepresentativeRole = new PartyRole(customerServiceRepresentativeRoleType); var communicationRelationshipType = new PartyRelationshipType("Communication relationship"); var communicationRelationship = new Communication(communicationRelationshipType); communicationRelationship.AddRole(customerServiceRepresentativeRole); communicationRelationship.Assign(customerServiceRepresentativeRole, vlad); communicationRelationship.Assign(customerServiceRepresentativeRole, ilona); var customerCommunicationManager = new CustomerCommunicationManager(); var customerServiceCase = new CustomerServiceCase(new CustomerServiceCaseIdentifier(Guid.NewGuid())); customerCommunicationManager.AddCustomerServiceCases(customerServiceCase); var thread1 = new CommunicationThread(); customerServiceCase.AddThread(thread1); var communication = new Communication(communicationRelationshipType); thread1.AddCommunication(communicationRelationship); }
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()); }