Beispiel #1
0
        public void InitializedWithAlgorithmFromDITest()
        {
            try
            {
                InitializeSymmetricAlgorithmTest();

                var target = new SymmetricAlgorithmFactory();

                target.Initialize();
                var symmetric1 = target.Create();

                Assert.IsNotNull(symmetric1);

                var symmetric2 = target.Create();

                Assert.IsNotNull(symmetric2);
                Assert.IsFalse(object.ReferenceEquals(symmetric1, symmetric2));
                Assert.IsInstanceOfType(symmetric1, typeof(Aes));
                Assert.IsInstanceOfType(symmetric2, typeof(Aes));
            }
            finally
            {
                CleanupTest();
            }
        }
Beispiel #2
0
        public void InitializedTest5()
        {
            try
            {
                ServiceLocatorWrapper.Reset();
                _unityServiceLocator = new UnityServiceLocator(
                    new UnityContainer()
                    /*.RegisterInstance<string>(Algorithms.Symmetric.ResolveName, "DES")*/
                    /*.RegisterType<Symmetric, TripleDESCryptoServiceProvider>()*/);
                ServiceLocator.SetLocatorProvider(() => _unityServiceLocator);

                var target = new SymmetricAlgorithmFactory();

                target.Initialize("RC2");

                var symmetric = target.Create();

                Assert.IsNotNull(symmetric);
                Assert.IsInstanceOfType(symmetric, typeof(RC2));
            }
            finally
            {
                CleanupTest();
            }
        }
Beispiel #3
0
        public void UninitializedTest()
        {
            try
            {
                var target = new SymmetricAlgorithmFactory();

                target.Create();
            }
            finally
            {
                CleanupTest();
            }
        }
Beispiel #4
0
        public void InitializedWithGoodNameTest()
        {
            try
            {
                InitializeSymmetricNameTest("DES");

                var target = new SymmetricAlgorithmFactory();

                target.Initialize("TripleDES");
                var symmetric1 = target.Create();

                Assert.IsNotNull(symmetric1);
                Assert.AreEqual("TripleDES", target.SymmetricAlgorithmName);

                var symmetric2 = target.Create();

                Assert.IsNotNull(symmetric2);
                Assert.AreNotEqual(symmetric1, symmetric2);
            }
            finally
            {
                CleanupTest();
            }
        }
Beispiel #5
0
        public void InitializedWithEmptyNameFromDITest()
        {
            try
            {
                InitializeSymmetricNameTest("");

                var target = new SymmetricAlgorithmFactory();

                target.Initialize();
                var symmetric1 = target.Create();

                Assert.IsNotNull(symmetric1);
                Assert.AreEqual("AESManaged", target.SymmetricAlgorithmName);

                var symmetric2 = target.Create();

                Assert.IsNotNull(symmetric2);
                Assert.AreNotEqual(symmetric1, symmetric2);
            }
            finally
            {
                CleanupTest();
            }
        }