public void LoadingTest()
        {
            context.AccessLevel = EntityAccessLevel.Administrator;
            context.Execute("DELETE FROM pubserver;");
            context.Execute("DELETE FROM usr WHERE username IN ('user1', 'user2');");

            User user1 = new User(context);

            user1.Username = "******";
            user1.Store();

            User user2 = new User(context);

            user2.Username = "******";
            user2.Store();

            context.StartImpersonation(user1.Id);
            PublishServer p1 = new PublishServer(context);

            p1.Name     = "p1";
            p1.Protocol = "ftp";
            p1.Hostname = "test.org";
            p1.Store();
            PublishServer p2 = new PublishServer(context);

            p2.Name     = "p2";
            p2.Protocol = "ftp";
            p2.Hostname = "test.org";
            p2.Store();
            context.EndImpersonation();

            context.StartImpersonation(user2.Id);
            PublishServer p3 = new PublishServer(context);

            p3.Name     = "p3";
            p3.Protocol = "ftp";
            p3.Hostname = "test.org";
            p3.Store();
            context.EndImpersonation();

            context.StartImpersonation(user1.Id);
            EntityDictionary <PublishServer> pd1 = new EntityDictionary <PublishServer>(context);

            pd1.ItemVisibility = EntityItemVisibility.OwnedOnly;
            pd1.Load();
            Assert.AreEqual(2, pd1.Count);
            context.EndImpersonation();

            context.StartImpersonation(user2.Id);
            EntityDictionary <PublishServer> pd2 = new EntityDictionary <PublishServer>(context);

            Assert.Throws <EntityNotFoundException>(delegate {
                pd2.LoadFromSource(pd1, false);
            });

            pd2.LoadFromSource(pd1, true);
            Assert.AreEqual(2, pd2.Count);

            context.EndImpersonation();
        }
Exemple #2
0
#pragma warning disable RCS1163 // Unused parameter.
        private static void Main(string[] args)
#pragma warning restore RCS1163 // Unused parameter.
        {
            Console.WriteLine("Hello Server!");

            PublishServer publisher = new PublishServer();

            publisher.Publish();

            Console.ReadLine();
        }
        public void TotalResultsTest()
        {
            context.AccessLevel = EntityAccessLevel.Administrator;
            context.Execute("DELETE FROM pubserver;");

            PublishServer p1 = new PublishServer(context);

            p1.Name     = "pf1";
            p1.Protocol = "ftp";
            p1.Hostname = "test.org";
            p1.Port     = 23;
            p1.Store();
            PublishServer p2 = new PublishServer(context);

            p2.Name     = "pf2";
            p2.Protocol = "ftp";
            p2.Hostname = "anothertest.org";
            p2.Port     = 123;
            p2.Store();
            PublishServer p3 = new PublishServer(context);

            p3.Name     = "pf3";
            p3.Protocol = "sftp";
            p3.Hostname = "experiment.org";
            p3.Port     = 234;
            p3.Store();
            PublishServer p4 = new PublishServer(context);

            p4.Name     = "pf4";
            p4.Protocol = "sftp";
            p4.Hostname = "try.org";
            p4.Port     = 345;
            p4.Store();

            EntityDictionary <PublishServer> pd1 = new EntityDictionary <PublishServer>(context);

            pd1.SetFilter("Protocol", "sftp");
            pd1.Load();
            Assert.AreEqual(2, pd1.Count);
            Assert.AreEqual(2, pd1.TotalResults); // filtered

            EntityDictionary <PublishServer> pd2 = new EntityDictionary <PublishServer>(context);

            pd2.ItemsPerPage = 3;
            pd2.Load();
            Assert.AreEqual(3, pd2.Count);
            Assert.AreEqual(4, pd2.TotalResults); // all
        }
        public void GroupFilterTest()
        {
            context.AccessLevel = EntityAccessLevel.Administrator;
            context.Execute("DELETE FROM pubserver;");

            PublishServer p1 = new PublishServer(context);

            p1.Name        = "pf1";
            p1.Protocol    = "ftp";
            p1.Hostname    = "test.org";
            p1.Port        = 23;
            p1.FileRootDir = "/dir1";
            p1.Store();
            PublishServer p2 = new PublishServer(context);

            p2.Name        = "pf1";
            p2.Protocol    = "ftp";
            p2.Hostname    = "anothertest.org";
            p2.Port        = 123;
            p2.FileRootDir = "/dir2";
            p2.Store();
            PublishServer p3a = new PublishServer(context);

            p3a.Name     = "pf3";
            p3a.Protocol = "ftp";
            p3a.Hostname = "experiment.org";
            p3a.Port     = 234;
            p3a.Store();

            EntityDictionary <PublishServer> pd1 = new EntityDictionary <PublishServer>(context);

            pd1.Load();
            Assert.AreEqual(3, pd1.TotalResults);
            Assert.AreEqual(3, pd1.Count);

            EntityDictionary <PublishServer> pd2 = new EntityDictionary <PublishServer>(context);

            context.ConsoleDebug = true;
            pd2.SetGroupFilter("Name");
            pd2.Load();
            Assert.AreEqual(2, pd2.TotalResults);
            Assert.AreEqual(2, pd2.Count);
        }
Exemple #5
0
        public void _CreateData()
        {
            try {
                if (rebuildData)
                {
                    context.AccessLevel = EntityAccessLevel.Administrator;

                    domain1            = new Domain(context);
                    domain1.Identifier = "domain-1";
                    domain1.Name       = "domain-1";
                    domain1.Store();

                    domain2            = new Domain(context);
                    domain2.Identifier = "domain-2";
                    domain2.Name       = "domain-2";
                    domain2.Store();

                    user0            = new User(context);
                    user0.Identifier = "user-0";
                    user0.Store();

                    user11            = new User(context);
                    user11.Identifier = "domain-1_cr_viewer+changer";
                    user11.Store();

                    user12            = new User(context);
                    user12.Identifier = "domain-1_cr_viewer+changer+deleter";
                    user12.Store();

                    user21            = new User(context);
                    user21.Identifier = "global_cr_deleter";
                    user21.Store();

                    group1            = new Group(context);
                    group1.Identifier = "domain-1_cr_viewers+changers";
                    group1.Store();
                    group1.AssignUsers(new int[] { user11.Id, user12.Id });

                    group2            = new Group(context);
                    group2.Identifier = "global_cr_deleters";
                    group2.Store();
                    group2.AssignUsers(new int[] { user21.Id });

                    user31            = new User(context);
                    user31.Identifier = "global_service_admin";
                    user31.Store();

                    role1            = new Role(context);
                    role1.Identifier = "cr_view+change";
                    role1.Store();
                    role1.IncludePrivileges(Privilege.Get(EntityType.GetEntityType(typeof(ComputingResource)), new EntityOperationType[] { EntityOperationType.Search, EntityOperationType.View, EntityOperationType.Change }));
                    role1.GrantToGroups(new int[] { group1.Id }, domain1.Id);

                    role2            = new Role(context);
                    role2.Identifier = "cr_delete";
                    role2.Store();
                    role2.IncludePrivilege(Privilege.Get(EntityType.GetEntityType(typeof(ComputingResource)), EntityOperationType.Delete));
                    role2.GrantToUsers(new int[] { user12.Id }, domain1.Id);
                    role2.GrantToGroups(new int[] { group2.Id }, 0);

                    role3            = new Role(context);
                    role3.Identifier = "service_all";
                    role3.Store();
                    role3.IncludePrivileges(Privilege.Get(EntityType.GetEntityType(typeof(Service))));
                    role3.GrantToUsers(new int[] { user31.Id }, 0);

                    ComputingResource cr1 = new GenericComputingResource(context);
                    cr1.Identifier = "cr-1";
                    cr1.Name       = "cr-1";
                    cr1.Domain     = domain1;
                    cr1.Store();
                    cr1.GrantPermissionsToUsers(new int[] { user12.Id });

                    PublishServer ps1 = new PublishServer(context);
                    ps1.Identifier = "ps-1";
                    ps1.Name       = "ps-1";
                    ps1.Hostname   = "mytest.host";
                    ps1.Domain     = domain1;
                    ps1.Protocol   = "http";
                    ps1.Store();

                    seriesShareDomain            = new Domain(context);
                    seriesShareDomain.Identifier = "series-share";
                    seriesShareDomain.Name       = "series-share";
                    seriesShareDomain.Store();

                    shareCreator            = new User(context);
                    shareCreator.Identifier = "share-creator";
                    shareCreator.Store();
                    shareReceiver            = new User(context);
                    shareReceiver.Identifier = "share-receiver";
                    shareReceiver.Store();

                    context.StartImpersonation(shareCreator.Id);
                    sharedSeries            = new Series(context);
                    sharedSeries.Identifier = "shared-series";
                    sharedSeries.Store();
                    sharedSeries.GrantPermissionsToUsers(new int[] { shareReceiver.Id });
                    unsharedSeries            = new Series(context);
                    unsharedSeries.Domain     = seriesShareDomain;
                    unsharedSeries.Identifier = "unshared-series";
                    unsharedSeries.Store();
                    context.EndImpersonation();

                    seriesShareRole            = new Role(context);
                    seriesShareRole.Identifier = "series_all";
                    seriesShareRole.Store();
                    seriesShareRole.IncludePrivileges(Privilege.Get(EntityType.GetEntityType(typeof(Series))));
                    seriesShareRole.GrantToUsers(new int[] { shareCreator.Id }, seriesShareDomain.Id);

                    context.AccessLevel = EntityAccessLevel.Permission;
                }
                else
                {
                    domain1 = Domain.GetInstance(context);
                    domain1.Load("domain-1");
                    domain2 = Domain.GetInstance(context);
                    domain2.Load("domain-2");
                    group1 = Group.FromIdentifier(context, "domain-1_cr_viewers+changers");
                    group2 = Group.FromIdentifier(context, "global_cr_deleters");
                    user0  = User.FromUsername(context, "user-0");
                    user11 = User.FromUsername(context, "domain-1_cr_viewer+changer");
                    user12 = User.FromUsername(context, "domain-1_cr_viewer+changer+deleter");
                    user21 = User.FromUsername(context, "global_cr_deleter");
                    user31 = User.FromUsername(context, "global_service_admin");
                    role1  = Role.GetInstance(context);
                    role1.Load("cr_view+change");
                    role2 = Role.GetInstance(context);
                    role2.Load("cr_delete");
                    role2 = Role.GetInstance(context);
                    role2.Load("service_all");
                }
            } catch (Exception e) {
                Console.WriteLine("{0} - {1}", e.Message, e.StackTrace);
                throw;
            }
        }
        public void VisibilityTest()
        {
            context.AccessLevel = EntityAccessLevel.Administrator;
            context.Execute("DELETE FROM pubserver;");

            User user = new User(context);

            user.Username = "******";
            user.Store();

            User user2 = new User(context);

            user2.Username = "******";
            user2.Store();

            Group group = new Group(context);

            group.Name       = "groupVis";
            group.Identifier = "groupVis";
            group.Store();

            Group group2 = new Group(context);

            group2.Name       = "groupVis2";
            group2.Identifier = "groupVis2";
            group2.Store();

            group.AssignUser(user);

            PublishServer ppub = new PublishServer(context);

            ppub.Name     = "public";
            ppub.Protocol = "ftp";
            ppub.Hostname = "test.org";
            ppub.Store();
            ppub.GrantPermissionsToAll();

            PublishServer ppubresg = new PublishServer(context);

            ppubresg.Name     = "public and assigned to group";
            ppubresg.Protocol = "ftp";
            ppubresg.Hostname = "test.org";
            ppubresg.Store();
            ppubresg.GrantPermissionsToAll();
            ppubresg.GrantPermissionsToGroups(new Group[] { group });

            PublishServer ppubresg2 = new PublishServer(context);

            ppubresg2.Name     = "public and assigned to other group";
            ppubresg2.Protocol = "ftp";
            ppubresg2.Hostname = "test.org";
            ppubresg2.Store();
            ppubresg2.GrantPermissionsToAll();
            ppubresg2.GrantPermissionsToGroups(new Group[] { group2 });

            PublishServer ppubresu = new PublishServer(context);

            ppubresu.Name     = "public and assigned to user";
            ppubresu.Protocol = "ftp";
            ppubresu.Hostname = "test.org";
            ppubresu.Store();
            ppubresu.GrantPermissionsToAll();
            ppubresu.GrantPermissionsToUsers(new User[] { user });

            PublishServer ppubresu2 = new PublishServer(context);

            ppubresu2.Name     = "public and assigned to other user";
            ppubresu2.Protocol = "ftp";
            ppubresu2.Hostname = "test.org";
            ppubresu2.Store();
            ppubresu2.GrantPermissionsToAll();
            ppubresu2.GrantPermissionsToUsers(new User[] { user2 });

            PublishServer presg = new PublishServer(context);

            presg.Name     = "restricted to group";
            presg.Protocol = "ftp";
            presg.Hostname = "test.org";
            presg.Store();
            presg.GrantPermissionsToGroups(new Group[] { group });

            PublishServer presu = new PublishServer(context);

            presu.Name     = "restricted to user";
            presu.Protocol = "ftp";
            presu.Hostname = "test.org";
            presu.Store();
            presu.GrantPermissionsToUsers(new User[] { user });

            PublishServer powna = new PublishServer(context);

            powna.OwnerId  = user.Id;
            powna.Name     = "owned by user (shared with all)";
            powna.Protocol = "ftp";
            powna.Hostname = "test.org";
            powna.Store();
            powna.GrantPermissionsToAll();

            PublishServer powng = new PublishServer(context);

            powng.OwnerId  = user.Id;
            powng.Name     = "owned by user (shared with group)";
            powng.Protocol = "ftp";
            powng.Hostname = "test.org";
            powng.Store();
            powng.GrantPermissionsToGroups(new Group[] { group });

            PublishServer pownu = new PublishServer(context);

            pownu.OwnerId  = user.Id;
            pownu.Name     = "owned by user (shared with other user)";
            pownu.Protocol = "ftp";
            pownu.Hostname = "test.org";
            pownu.Store();
            pownu.GrantPermissionsToUsers(new User[] { user2 });

            PublishServer pown = new PublishServer(context);

            pown.OwnerId  = user.Id;
            pown.Name     = "owned by user (exclusive)";
            pown.Protocol = "ftp";
            pown.Hostname = "test.org";
            pown.Store();

            PublishServer pn = new PublishServer(context);

            pn.Name     = "not accessible";
            pn.Protocol = "ftp";
            pn.Hostname = "test.org";
            pn.Store();

            context.StartImpersonation(user.Id);
            context.AccessLevel = EntityAccessLevel.Privilege;
            EntityDictionary <PublishServer> pd = new EntityDictionary <PublishServer>(context);

            pd.ItemVisibility = EntityItemVisibility.All;
            pd.Load();
            Assert.AreEqual(11, pd.Count);
            Assert.IsTrue(pd.Contains(ppub.Id));
            Assert.AreEqual(EntityItemVisibility.Public, pd[ppub.Id].Visibility);
            Assert.IsTrue(pd.Contains(ppubresg.Id));
            Assert.AreEqual(EntityItemVisibility.Public, pd[ppubresg.Id].Visibility);
            Assert.IsTrue(pd.Contains(ppubresg2.Id));
            Assert.AreEqual(EntityItemVisibility.Public, pd[ppubresg2.Id].Visibility);
            Assert.IsTrue(pd.Contains(ppubresu.Id));
            Assert.AreEqual(EntityItemVisibility.Public, pd[ppubresu.Id].Visibility);
            Assert.IsTrue(pd.Contains(ppubresu2.Id));
            Assert.AreEqual(EntityItemVisibility.Public, pd[ppubresu2.Id].Visibility);
            Assert.IsTrue(pd.Contains(presg.Id));
            Assert.AreEqual(EntityItemVisibility.Restricted, pd[presg.Id].Visibility);
            Assert.IsTrue(pd.Contains(presu.Id));
            Assert.AreEqual(EntityItemVisibility.Private, pd[presu.Id].Visibility);
            Assert.IsTrue(pd.Contains(powna.Id));
            Assert.AreEqual(EntityItemVisibility.Public, pd[powna.Id].Visibility);
            Assert.IsTrue(pd.Contains(powng.Id));
            Assert.AreEqual(EntityItemVisibility.Restricted, pd[powng.Id].Visibility);
            Assert.IsTrue(pd.Contains(pownu.Id));
            Assert.AreEqual(EntityItemVisibility.Restricted, pd[pownu.Id].Visibility);
            Assert.IsTrue(pd.Contains(pown.Id));
            Assert.AreEqual(EntityItemVisibility.Private, pd[pown.Id].Visibility);

            pd.Clear();
            pd.ItemVisibility = EntityItemVisibility.Public;
            pd.Load();
            Assert.AreEqual(6, pd.Count);
            Assert.IsTrue(pd.Contains(ppub.Id));
            Assert.IsTrue(pd.Contains(ppubresg.Id));
            Assert.IsTrue(pd.Contains(ppubresg2.Id));
            Assert.IsTrue(pd.Contains(ppubresu.Id));
            Assert.IsTrue(pd.Contains(ppubresu2.Id));
            Assert.IsTrue(pd.Contains(powna.Id));

            pd.Clear();
            pd.ItemVisibility = EntityItemVisibility.Restricted;
            pd.Load();
            Assert.AreEqual(3, pd.Count);
            Assert.IsTrue(pd.Contains(presg.Id));
            Assert.IsTrue(pd.Contains(powng.Id));
            Assert.IsTrue(pd.Contains(pownu.Id));

            pd.Clear();
            pd.ItemVisibility = EntityItemVisibility.Private;
            pd.Load();
            Assert.AreEqual(2, pd.Count);
            Assert.IsTrue(pd.Contains(presu.Id));
            Assert.IsTrue(pd.Contains(pown.Id));

            pd.Clear();
            pd.ItemVisibility = EntityItemVisibility.Public | EntityItemVisibility.Restricted;
            pd.Load();
            Assert.AreEqual(9, pd.Count);
            Assert.IsTrue(pd.Contains(ppub.Id));
            Assert.IsTrue(pd.Contains(ppubresg.Id));
            Assert.IsTrue(pd.Contains(ppubresg2.Id));
            Assert.IsTrue(pd.Contains(ppubresu.Id));
            Assert.IsTrue(pd.Contains(ppubresu2.Id));
            Assert.IsTrue(pd.Contains(presg.Id));
            Assert.IsTrue(pd.Contains(powna.Id));
            Assert.IsTrue(pd.Contains(powng.Id));
            Assert.IsTrue(pd.Contains(pownu.Id));

            pd.Clear();
            pd.ItemVisibility = EntityItemVisibility.Public | EntityItemVisibility.Private;
            pd.Load();
            Assert.AreEqual(8, pd.Count);
            Assert.IsTrue(pd.Contains(ppub.Id));
            Assert.IsTrue(pd.Contains(ppubresg.Id));
            Assert.IsTrue(pd.Contains(ppubresg2.Id));
            Assert.IsTrue(pd.Contains(ppubresu.Id));
            Assert.IsTrue(pd.Contains(ppubresu2.Id));
            Assert.IsTrue(pd.Contains(presu.Id));
            Assert.IsTrue(pd.Contains(powna.Id));
            Assert.IsTrue(pd.Contains(pown.Id));

            pd.Clear();
            pd.ItemVisibility = EntityItemVisibility.All | EntityItemVisibility.OwnedOnly;
            pd.Load();
            Assert.AreEqual(4, pd.Count);
            Assert.IsTrue(pd.Contains(powna.Id));
            Assert.IsTrue(pd.Contains(powng.Id));
            Assert.IsTrue(pd.Contains(pownu.Id));
            Assert.IsTrue(pd.Contains(pown.Id));

            pd.Clear();
            pd.ItemVisibility = EntityItemVisibility.Public | EntityItemVisibility.OwnedOnly;
            pd.Load();
            Assert.AreEqual(1, pd.Count);
            Assert.IsTrue(pd.Contains(powna.Id));

            pd.Clear();
            pd.ItemVisibility = EntityItemVisibility.Restricted | EntityItemVisibility.OwnedOnly;
            pd.Load();
            Assert.AreEqual(2, pd.Count);
            Assert.IsTrue(pd.Contains(powng.Id));
            Assert.IsTrue(pd.Contains(pownu.Id));

            pd.Clear();
            pd.ItemVisibility = EntityItemVisibility.Private | EntityItemVisibility.OwnedOnly;
            pd.Load();
            Assert.AreEqual(1, pd.Count);
            Assert.IsTrue(pd.Contains(pown.Id));

            context.EndImpersonation();
        }
        public void SortTest()
        {
            context.AccessLevel = EntityAccessLevel.Administrator;
            context.Execute("DELETE FROM pubserver;");

            PublishServer p1 = new PublishServer(context);

            p1.Name     = "pf1";
            p1.Protocol = "ftp";
            p1.Hostname = "test.org";
            p1.Port     = 23;
            p1.Store();
            PublishServer p2 = new PublishServer(context);

            p2.Name     = "pf2";
            p2.Protocol = "ftp";
            p2.Hostname = "anothertest.org";
            p2.Port     = 123;
            p2.Store();
            PublishServer p3 = new PublishServer(context);

            p3.Name     = "pf3";
            p3.Protocol = "sftp";
            p3.Hostname = "experiment.org";
            p3.Port     = 234;
            p3.Store();
            PublishServer p4 = new PublishServer(context);

            p4.Name     = "pf4";
            p4.Protocol = "sftp";
            p4.Hostname = "try.org";
            p4.Port     = 345;
            p4.Store();

            int index;

            int[] expectedIds;

            EntityDictionary <PublishServer> pd1 = new EntityDictionary <PublishServer>(context);

            pd1.AddSort("Name");
            pd1.Load();
            Assert.AreEqual(4, pd1.Count);
            expectedIds = new int[] { p1.Id, p2.Id, p3.Id, p4.Id };
            index       = 0;
            foreach (PublishServer ps in pd1)
            {
                Assert.AreEqual(expectedIds[index++], ps.Id);
            }

            EntityDictionary <PublishServer> pd2 = new EntityDictionary <PublishServer>(context);

            pd2.AddSort("Name", SortDirection.Descending);
            pd2.Load();
            Assert.AreEqual(4, pd2.Count);
            expectedIds = new int[] { p4.Id, p3.Id, p2.Id, p1.Id };
            index       = 0;
            foreach (PublishServer ps in pd2)
            {
                Assert.AreEqual(expectedIds[index++], ps.Id);
            }

            EntityDictionary <PublishServer> pd3 = new EntityDictionary <PublishServer>(context);

            pd3.AddSort("Port", SortDirection.Descending);
            pd3.Load();
            Assert.AreEqual(4, pd3.Count);
            expectedIds = new int[] { p4.Id, p3.Id, p2.Id, p1.Id };
            index       = 0;
            foreach (PublishServer ps in pd3)
            {
                Assert.AreEqual(expectedIds[index++], ps.Id);
            }

            EntityDictionary <PublishServer> pd4 = new EntityDictionary <PublishServer>(context);

            pd4.AddSort("Protocol", SortDirection.Ascending);
            pd4.AddSort("Name", SortDirection.Descending);
            pd4.Load();
            Assert.AreEqual(4, pd4.Count);
            expectedIds = new int[] { p2.Id, p1.Id, p4.Id, p3.Id };
            index       = 0;
            foreach (PublishServer ps in pd4)
            {
                Assert.AreEqual(expectedIds[index++], ps.Id);
            }
        }
        public void KeywordFilterTest()
        {
            context.AccessLevel = EntityAccessLevel.Administrator;
            context.Execute("DELETE FROM pubserver;");

            PublishServer p1 = new PublishServer(context);

            p1.Name     = "pf1 abc def ghi";
            p1.Protocol = "ftp";
            p1.Hostname = "test.org";
            p1.Store();
            PublishServer p2 = new PublishServer(context);

            p2.Name     = "pf2";
            p2.Protocol = "ftp";
            p2.Hostname = "def.org";
            p2.Store();
            PublishServer p3 = new PublishServer(context);

            p3.Name     = "pf3";
            p3.Protocol = "ftp";
            p3.Hostname = "test.org";
            p3.Path     = "/ghi/jkl";
            p3.Store();
            PublishServer p4 = new PublishServer(context);

            p4.Name     = "z*";
            p4.Protocol = "z";
            p4.Hostname = "z.org";
            p4.Path     = "/z";
            p4.Store();
            EntityDictionary <PublishServer> pd;

            pd = new EntityDictionary <PublishServer>(context);
            pd.SearchKeyword = "abc";
            pd.Load();
            Assert.AreEqual(1, pd.TotalResults);
            Assert.AreEqual(1, pd.Count);
            Assert.IsTrue(pd.Contains(p1.Id));

            pd = new EntityDictionary <PublishServer>(context);
            pd.SearchKeyword = "def";
            pd.Load();
            Assert.AreEqual(2, pd.TotalResults);
            Assert.AreEqual(2, pd.Count);
            Assert.IsTrue(pd.Contains(p1.Id) && pd.Contains(p2.Id));

            pd = new EntityDictionary <PublishServer>(context);
            pd.SearchKeyword = "ghi";
            pd.Load();
            Assert.AreEqual(2, pd.TotalResults);
            Assert.AreEqual(2, pd.Count);
            Assert.IsTrue(pd.Contains(p1.Id) && pd.Contains(p3.Id));

            pd = new EntityDictionary <PublishServer>(context);
            pd.SearchKeyword  = "de";
            pd.FindWholeWords = true;
            pd.Load();
            Assert.AreEqual(0, pd.TotalResults);
            Assert.AreEqual(0, pd.Count);

            pd = new EntityDictionary <PublishServer>(context);
            pd.SearchKeyword  = "de";
            pd.FindWholeWords = false;
            pd.Load();
            Assert.AreEqual(2, pd.TotalResults);
            Assert.AreEqual(2, pd.Count);
            Assert.IsTrue(pd.Contains(p1.Id) && pd.Contains(p2.Id));

            pd = new EntityDictionary <PublishServer>(context);
            pd.SearchKeyword  = "*";
            pd.FindWholeWords = false;
            pd.Load();
            Assert.AreEqual(4, pd.TotalResults);
            Assert.AreEqual(4, pd.Count);
            Assert.IsTrue(pd.Contains(p1.Id) && pd.Contains(p2.Id) && pd.Contains(p3.Id) && pd.Contains(p4.Id));

            pd = new EntityDictionary <PublishServer>(context);
            pd.SearchKeyword  = "z*";
            pd.FindWholeWords = false;
            pd.LiteralSearch  = true;
            pd.Load();
            Assert.AreEqual(1, pd.TotalResults);
            Assert.AreEqual(1, pd.Count);
            Assert.IsTrue(pd.Contains(p4.Id));
        }
        public void OwnerFilterTest()
        {
            context.AccessLevel = EntityAccessLevel.Administrator;
            context.Execute("DELETE FROM usr WHERE username IN ('user1', 'user2', 'psmith');");
            context.Execute("DELETE FROM pubserver;");

            User user1 = new User(context);

            user1.Username  = "******";
            user1.FirstName = "John";
            user1.LastName  = "Doe";
            user1.Store();

            User user2 = new User(context);

            user2.Username  = "******";
            user2.FirstName = "Jane";
            user2.LastName  = "Doe";
            user2.Store();

            User user3 = new User(context);

            user3.Username  = "******";
            user3.FirstName = "Peter";
            user3.LastName  = "Smith";
            user3.Store();

            PublishServer p1 = new PublishServer(context);

            p1.Name        = "p1";
            p1.Protocol    = "ftp";
            p1.Hostname    = "test1.org";
            p1.FileRootDir = "/dir";
            p1.OwnerId     = user1.Id;
            p1.Store();

            PublishServer p2 = new PublishServer(context);

            p2.Name        = "p2";
            p2.Protocol    = "ftp";
            p2.Hostname    = "test2.org";
            p2.FileRootDir = "/dir";
            p2.OwnerId     = user2.Id;
            p2.Store();

            PublishServer p3 = new PublishServer(context);

            p3.Name        = "p3";
            p3.Protocol    = "ftp";
            p3.Hostname    = "test3.org";
            p3.FileRootDir = "/dir";
            p3.OwnerId     = user3.Id;
            p3.Store();

            EntityDictionary <PublishServer> pd1 = new EntityDictionary <PublishServer>(context);

            pd1.SearchKeyword = "doe";
            pd1.IncludeOwnerFieldsInSearch = true;
            pd1.Load();
            Assert.AreEqual(2, pd1.TotalResults);
            Assert.AreEqual(2, pd1.Count);
            Assert.IsTrue(pd1.Contains(p1.Id) && pd1.Contains(p2.Id));

            EntityDictionary <PublishServer> pd2 = new EntityDictionary <PublishServer>(context);

            pd2.SearchKeyword = "peter";
            pd2.IncludeOwnerFieldsInSearch = true;
            context.ConsoleDebug           = true;
            pd2.Load();
            Assert.AreEqual(1, pd2.TotalResults);
            Assert.AreEqual(1, pd2.Count);
            Assert.IsTrue(pd2.Contains(p3.Id));

            EntityDictionary <PublishServer> pd3 = new EntityDictionary <PublishServer>(context);

            pd3.SearchKeyword = "Smith";
            pd3.IncludeOwnerFieldsInSearch = true;
            context.ConsoleDebug           = true;
            pd3.Load();
            Assert.AreEqual(1, pd3.TotalResults);
            Assert.AreEqual(1, pd3.Count);
            Assert.IsTrue(pd3.Contains(p3.Id));
        }
        public void FilterTest()
        {
            context.AccessLevel = EntityAccessLevel.Administrator;
            context.Execute("DELETE FROM domain;");
            context.Execute("DELETE FROM pubserver;");

            Domain testDomain1 = new Domain(context);

            testDomain1.Identifier = "domain1";
            testDomain1.Store();

            Domain testDomain2 = new Domain(context);

            testDomain2.Identifier = "domain2";
            testDomain2.Store();

            PublishServer p1 = new PublishServer(context);

            p1.Name        = "pf1";
            p1.Protocol    = "ftp";
            p1.Hostname    = "test.org";
            p1.Port        = 23;
            p1.FileRootDir = "/dir1";
            p1.Domain      = testDomain1;
            p1.Store();
            PublishServer p2 = new PublishServer(context);

            p2.Name        = "pf2";
            p2.Protocol    = "ftp";
            p2.Hostname    = "anothertest.org";
            p2.Port        = 123;
            p2.FileRootDir = "/dir2";
            p2.Store();
            PublishServer p3a = new PublishServer(context);

            p3a.Name     = "pf3a";
            p3a.Protocol = "ftp";
            p3a.Hostname = "experiment.org";
            p3a.Port     = 234;
            p3a.Store();
            PublishServer p3b = new PublishServer(context);

            p3b.Name     = "pf3b";
            p3b.Protocol = "ftp";
            p3b.Hostname = "try.org";
            p3b.Port     = 345;
            p3b.Domain   = testDomain2;
            p3b.Store();

            EntityDictionary <PublishServer> pd1 = new EntityDictionary <PublishServer>(context);

            pd1.SetFilter("Hostname", "*test*.org");
            pd1.Load();
            Assert.AreEqual(2, pd1.TotalResults);
            Assert.AreEqual(2, pd1.Count);
            Assert.IsTrue(pd1.Contains(p1.Id) && pd1.Contains(p2.Id));

            EntityDictionary <PublishServer> pd2 = new EntityDictionary <PublishServer>(context);

            pd2.SetFilter("Port", "123");
            pd2.Load();
            Assert.AreEqual(1, pd2.TotalResults);
            Assert.AreEqual(1, pd2.Count);
            Assert.IsTrue(pd2.Contains(p2.Id));

            EntityDictionary <PublishServer> pd3 = new EntityDictionary <PublishServer>(context);

            pd3.SetFilter("Port", "[234");
            pd3.Load();
            Assert.AreEqual(2, pd3.TotalResults);
            Assert.AreEqual(2, pd3.Count);
            Assert.IsTrue(pd3.Contains(p3a.Id) && pd3.Contains(p3b.Id));

            EntityDictionary <PublishServer> pd4 = new EntityDictionary <PublishServer>(context);

            pd4.SetFilter("Port", "]100,300[");
            pd4.Load();
            Assert.AreEqual(2, pd4.TotalResults);
            Assert.AreEqual(2, pd4.Count);
            Assert.IsTrue(pd4.Contains(p2.Id) && pd4.Contains(p3a.Id));

            EntityDictionary <PublishServer> pd5 = new EntityDictionary <PublishServer>(context);

            pd5.SetFilter("Name", "pf3*");
            pd5.Load();
            Assert.AreEqual(2, pd5.TotalResults);
            Assert.AreEqual(2, pd5.Count);
            Assert.IsTrue(pd5.Contains(p3a.Id) && pd3.Contains(p3b.Id));

            EntityDictionary <PublishServer> pd6 = new EntityDictionary <PublishServer>(context);

            pd6.SetFilter("FileRootDir", SpecialSearchValue.Null);
            pd6.Load();
            Assert.AreEqual(2, pd6.TotalResults);
            Assert.AreEqual(2, pd6.Count);
            Assert.IsTrue(pd6.Contains(p3a.Id) && pd6.Contains(p3b.Id));

            EntityDictionary <PublishServer> pd7 = new EntityDictionary <PublishServer>(context);

            pd7.SetFilter("FileRootDir", SpecialSearchValue.NotNull);
            pd7.Load();
            Assert.AreEqual(2, pd7.TotalResults);
            Assert.AreEqual(2, pd7.Count);
            Assert.IsTrue(pd7.Contains(p1.Id) && pd7.Contains(p2.Id));

            EntityDictionary <PublishServer> pd8 = new EntityDictionary <PublishServer>(context);

            pd8.SetFilter("FileRootDir", new object[] { "/dir2", SpecialSearchValue.Null });
            pd8.Load();
            Assert.AreEqual(3, pd8.TotalResults);
            Assert.AreEqual(3, pd8.Count);
            Assert.IsTrue(pd8.Contains(p2.Id) && pd8.Contains(p3a.Id) && pd8.Contains(p3b.Id));

            EntityDictionary <PublishServer> pd9 = new EntityDictionary <PublishServer>(context);

            pd9.SetFilter("DomainId", new object[] { testDomain1.Id, SpecialSearchValue.Null });
            pd9.Load();
            Assert.AreEqual(3, pd9.TotalResults);
            Assert.AreEqual(3, pd9.Count);
            Assert.IsTrue(pd9.Contains(p1.Id) && pd9.Contains(p2.Id) && pd9.Contains(p3a.Id));
        }