コード例 #1
0
        static void Main(string[] args)
        {
            //SetUp
            Storage  s = new Storage();
            Commands c = new Commands(s);
            Queries  q = new Queries(s);

            var shad = new Models.Person {
                Email = "*****@*****.**", DNVGLID = Guid.NewGuid().ToString(), Id = 1, Name = "Shad"
            };
            var anatoliy = new Models.Person {
                Email = "*****@*****.**", DNVGLID = Guid.NewGuid().ToString(), Id = 2, Name = "Anatoliy"
            };
            var s1 = new Models.Container {
                Id = 1, Name = "ship_01", ResourceId = Guid.NewGuid().ToString()
            };
            var s2 = new Models.Container {
                Id = 2, Name = "ship_02", ResourceId = Guid.NewGuid().ToString()
            };


            c.AddUser(shad);
            c.AddUser(anatoliy);

            c.AddContainer(s1);
            c.AddContainer(s2);

            //Add all ships containers to container grouping ships
            var cg1 = new Models.ContainerGroup {
                Id = 1, name = "ships", ContainerInGroup = new List <Models.Container>()
            };

            c.AddContainerToContainerGroup(s1, cg1);
            c.AddContainerToContainerGroup(s2, cg1);


            //Create user groups to access ships
            var ug1 = new Models.UserGroup {
                Id = 1, name = "readers of ships", PersonInGroup = new List <Models.Person>()
            };
            var ug2 = new Models.UserGroup {
                Id = 2, name = "admin of ships", PersonInGroup = new List <Models.Person>()
            };


            //Add users to a user group
            c.AddPersonToUserGroup(shad, ug1);
            c.AddPersonToUserGroup(shad, ug2);
            c.AddPersonToUserGroup(anatoliy, ug2);

            //Give access to ship
            c.AddContainerGroupToUserGroup(cg1, ug1);
            c.AddContainerGroupToUserGroup(cg1, ug2);

            //Which group has access?
            var o = q.getListOfUserGroupsWithAcessToContainerGroup(cg1);


            Console.WriteLine($"Which group has access to {cg1.name}");
            Console.WriteLine(o.Count);
            foreach (var aa in o)
            {
                Console.WriteLine(aa.name);

                Console.WriteLine("whos in that group?");
                var p = q.getListOfPeapleInGroupQuery(aa);
                foreach (var pp in p)
                {
                    Console.WriteLine(pp.Name);
                }
            }

            Console.WriteLine($"-------------------------");
            Console.WriteLine($"Removing user group {ug1.name} access from container group {cg1.name}");
            //Remove access
            c.RemoveContainerGroupFromUserGroup(cg1, ug1);
            //Which group has access?
            o = q.getListOfUserGroupsWithAcessToContainerGroup(cg1);

            Console.WriteLine($"Which group has access to {cg1.name}");
            Console.WriteLine(o.Count);
            foreach (var aa in o)
            {
                Console.WriteLine(aa.name);

                Console.WriteLine("whos in that group?");
                var p = q.getListOfPeapleInGroupQuery(aa);
                foreach (var pp in p)
                {
                    Console.WriteLine(pp.Name);
                }
            }

            Console.Read();
        }