Beispiel #1
0
        public void Test_LoopThroughExpiredCachedListWithReinsertedValues()
        {
            int    numberOfItems = 10;
            string value;
            int    half = numberOfItems / 2;

            SlimCacheManager.PurgeCacheItem(TestCacheItem.slim_testitem_1.ToString());
            Trace.WriteLine("\n\nStart Loop through direct access with change");
            foreach (int key in GetDictionaryFromCache(TestCacheItem.slim_testitem_1, numberOfItems).Keys)
            {
                if (half == key)
                {
                    Trace.WriteLine("Remove object from cache");
                    SlimCacheManager.PurgeCacheItem(TestCacheItem.slim_testitem_1.ToString());
                    Assert.AreEqual(false, SlimCacheManager.IsObjectCached(TestCacheItem.slim_testitem_1.ToString()));

                    Trace.WriteLine("Insert object into cache with half amount of items");
                    var records = GetDictionaryFromCache(TestCacheItem.slim_testitem_1, half);
                    DebugUtility.GetDebugString(records);
                }

                if (key >= half)
                {
                    Assert.Throws <KeyNotFoundException>(delegate { value = GetDictionaryFromCache(TestCacheItem.slim_testitem_1, numberOfItems)[key]; });
                }
                else
                {
                    value = GetDictionaryFromCache(TestCacheItem.slim_testitem_1, numberOfItems)[key];
                    Trace.WriteLine("Successfully retrieved value: " + value);
                }
            }
        }
Beispiel #2
0
        public void Test_LoopThroughExpiredCachedListWithLocalCopyAndNullCheck()
        {
            int numberOfItems = 10;

            Dictionary <int, string> records = GetDictionaryFromCache(TestCacheItem.slim_testitem_1, numberOfItems);

            string value;
            int    half = numberOfItems / 2;


            SlimCacheManager.PurgeCacheItem(TestCacheItem.slim_testitem_1.ToString());
            records = GetDictionaryFromCache(TestCacheItem.slim_testitem_1, numberOfItems);
            Trace.WriteLine("\n\nStart Loop through local copy");
            foreach (int key in records.Keys)
            {
                if (half == key)
                {
                    Trace.WriteLine("Remove object from cache");
                    SlimCacheManager.PurgeCacheItem(TestCacheItem.slim_testitem_1.ToString());
                    Assert.AreEqual(false, SlimCacheManager.IsObjectCached(TestCacheItem.slim_testitem_1.ToString()));

                    Trace.WriteLine("Insert object into cache with half amount of items");
                    records = GetDictionaryFromCache(TestCacheItem.slim_testitem_1, half);
                    DebugUtility.GetDebugString(records);
                }

                if (records.ContainsKey(key))
                {
                    value = records[key];
                    Trace.WriteLine("Successfully retrieved value: " + value);
                }
            }
        }
Beispiel #3
0
        public void Test_EnumDebugString()
        {
            Trace.WriteLine(Configuration.GetGenericHeader());

            Assert.AreEqual(DebugUtility.GetDebugString(typeof(DummyEnum)), "One, Two, THREE");

            Trace.WriteLine(Configuration.GetGenericFooter());
        }
Beispiel #4
0
        public void Test_EnumerableDebugString()
        {
            Trace.WriteLine(Configuration.GetGenericHeader());

            List <string> strings = new List <string>()
            {
                "One", "Two", "THREE"
            };

            Assert.AreEqual(DebugUtility.GetDebugString(strings), "One, Two, THREE");

            List <int> numbers = new List <int>()
            {
                1, 2, 3
            };

            Assert.AreEqual(DebugUtility.GetDebugString(numbers), "1, 2, 3");

            Trace.WriteLine(Configuration.GetGenericFooter());
        }
Beispiel #5
0
        public void Test_ParseXElementNode()
        {
            XElement element = new XElement("r");

            TimeSpan ts1 = new TimeSpan(12, 5, 3);
            TimeSpan ts2 = TimeSpan.FromDays(2);

            Trace.WriteLine(ts1.ToString());
            Trace.WriteLine(ts2.ToString());

            Trace.WriteLine(string.Format("{0}.{1:00}:{2:00}:{3:00}", ts1.Days, (int)ts1.Hours, ts1.Minutes, ts1.Seconds));

            #region enums
            element.SetElementValue("TimeSpan", string.Format("{0}.{1:00}:{2:00}:{3:00}", ts1.Days, (int)ts1.Hours, ts1.Minutes, ts1.Seconds));
            var testTimeSpan = element.ParseXElementNode <TimeSpan>("TimeSpan", TimeSpan.FromDays(1));

            Assert.AreEqual(ts1, testTimeSpan);
            #endregion

            #region enums
            element.SetElementValue("Enum", TestEnum.Value1);
            var testEnum = element.ParseXElementNode <TestEnum>("Enum", TestEnum.Undefined);

            Assert.AreEqual(TestEnum.Value1, testEnum);

            TestEnum?testEnum2;
            element.SetElementValue("Enum2", null);
            testEnum2 = element.ParseXElementNode <TestEnum?>("Enum2", null);

            Assert.AreEqual(null, testEnum2);
            element.SetElementValue("Enum2", TestEnum.Value1);
            testEnum2 = element.ParseXElementNode <TestEnum?>("Enum2", null);

            Assert.AreEqual(TestEnum.Value1, testEnum2);
            #endregion

            #region lists
            List <int> testList = new List <int>()
            {
                1, 2, 3, 4, 5
            };
            List <bool> testList2 = new List <bool>()
            {
                false, true, false
            };
            List <string> testList3 = new List <string>()
            {
                "false", "true", "false"
            };
            List <DayOfWeek> testList4 = new List <DayOfWeek>()
            {
                DayOfWeek.Friday, DayOfWeek.Monday
            };
            List <TestEnum> testList5 = new List <TestEnum>()
            {
                TestEnum.Value1, TestEnum.Undefined
            };

            element.SetXElementNodeList("MyList1", testList);
            element.SetXElementNodeList("MyList2", testList2);
            element.SetXElementNodeList("MyList3", testList3);
            element.SetXElementNodeList("MyList4", testList4);
            element.SetXElementNodeList("MyList5", testList5);


            Trace.WriteLine(DebugUtility.GetDebugString(element.ParseXElementNodeList <List <int> >("MyList1", new List <int>())));
            Trace.WriteLine(DebugUtility.GetDebugString(element.ParseXElementNodeList <List <bool> >("MyList2", new List <bool>())));
            Trace.WriteLine(DebugUtility.GetDebugString(element.ParseXElementNodeList <List <string> >("MyList3", new List <string>())));
            Trace.WriteLine(DebugUtility.GetDebugString(element.ParseXElementNodeList <List <DayOfWeek> >("MyList4", new List <DayOfWeek>())));
            Trace.WriteLine(DebugUtility.GetDebugString(element.ParseXElementNodeList <List <TestEnum> >("MyList5", new List <TestEnum>())));
            #endregion

            #region dictionaries
            Dictionary <int, string> dict1 = new Dictionary <int, string>()
            {
                { 1, "test1" }, { 2, "test2" }
            };

            element.SetXElementNodeLookup("MyDict1", dict1);

            Trace.WriteLine(DebugUtility.GetDebugString(element.ParseXElementNodeLookup <Dictionary <int, string> >("MyDict1", new Dictionary <int, string>())));

            #endregion

            Trace.WriteLine(element.ToString(SaveOptions.None));
        }
 private string EncodePassword(string pass, string salt, MembershipPasswordFormat format)
 {
     if (format == MembershipPasswordFormat.Clear)
     {
         return(pass);
     }
     if (format == MembershipPasswordFormat.Hashed)
     {
         if (!Enum.IsDefined(typeof(SimpleHashAlgorithm), this.EncryptionAlgorithm))
         {
             throw new ProviderException("Encryption algorithm not valid. Possible values are " + DebugUtility.GetDebugString(typeof(SimpleHashAlgorithm)) + " when using hashed encryption.");
         }
         return(EncryptionManager.ComputeHash(pass, (SimpleHashAlgorithm)Enum.Parse(typeof(SimpleHashAlgorithm), this.EncryptionAlgorithm), Encoding.Unicode.GetBytes(salt)));
     }
     else
     {
         if (this.EncryptionAlgorithm.ToUpper() == "DPAPI")
         {
             return(EncryptionManager.EncryptDPAPI(pass));
         }
         if (!Enum.IsDefined(typeof(RijndaelSimpleHashAlgorithm), this.EncryptionAlgorithm))
         {
             throw new ProviderException("Membership.HashAlgorithmType not found. Possible values are " + DebugUtility.GetDebugString(typeof(RijndaelSimpleHashAlgorithm)) + " and DPAPI");
         }
         return(EncryptionManager.AES_Simple_Encrypt(pass, this.PasswordPassphrase, salt, this.PasswordInitVector, (RijndaelSimpleHashAlgorithm)Enum.Parse(typeof(RijndaelSimpleHashAlgorithm), this.EncryptionAlgorithm), RijndaelSimpleKeySize.Medium, 3));
     }
 }
        private bool CheckPassword(string password, string dbpassword, string salt, MembershipPasswordFormat format)
        {
            switch (format)
            {
            case MembershipPasswordFormat.Clear:
                return(dbpassword.Equals(password));

            case MembershipPasswordFormat.Hashed:
                if (!Enum.IsDefined(typeof(SimpleHashAlgorithm), this.EncryptionAlgorithm))
                {
                    throw new ProviderException("Membership.HashAlgorithmType not found. Possible values are " + DebugUtility.GetDebugString(typeof(SimpleHashAlgorithm)) + " when using hashed encryption.");
                }
                return(EncryptionManager.VerifyHash(password, (SimpleHashAlgorithm)Enum.Parse(typeof(SimpleHashAlgorithm), this.EncryptionAlgorithm), dbpassword));

            case MembershipPasswordFormat.Encrypted:
                return(this.DecodePassword(dbpassword, salt, format).Equals(password));

            default:
                throw new NotImplementedException(("MembershipPasswordFormat " + format) ?? (this.PasswordFormat + " not implemented."));
            }
        }
        private string DecodePassword(string dbpassword, string salt, MembershipPasswordFormat?format)
        {
            switch (format ?? this.PasswordFormat)
            {
            case MembershipPasswordFormat.Clear:
            case MembershipPasswordFormat.Hashed:
                return(dbpassword);

            case MembershipPasswordFormat.Encrypted:
            {
                string result = string.Empty;
                if (this.EncryptionAlgorithm.ToUpper() == "DPAPI")
                {
                    result = EncryptionManager.DecryptDPAPI(dbpassword);
                }
                else
                {
                    if (!Enum.IsDefined(typeof(RijndaelSimpleHashAlgorithm), this.EncryptionAlgorithm))
                    {
                        throw new ProviderException("Encryption algorithm not valid. Possible values are " + DebugUtility.GetDebugString(typeof(RijndaelSimpleHashAlgorithm)) + " and DPAPI");
                    }
                    result = EncryptionManager.AES_Simple_Decrypt(dbpassword, this.PasswordPassphrase, salt, this.PasswordInitVector, (RijndaelSimpleHashAlgorithm)Enum.Parse(typeof(RijndaelSimpleHashAlgorithm), this.EncryptionAlgorithm), RijndaelSimpleKeySize.Medium, 3);
                }
                return(result);
            }

            default:
                throw new NotImplementedException(("MembershipPasswordFormat " + format) ?? (this.PasswordFormat + " not implemented."));
            }
        }