コード例 #1
0
        public void StorageFiresEventTest()
        {
            using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlString))
            {
                StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
                IStorageProviderReader storage = factory.Create(applConfig1) as IStorageProviderReader;
                Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));

                using (IConfigurationChangeWatcher watcher = storage.CreateConfigurationChangeWatcher())
                {
                    watcher.ConfigurationChanged += new ConfigurationChangedEventHandler(OnConfigurationChanged);

                    watcher.StartWatching();
                    Thread.Sleep(100);
                    ((IStorageProviderWriter)storage).Write(GetData());

                    for (int wait = 0; wait < 10 && eventFiredCount < 2; ++wait)
                    {
                        Thread.Sleep(500);
                    }

                    watcher.Dispose();
                }

                Assert.AreEqual(1, eventFiredCount);
            }
        }
コード例 #2
0
        public IHttpActionResult Get(string token)
        {
            if (string.IsNullOrWhiteSpace(token))
            {
                return(BadRequest());
            }

            var storageProviderName       = ConfigurationManager.AppSettings["ITokenStorageProviderName"];
            ITokenStorageProvider storage = StorageProviderFactory.Create(storageProviderName);

            if (storage == null)
            {
                return(InternalServerError(new ArgumentException("Storage provider not found.")));
            }

            //try to get the item
            var value = storage.Read(token);

            if (string.IsNullOrWhiteSpace(value))
            {
                return(NotFound());
            }

            return(Ok(value));
        }
コード例 #3
0
 public void NoPathReadWriteTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(NoPathXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         factory.Create(applConfig1);
     }
 }
コード例 #4
0
 public void TypeDoesNotImplementTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(notImplXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         factory.Create("ApplConfig1");
     }
 }
コード例 #5
0
 public void BadSectionTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(notImplXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         factory.Create("Foo");
     }
 }
コード例 #6
0
        private ITokenStorageProvider GetStorageProvider()
        {
            //get the storage provider, based on config setting
            //Note: more robust implementation would probably use Dependency Injection, for now using a factory
            var storageProviderName       = ConfigurationManager.AppSettings["ITokenStorageProviderName"];
            ITokenStorageProvider storage = StorageProviderFactory.Create(storageProviderName);

            return(storage);
        }
コード例 #7
0
 public void CreateTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(xmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderReader storage = factory.Create("ApplConfig1");
         Assert.IsNotNull(storage);
     }
 }
コード例 #8
0
 public void ExceptionConstructorCreateTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(exceptionConstructorTypeXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         factory.Create("ApplConfig1");
         Assert.Fail("Should never reach here because we should get a ConfigurationException.");
     }
 }
コード例 #9
0
 public void SectionNameTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderWriter storage = factory.Create(applConfig1) as IStorageProviderWriter;
         Assert.AreEqual(applConfig1, ((XmlFileStorageProvider)storage).CurrentSectionName);
     }
 }
コード例 #10
0
 public void BadTypeTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(badTypeXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         factory.Create("ApplConfig1");
         Assert.Fail("Should not get here");
     }
 }
コード例 #11
0
 public void WriteNonXmlNodeValueTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderWriter storage = factory.Create(applConfig1) as IStorageProviderWriter;
         Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
         storage.Write(new object());
     }
 }
コード例 #12
0
 public void StorageBadFileTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlBadFileString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderWriter storage = factory.Create(applConfig1) as IStorageProviderWriter;
         Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
         storage.Write(GetData());
     }
 }
コード例 #13
0
 public void BadFilePathStorageTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlBadFilePathString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderWriter storage = factory.Create(applConfig1) as IStorageProviderWriter;
         Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
         storage.Write(GetData());
         Assert.Fail("Should never get here since the file is not specified in configuration.");
     }
 }
コード例 #14
0
 public void NoSectionStorageTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(NoSectionXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderReader storage = factory.Create(applConfig1) as IStorageProviderReader;
         Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
         storage.Read();
         Assert.Fail("Should never get here since the section is not specified in the external configuration file.");
     }
 }
コード例 #15
0
 public void StorageTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderReader storage = factory.Create(applConfig1) as IStorageProviderReader;
         Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
         ((IStorageProviderWriter)storage).Write(GetData());
         XmlNode data = storage.Read() as XmlNode;
         Assert.AreEqual(GetData().OuterXml, data.OuterXml);
     }
 }
コード例 #16
0
        public void StorageTestChangeEncryption()
        {
            SaveKeyAlgorithmPair(XmlStringWithEncryption);

            using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlStringWithEncryption))
            {
                StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
                IStorageProviderReader storage = factory.Create(applConfig1) as IStorageProviderReader;
                Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
                ((IStorageProviderWriter)storage).Write(GetData());

                configurationContext.GetMetaConfiguration().ConfigurationSections[0].Encrypt = false;
                factory = new StorageProviderFactory(configurationContext);
                IStorageProviderWriter storageWriter = factory.Create(applConfig1) as IStorageProviderWriter;
                storageWriter.Write(GetData());

                XmlNode data = storageWriter.Read() as XmlNode;
                Assert.AreEqual(GetData().OuterXml, data.OuterXml);
            }
        }
コード例 #17
0
        public void StorageTestWithEncryption()
        {
            SaveKeyAlgorithmPair(XmlStringWithEncryption);
            using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlStringWithEncryption))
            {
                using (FileStream s = new FileStream(Path.GetFullPath(testConfigFile), FileMode.Create))
                {
                    for (int i = 0; i < 1000; i++)
                    {
                        byte b = 0;
                        s.WriteByte(b);
                    }
                }

                StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
                IStorageProviderReader storage = factory.Create(applConfig1) as IStorageProviderReader;
                Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
                ((IStorageProviderWriter)storage).Write(GetData());
                XmlNode data = storage.Read() as XmlNode;
                Assert.AreEqual(GetData().OuterXml, data.OuterXml);
            }
        }
コード例 #18
0
        public void StorageTestChangeEncryption()
        {
            SaveKeyAlgorithmPair(XmlStringWithEncryption);

            using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlStringWithEncryption))
            {
                StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
                IStorageProviderReader storage = factory.Create(applConfig1) as IStorageProviderReader;
                Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
                ((IStorageProviderWriter)storage).Write(GetData());

                configurationContext.GetMetaConfiguration().ConfigurationSections[0].Encrypt = false;
                factory = new StorageProviderFactory(configurationContext);
                IStorageProviderWriter storageWriter = factory.Create(applConfig1) as IStorageProviderWriter;
                storageWriter.Write(GetData());

                XmlNode data = storageWriter.Read() as XmlNode;
                Assert.AreEqual(GetData().OuterXml, data.OuterXml);
            }
        }
コード例 #19
0
 public void NoPathReadWriteTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(NoPathXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         factory.Create(applConfig1);
     }
 }
コード例 #20
0
 public void NoFileStorageTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlNoFileString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderWriter storage = factory.Create(applConfig1) as IStorageProviderWriter;
         Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
         storage.Write(GetData());
         Assert.Fail("Should never get here since the file is not specified in configuration.");
     }
 }
コード例 #21
0
 public void TypeDoesNotImplementTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(notImplXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         factory.Create("ApplConfig1");
     }
 }
コード例 #22
0
 public void NoSectionStorageTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(NoSectionXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderReader storage = factory.Create(applConfig1) as IStorageProviderReader;
         Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
         storage.Read();
         Assert.Fail("Should never get here since the section is not specified in the external configuration file.");
     }
 }
コード例 #23
0
 public void CreateTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(xmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderReader storage = factory.Create("ApplConfig1");
         Assert.IsNotNull(storage);
     }
 }
コード例 #24
0
 public void PrivateConstructorCreateTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(privateConstructorTypeXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         factory.Create("ApplConfig1");
         Assert.Fail("Should never reach here because we should get a ConfigurationException.");
     }
 }
コード例 #25
0
 public void BadSectionTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(notImplXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         factory.Create("Foo");
     }
 }
コード例 #26
0
 public void BadTypeTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(badTypeXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         factory.Create("ApplConfig1");
         Assert.Fail("Should not get here");
     }
 }
コード例 #27
0
 public void SectionNameTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderWriter storage = factory.Create(applConfig1) as IStorageProviderWriter;
         Assert.AreEqual(applConfig1, ((XmlFileStorageProvider)storage).CurrentSectionName);
     }
 }
コード例 #28
0
 public void WriteNullValueTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderWriter storage = factory.Create(applConfig1) as IStorageProviderWriter;
         Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
         storage.Write(null);
     }
 }
コード例 #29
0
 public void StorageTestWithEncryptionAndDpapi()
 {
     SaveKeyAlgorithmPair(XmlStringWithEncryptionAndDpapi);
     using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlStringWithEncryptionAndDpapi))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderReader storage = factory.Create(applConfig1) as IStorageProviderReader;
         Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
         ((IStorageProviderWriter)storage).Write(GetData());
         XmlNode data = storage.Read() as XmlNode;
         Assert.AreEqual(GetData().OuterXml, data.OuterXml);
     }
 }
コード例 #30
0
        public void StorageTestWithEncryption()
        {
            SaveKeyAlgorithmPair(XmlStringWithEncryption);
            using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlStringWithEncryption))
            {
                using( FileStream s = new FileStream(Path.GetFullPath(testConfigFile), FileMode.Create) )
                {
                    for (int i=0; i<1000; i++)
                    {
                        byte b = 0;
                        s.WriteByte(b);
                    }
                }

                StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
                IStorageProviderReader storage = factory.Create(applConfig1) as IStorageProviderReader;
                Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
                ((IStorageProviderWriter)storage).Write(GetData());
                XmlNode data = storage.Read() as XmlNode;
                Assert.AreEqual(GetData().OuterXml, data.OuterXml);
            }
        }
コード例 #31
0
        public void StorageFiresEventTest()
        {
            using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlString))
            {
                StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
                IStorageProviderReader storage = factory.Create(applConfig1) as IStorageProviderReader;
                Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));

                using (IConfigurationChangeWatcher watcher = storage.CreateConfigurationChangeWatcher())
                {
                    watcher.ConfigurationChanged += new ConfigurationChangedEventHandler(OnConfigurationChanged);

                    watcher.StartWatching();
                    Thread.Sleep(100);
                    ((IStorageProviderWriter)storage).Write(GetData());

                    for (int wait = 0; wait < 10 && eventFiredCount < 2; ++wait)
                    {
                        Thread.Sleep(500);
                    }

                    watcher.Dispose();
                }

                Assert.AreEqual(1, eventFiredCount);
            }
        }