Пример #1
0
        public void ChangeParent_When_New_Parent_Is_Null()
        {
            Project parent = new Project();
            Project child_1 = new Project();
            parent.AddChild(child_1);

            child_1.ChangeParent(null);
            Assert.That(child_1.Parent, Is.EqualTo(null));
            Assert.That(parent.Children.Count, Is.EqualTo(0));
        }
Пример #2
0
 public virtual void ChangeParent(Project newParent)
 {
     if (this.Parent != newParent)
     {
         if (this.Parent == null)
         {
             newParent.AddChild(this);
         }
         else
         {
             this.Parent.RemoveChild(this);
             if (newParent != null)
             {
                 newParent.AddChild(this);
             }
         }
     }
 }
Пример #3
0
        public void ChangeParent_When_New_Parent_Is_Old_Parent()
        {
            Project parent = new Project();
            Project child_1 = new Project();
            Project child_2 = new Project();
            parent.AddChild(child_1);
            parent.AddChild(child_2);

            child_1.ChangeParent(parent);
            Assert.That(child_1.Parent, Is.EqualTo(parent));
            Assert.That(child_2.Parent, Is.EqualTo(parent));
            Assert.That(parent.Children.Count, Is.EqualTo(2));
            Assert.That(parent.Children.Contains(child_1));
            Assert.That(parent.Children.Contains(child_2));
        }
Пример #4
0
        public void ChangeParent()
        {
            Project parent_1 = new Project();
            Project parent_2 = new Project();
            Project child = new Project();

            parent_1.AddChild(child);
            Assert.That(child.Parent, Is.EqualTo(parent_1));
            Assert.That(parent_1.Children.Count, Is.EqualTo(1));
            Assert.That(parent_1.Children.Contains(child));

            child.ChangeParent(parent_2);
            Assert.That(child.Parent, Is.EqualTo(parent_2));
            Assert.That(parent_1.Children.IsNullOrEmpty(), Is.True);
            Assert.That(parent_2.Children.Count, Is.EqualTo(1));
            Assert.That(parent_2.Children.Contains(child));
        }
Пример #5
0
        public void RemoveChild()
        {
            Project parent = new Project();
            Project child_1 = new Project();
            Project child_2 = new Project();

            parent.AddChild(child_1);
            parent.AddChild(child_2);

            parent.RemoveChild(child_1);

            Assert.That(parent.Children.Count, Is.EqualTo(1));
            Assert.That(parent.Children.Contains(child_2));
            Assert.That(child_1.Parent, Is.Null);
        }
Пример #6
0
        public void IsOffspring()
        {
            Project child_1 = new Project();
            Project child_2 = new Project();
            Project parent_1 = new Project();
            Project parent_2 = new Project();
            Project grand_parent = new Project();

            Project other = new Project();

            parent_1.AddChild(child_1);
            parent_1.AddChild(child_2);
            grand_parent.AddChild(parent_1);
            grand_parent.AddChild(parent_2);

            Assert.That(child_1.IsOffspring(parent_1), Is.True);
            Assert.That(child_2.IsOffspring(parent_1), Is.True);
            Assert.That(parent_1.IsOffspring(parent_1), Is.False);
            Assert.That(parent_2.IsOffspring(parent_1), Is.False);
            Assert.That(grand_parent.IsOffspring(parent_1), Is.False);
            Assert.That(other.IsOffspring(parent_1), Is.False);

            Assert.That(child_1.IsOffspring(parent_2), Is.False);
            Assert.That(child_2.IsOffspring(parent_2), Is.False);
            Assert.That(parent_1.IsOffspring(parent_2), Is.False);
            Assert.That(parent_2.IsOffspring(parent_2), Is.False);
            Assert.That(grand_parent.IsOffspring(parent_1), Is.False);
            Assert.That(other.IsOffspring(parent_1), Is.False);

            Assert.That(child_1.IsOffspring(grand_parent), Is.True);
            Assert.That(child_2.IsOffspring(grand_parent), Is.True);
            Assert.That(parent_1.IsOffspring(grand_parent), Is.True);
            Assert.That(parent_2.IsOffspring(grand_parent), Is.True);
            Assert.That(grand_parent.IsOffspring(grand_parent), Is.False);
            Assert.That(other.IsOffspring(grand_parent), Is.False);
        }
Пример #7
0
        public void Setup()
        {
            User zyfei = new User { Name = "自由飞" };
            authorization_1 = new Authorization
            {
                User = zyfei,
                IsAdmin = true,
                IsFounder = true,
                IsPublisher = false,
                IsOwner = false
            };
            zyfei.Authorizations = new List<Authorization> { authorization_1 };

            User yongbaosijie = new User { Name = "拥抱世界" };
            authorization_2 = new Authorization
            {
                User = yongbaosijie,
                IsAdmin = false,
                IsFounder = false,
                IsPublisher = true,
                IsOwner = false
                //TODO: not define the Project, OK?
            };
            yongbaosijie.Authorizations = new List<Authorization> { authorization_2 };

            User jishuzai = new User { Name = "技术宅" };
            authorization_3 = new Authorization
            {
                User = jishuzai,
                IsAdmin = false,
                IsFounder = false,
                IsPublisher = true,
                IsOwner = false
            };
            jishuzai.Authorizations = new List<Authorization> { authorization_3 };

            User kejigaibianshenghou = new User { Name = "科技改变生活" };
            authorization_4 = new Authorization
            {
                User = kejigaibianshenghou,
                IsAdmin = false,
                IsFounder = false,
                IsPublisher = false,
                IsOwner = false
            };
            kejigaibianshenghou.Authorizations = new List<Authorization> { authorization_4 };

            authorizations = new List<Authorization>
            {
                authorization_1,authorization_2,authorization_3,authorization_4
            };

            project_1 = new Project();
            project_1.MockId(1);
            project_1.Name = "创业家园";
            project_1.Description = "创业者的心灵家园";

            project_2 = new Project();
            project_2.MockId(2);
            project_2.Name = "前台";
            project_2.Description = "负责页面";

            project_3 = new Project();
            project_3.MockId(3);
            project_3.Name = "后台";
            project_3.Description = "负责业务流程";

            project_4 = new Project();
            project_4.MockId(4);
            project_4.Name = "文档";
            project_4.Description = "负责文档的编写";

            project_5 = new Project();
            project_5.MockId(5);
            project_5.Name = "任务管理";
            project_5.Description = "任务的分配承接的系统";

            project_6 = new Project();
            project_6.MockId(6);
            project_6.Name = "前台";
            project_6.Description = "负责页面";

            project_7 = new Project();
            project_7.MockId(7);
            project_7.Name = "后台";
            project_7.Description = "负责业务流程";

            project_1.AddChild(project_2);
            project_1.AddChild(project_3);
            project_1.AddChild(project_4);

            project_5.AddChild(project_6);
            project_5.AddChild(project_7);

            project = new Project
            {
                Children = new List<Project> { project_1, project_5 },
                Name = "自由飞任务管理系统",
                Description = null,
                Authorizations = authorizations
            };
            project_1.Authorizations = authorizations;
            project_2.Authorizations = authorizations;
            project_5.Authorizations = authorizations;
        }