示例#1
0
        public void UpdateTest()
        {
            IAccount a = AccountGateway.GetAll().FirstOrDefault();

            Console.WriteLine("Old Values:");
            PrintAccount(a);

            a.Host      = "www.test.com";
            a.UserName  = "******";
            a.IsDefault = true;
            a.Password  = "******";

            IAccount b = AccountGateway.Update(a);

            Console.WriteLine("New Values:");
            PrintAccount(b);

            Assert.AreEqual(a.Id, b.Id);
        }
示例#2
0
        public void UpdateCollectionTest()
        {
            IAccount a1 = AccountGateway.Add("test1", "test1", "www.baidu.com", "*****@*****.**");
            IAccount a2 = AccountGateway.Add("test2", "test2", "www.google.com", "*****@*****.**", true);

            Process.Start(AccountGateway.AccountSettingPath);

            Thread.Sleep(1000);

            Console.WriteLine("Account(a1) Old Values:");
            PrintAccount(a1);

            Console.WriteLine("Account(a2) Old Values:");
            PrintAccount(a2);

            a1.UserName = "******";
            a1.Host     = "www.baidudu.com";

            a2.UserName = "******";
            a2.Host     = "www.googlegle.com";

            IList <IAccount> expect = new List <IAccount>()
            {
                a1, a2
            };

            IList <IAccount> actual = AccountGateway.Update(expect);

            Process.Start(AccountGateway.AccountSettingPath);

            a1 = actual.FirstOrDefault(a => a.Id == a1.Id);

            Assert.IsNotNull(a1);
            Console.WriteLine("Found Account(a1) New Values:");
            PrintAccount(a1);

            a2 = actual.FirstOrDefault(a => a.Id == a2.Id);

            Assert.IsNotNull(a2);
            Console.WriteLine("Found Account(a1) New Values:");
            PrintAccount(a2);
        }
示例#3
0
        public void RefreshTest()
        {
            IList <Cookie> cookies = new List <Cookie>();

            #region Test email host domain

            //IList<IAccount> accounts = AccountGateway.GetAll();

            //foreach (IAccount account in accounts)
            //{
            //    account.IsDefault = account.Host == "legacymail.taylorcorp.com";
            //}

            //accounts= AccountGateway.Update(accounts);

            #endregion

            #region Test wrong email host domain

            IAccount a = AccountGateway.GetDefault();
            a.Host = "test.test.com";
            a      = AccountGateway.Update(a);

            #endregion

            Process.Start(AccountGateway.AccountSettingPath);

            try
            {
                Authentication.AuthenticationManager.Refresh();
                cookies = Authentication.AuthenticationManager.Current.CookieCache;
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(e, typeof(AuthenticationException));
                Console.WriteLine(e.Message);
            }

            Assert.IsTrue(cookies.Count < 2);

            #region Test email host domain

            //foreach (IAccount account in accounts)
            //{
            //    account.IsDefault = account.Host == "webmail.taylorcorp.com";
            //}
            //AccountGateway.Update(accounts);

            #endregion

            #region Test wrong email host domain

            a.Host = "webmail.taylorcorp.com";
            a      = AccountGateway.Update(a);

            #endregion

            Process.Start(AccountGateway.AccountSettingPath);

            Authentication.AuthenticationManager.Refresh();

            cookies = Authentication.AuthenticationManager.Current.CookieCache;

            Console.WriteLine("Count:{0}", cookies.Count);

            Assert.IsTrue(cookies.Count >= 2);
        }
        /**
         * Facilitate testing of data layer
         */
        public static void Main(string[] args)
        {
            // FOR PROTOTYPE DEMO, START WITH EMPTY DB

            var db              = new DbObj();
            var db2             = new DbObj();
            var accGateway      = new AccountGateway(db);
            var metadataGateway = new MetadataGateway(db2);

            string       email = "*****@*****.**";
            ObjectId     objId;
            AccountModel acc;

            while (true)
            {
                Console.WriteLine("\nSelect an operation:");
                Console.WriteLine("0.  Exit.");
                Console.WriteLine("1.  Create 4 new users.");
                Console.WriteLine("2.  View all users.");
                Console.WriteLine("3.  Update a user's name.");
                Console.WriteLine("4.  Delete a user's account.");
                Console.WriteLine("5.  View name & password of a user.");
                Console.WriteLine("6.  Create sample file and folders.");
                Console.WriteLine("7.  View content of user's root folder.");
                string cmd = Console.ReadLine();

                switch (cmd)
                {
                case "0":
                    Console.WriteLine("\nExit ok.");
                    return;

                case "1":
                    // CREATE
                    objId = ObjectId.GenerateNewId();
                    accGateway.Insert(new AccountModel(objId, "Ng Cai Feng", "Mr",
                                                       "*****@*****.**", "password1", DateTime.Now, true, "", "Bio"));
                    objId = ObjectId.GenerateNewId();
                    accGateway.Insert(new AccountModel(objId, "Chua Xiang Wei, Jerahmeel", "Mr",
                                                       "*****@*****.**", "password2", DateTime.Now, true, "", "Bio"));
                    objId = ObjectId.GenerateNewId();
                    accGateway.Insert(new AccountModel(objId, "Ryan Chia Dong Yi", "Mr",
                                                       "*****@*****.**", "password3", DateTime.Now, true, "", "Bio"));
                    objId = ObjectId.GenerateNewId();
                    accGateway.Insert(new AccountModel(objId, "Lim Jing Pei", "Ms",
                                                       "*****@*****.**", "password4", DateTime.Now, true, "", "Bio"));
                    accGateway.Save();

                    break;

                case "2":
                    // READ all accounts
                    var readResults = accGateway.SelectAll().GetEnumerator();

                    while (readResults.MoveNext())
                    {
                        Console.WriteLine(readResults.Current?.Email + " " + readResults.Current?.Name);
                    }

                    break;

                case "3":
                    // UPDATE account by email
                    Console.WriteLine("Enter the email of the user whose name you want to update:");
                    email = Console.ReadLine();
                    Console.WriteLine("Enter the new name:");
                    String name = Console.ReadLine();

                    acc = accGateway.SelectByEmail(email);
                    if (acc != null)
                    {
                        acc.Name = name;

                        accGateway.Update(acc);
                        accGateway.Save();
                    }
                    else
                    {
                        Console.WriteLine("Email not found.");
                    }

                    break;

                case "4":
                    // DELETE account by email
                    Console.WriteLine("Enter the email of the user to delete:");
                    email = Console.ReadLine();

                    acc = accGateway.SelectByEmail(email);
                    if (acc != null)
                    {
                        accGateway.Delete(acc);
                        accGateway.Save();
                    }
                    else
                    {
                        Console.WriteLine("Email not found.");
                    }

                    break;

                case "5":
                    // SELECT ACCOUNT MODEL BY EMAIL
                    Console.WriteLine("Enter the email of the user you want to view:");
                    email = Console.ReadLine();

                    acc = accGateway.SelectByEmail(email);
                    if (acc != null)
                    {
                        Console.WriteLine("Name of " + email + ": " + acc.Name);
                        Console.WriteLine("Password of " + email + ": " + acc.Password);
                    }
                    else
                    {
                        Console.WriteLine("Email not found.");
                    }

                    break;

                case "6":
                    // CREATE FILES AND FOLDERS

                    AccessControlsModel        acModel1 = new AccessControlsModel("*****@*****.**", true, true);
                    AccessControlsModel        acModel2 = new AccessControlsModel("*****@*****.**", true, true);
                    List <AccessControlsModel> acList   = new List <AccessControlsModel>();
                    acList.Add(acModel1); acList.Add(acModel2);

                    ObjectId userRootId = ObjectId.GenerateNewId();
                    ObjectId folderAId  = ObjectId.GenerateNewId();
                    ObjectId folderBId  = ObjectId.GenerateNewId();
                    ObjectId folderCId  = ObjectId.GenerateNewId();

                    // userRoot
                    metadataGateway.Insert(new MetadataModel(userRootId, email, email, 0, DateTime.Now, "", "", acList));
                    // folderA in root
                    metadataGateway.Insert(new MetadataModel(folderAId, email, "FolderA", 0, DateTime.Now, "", userRootId.ToString(), acList));
                    // fileA in folderA
                    metadataGateway.Insert(new MetadataModel(ObjectId.GenerateNewId(), email, "FileA", 1, DateTime.Now, "", folderAId.ToString(), acList));
                    // fileB in folderA
                    metadataGateway.Insert(new MetadataModel(ObjectId.GenerateNewId(), email, "FileB", 1, DateTime.Now, "", folderAId.ToString(), acList));
                    // fileC in folderA
                    metadataGateway.Insert(new MetadataModel(ObjectId.GenerateNewId(), email, "FileC", 1, DateTime.Now, "", folderAId.ToString(), acList));
                    // folderB in folderA
                    metadataGateway.Insert(new MetadataModel(folderBId, email, "FolderB", 0, DateTime.Now, "", folderAId.ToString(), acList));
                    // fileD in folderB
                    metadataGateway.Insert(new MetadataModel(ObjectId.GenerateNewId(), email, "FileD", 1, DateTime.Now, "", folderBId.ToString(), acList));
                    // folderC in root
                    metadataGateway.Insert(new MetadataModel(folderCId, email, "FolderC", 0, DateTime.Now, "", userRootId.ToString(), acList));
                    // fileE in folderC
                    metadataGateway.Insert(new MetadataModel(ObjectId.GenerateNewId(), email, "FileE", 1, DateTime.Now, "", folderCId.ToString(), acList));
                    // fileF in root
                    metadataGateway.Insert(new MetadataModel(ObjectId.GenerateNewId(), email, "FileF", 1, DateTime.Now, "", userRootId.ToString(), acList));
                    // fileG in root
                    metadataGateway.Insert(new MetadataModel(ObjectId.GenerateNewId(), email, "FileG", 1, DateTime.Now, "", userRootId.ToString(), acList));

                    metadataGateway.Save();

                    break;

                case "7":
                    // View content of user's root folder

                    Console.WriteLine("Enter the email of the user:"******"\nTop level files and folders:\n");
                        var contentEnumerator = content.GetEnumerator();
                        while (contentEnumerator.MoveNext())
                        {
                            Console.WriteLine(contentEnumerator.Current?.name);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Email not found.");
                    }

                    break;

                default:
                    Console.WriteLine("Invalid command.");
                    break;
                }
            }
        }