示例#1
0
        public void Initialize()
        {
            p1 = new Principal(nameof(p1));
            p2 = new Principal(nameof(p2));

            //Hierarchy from Myers2000 - Figure 3
            carl    = new Principal(nameof(carl));
            manager = new Principal(nameof(manager));
            doctor  = new Principal(nameof(doctor));
            bob     = new Principal(nameof(bob));
            amy     = new Principal(nameof(amy));
            group   = new Principal(nameof(group));

            carl.AddSubordinate(manager);
            carl.AddSubordinate(doctor);
            manager.AddSubordinate(bob);
            manager.AddSubordinate(amy);
            bob.AddSubordinate(group);
            amy.AddSubordinate(group);
        }
示例#2
0
 public void AddSubordinateTest()
 {
     Assert.True(p1.AddSubordinate(p2), $"{p1.Name} can have {p2.Name} added as a subordinate as it doesn't already have it.");
     Assert.False(p1.AddSubordinate(p2), $"{p1.Name} cannot have {p2.Name} added as a subordinate, because it already has it.");
     var ex = Assert.Throws <PrincipalCircularDependencyException>(() => p2.AddSubordinate(p1), $"{p2.Name} cannot have {p2.Name} added as a subordinate, because it would cause a circular dependency");
 }