Example #1
0
        public void ConfigHandler_IvalidModeType_ExceptionExpected()
        {
            InAnotherCastleHandler handler = new InAnotherCastleHandler();

            var type = typeof(MockProvider);

            SetConfigurationSection(type.AssemblyQualifiedName);
            InAnotherCastleHandler.RefreshConfiguration();
            var mockProvider = (MockProvider)InAnotherCastleHandler.Configuration.ServiceProvider;
            var testCach     = (MockProvider.MockCache)(mockProvider).GetConfigCacheValue;

            testCach.ExecuteCache = true;

            //Allow the cache function to execute the get section functionality within the handler

            handler.Parser = new TestParser()
            {
                ParseRedirectDetailsValue = (xml) => new MockRedirectIdentifier()
                {
                    Type = typeof(object).AssemblyQualifiedName,
                    Mode = (Mode)11111,// Invalid mode, in the file this may be some invalid text
                },
            };

            XmlDocument document = new XmlDocument();

            document.LoadXml("<Test></Test>");

            var resultingObject = handler.Create(null, null, document.FirstChild);
        }
Example #2
0
        public void ConfigHandler_Poco_FromRedirectBody_ShouldCallIntoParserWithXmlValue()
        {
            InAnotherCastleHandler handler = new InAnotherCastleHandler();

            object expectedObject = new TestResultObject();

            string expectedXml          = "<TestPassedIn></TestPassedIn>";
            int    expectedCachDuration = 919191;


            //Setup mock components used by handler
            var type = typeof(MockProvider);

            SetConfigurationSection(type.AssemblyQualifiedName);
            InAnotherCastleHandler.RefreshConfiguration();
            //Allow the cache function to execute the get section functionality within the handler
            var mockProvider = (MockProvider)InAnotherCastleHandler.Configuration.ServiceProvider;
            var testCach     = (MockProvider.MockCache)(mockProvider).GetConfigCacheValue;

            testCach.ExecuteCache = true;
            var mockStorage = (MockProvider.MockStorage)mockProvider.GetStorageValue;

            mockStorage.GetConfigurationSectionFunc = (n, s) =>
            {
                Assert.Fail("There should be no reason for the handler to use the storage function if the POCO body is set in the parser.");
                return(null);
            };

            string resultingXml = null;

            handler.Parser = new TestParser()
            {
                ParseRedirectDetailsValue = (xml) => new MockRedirectIdentifier()
                {
                    Type = typeof(TestResultObject).AssemblyQualifiedName,
                    Mode = Mode.Poco,
                    CacheDurationInMinutes = expectedCachDuration,
                    //Note poco body is populated so it should be used instead of a db call
                    PocoBody = new PocoBody()
                    {
                        Value = expectedXml
                    }
                },
                POCOConfigSectionParseValue = (xml, t) =>
                {
                    resultingXml = xml;
                    return(expectedObject);
                }
            };

            XmlDocument document = new XmlDocument();

            document.LoadXml("<TestSectionName></TestSectionName>");
            var resultingObject = handler.Create(null, null, document.FirstChild);

            Assert.AreEqual(resultingObject, expectedObject, "Object returned should be the expected as it has been mocked in the pipeline");
            Assert.AreEqual(resultingXml, expectedXml, "XML is expected to be based on the mock");
        }
Example #3
0
        public void ConfigHandler_ConfigProvider_ProperType_InstanceCreated()
        {
            var type = typeof(MockProvider);

            SetConfigurationSection(type.AssemblyQualifiedName);
            InAnotherCastleHandler.RefreshConfiguration();
            Assert.AreEqual(InAnotherCastleHandler.Configuration.ServiceProviderTypeName, type.AssemblyQualifiedName, "Name should be the same as what was given from config");
            Assert.IsInstanceOfType(InAnotherCastleHandler.Configuration.ServiceProvider, type, "Should be of the type passed in");
        }
Example #4
0
        public void ConfigHandler_ResetConfigWithInstanceFromConfig_PreviousInstanceDisposed()
        {
            var type = typeof(MockProvider);

            SetConfigurationSection(type.AssemblyQualifiedName);
            InAnotherCastleHandler.RefreshConfiguration();

            var first  = (MockProvider)InAnotherCastleHandler.Configuration.ServiceProvider;
            var second = new MockProvider();

            InAnotherCastleHandler.Configuration = new TestConfiguration()
            {
                ServiceProvider = second
            };

            Assert.IsTrue(first.WasDisposed, "Replaced providers should be disposed");
        }
Example #5
0
        public void ConfigHandler_SetConfigWhenNull_ConfigIsSet()
        {
            var type = typeof(MockProvider);

            SetConfigurationSection(type.AssemblyQualifiedName);
            InAnotherCastleHandler.ClearConfig();
            InAnotherCastleHandler handler = new InAnotherCastleHandler();

            var parser = new TestParser();

            handler.Parser = parser;

            XmlDocument document = new XmlDocument();

            document.LoadXml("<Test></Test>");

            var resultingObject = handler.Create(null, null, document.FirstChild);

            Assert.AreEqual(InAnotherCastleHandler.Configuration.ServiceProviderTypeName, type.AssemblyQualifiedName, "Name should be the same as what was given from config");
            Assert.IsInstanceOfType(InAnotherCastleHandler.Configuration.ServiceProvider, type, "Should be of the type passed in");

            Assert.IsNull(resultingObject, "The default test cache return is empty");
        }
Example #6
0
        public void ConfigHandler_Poco_FromDataStore_ShouldCallIntoParserWithXmlValue()
        {
            InAnotherCastleHandler handler = new InAnotherCastleHandler();

            object expectedObject = new TestResultObject();

            string             expectedName               = "TestName";
            string             expectedSystemName         = "SystemName";
            string             expectedXml                = "<TestPassedIn></TestPassedIn>";
            int                expectedCachDuration       = 919191;
            ConfigurationValue expectedConfigurationValue = new ConfigurationValue()
            {
                XML = expectedXml
            };

            //Setup mock components used by handler
            var type = typeof(MockProvider);

            SetConfigurationSection(type.AssemblyQualifiedName);
            InAnotherCastleHandler.RefreshConfiguration();
            //Allow the cache function to execute the get section functionality within the handler
            var mockProvider = (MockProvider)InAnotherCastleHandler.Configuration.ServiceProvider;
            var testCach     = (MockProvider.MockCache)(mockProvider).GetConfigCacheValue;

            testCach.ExecuteCache = true;
            var    mockStorage = (MockProvider.MockStorage)mockProvider.GetStorageValue;
            string resultingName = null, resultingSystemName = null, resultingXml = null;

            mockStorage.GetConfigurationSectionFunc = (n, s) =>
            {
                resultingName       = n;
                resultingSystemName = s;
                return(expectedConfigurationValue);
            };
            handler.Parser = new TestParser()
            {
                ParseRedirectDetailsValue = (xml) => new MockRedirectIdentifier()
                {
                    Type                   = typeof(TestResultObject).AssemblyQualifiedName,
                    Name                   = expectedName,
                    SystemName             = expectedSystemName,
                    Mode                   = Mode.Poco,
                    CacheDurationInMinutes = expectedCachDuration
                },
                POCOConfigSectionParseValue = (xml, t) =>
                {
                    resultingXml = xml;
                    return(expectedObject);
                }
            };

            XmlDocument document = new XmlDocument();

            document.LoadXml("<Test></Test>");
            var resultingObject = handler.Create(null, null, document.FirstChild);

            Assert.AreEqual(resultingObject, expectedObject, "Object returned should be the expected as it has been mocked in the pipeline");
            Assert.AreEqual(resultingName, expectedName, "Name is expected based on mock");
            Assert.AreEqual(resultingSystemName, expectedSystemName, "System Name is expected based on mock");
            Assert.AreEqual(resultingXml, expectedXml, "XML is expected to be based on the mock");
        }
Example #7
0
 public void ConfigHandler_ConfigProviderMissing_DefaultConfigurationUsed()
 {
     ClearConfiguration();
     InAnotherCastleHandler.RefreshConfiguration();
     Assert.IsInstanceOfType(InAnotherCastleHandler.Configuration.ServiceProvider, typeof(DefaultServiceProvider), "Should be of the type default packaged with this library");
 }
Example #8
0
 public void ConfigHandler_ConfigProvider_InvalidTypeName_ExceptionThrown()
 {
     SetConfigurationSection("Invalid Type Name here");
     InAnotherCastleHandler.RefreshConfiguration();
 }
Example #9
0
 public void ConfigHandler_ConfigProvider_NoType_ExceptionThrown()
 {
     SetConfigurationSection(null);//Null for typed
     InAnotherCastleHandler.RefreshConfiguration();
 }