public void Test_PropertiesMatch_MocPropertyVsWildCard()
        {
            AuthoriseReferenceStrategyLocator locator = new AuthoriseReferenceStrategyLocator();
            bool propertiesMatch = locator.PropertiesMatch("MockProperty", "*");

            Assert.IsTrue(propertiesMatch, "Didn't match when they should have.");
        }
        public void Test_TypesMatch_UserVsIEntity()
        {
            AuthoriseReferenceStrategyLocator locator = new AuthoriseReferenceStrategyLocator(StrategyState.Strategies);

            bool matches = locator.TypesMatch("User", "IEntity");

            Assert.IsTrue(matches, "Types don't match when they should.");
        }
        public void Test_IsMoreSpecific_EntityVsInterface()
        {
            Type specificType = typeof(MockEntity);
            Type generalType = typeof(IEntity);

            AuthoriseReferenceStrategyLocator locator = new AuthoriseReferenceStrategyLocator(StrategyState.Strategies);
            bool isMoreSpecific = locator.IsMoreSpecific(specificType, generalType);

            Assert.IsTrue(isMoreSpecific, "Returned false when it should be true.");
        }
        public void Test_IsMoreSpecific_EntityVsBaseClass()
        {
            Type specificType = typeof(MockEntity);
            Type generalType  = typeof(BaseEntity);

            AuthoriseReferenceStrategyLocator locator = new AuthoriseReferenceStrategyLocator(StrategyState.Strategies);
            bool isMoreSpecific = locator.IsMoreSpecific(specificType, generalType);

            Assert.IsTrue(isMoreSpecific, "Returned false when it should be true.");
        }
        public void Test_Locate_Basic_MockEntity_PublicEntities_MockPublicEntity()
        {
            StrategyStateNameValueCollection strategies = new StrategyStateNameValueCollection();
            strategies.Clear();
            strategies.Add(typeof(AuthoriseReferenceMockPublicEntityStrategy));

            AuthoriseReferenceStrategyLocator locator = new AuthoriseReferenceStrategyLocator(strategies);

            StrategyInfo strategy = locator.Locate("MockEntity", "PublicEntities", "MockPublicEntity", String.Empty);

            Assert.IsNotNull(strategy, "No strategy found.");

            string expectedType = typeof(AuthoriseReferenceMockPublicEntityStrategy).FullName + ", " + typeof(AuthoriseReferenceMockPublicEntityStrategy).Assembly.GetName().Name;

            Assert.AreEqual(expectedType, strategy.StrategyType, "Wrong strategy info located.");
        }
        public void Test_Locate_Wildcards()
        {
            //StrategyStateNameValueCollection strategies = new StrategyStateNameValueCollection();
            //strategies.Clear();
            //strategies.Add(typeof(AuthoriseReferenceMockPublicEntityStrategy));

            AuthoriseReferenceStrategyLocator locator = new AuthoriseReferenceStrategyLocator(StrategyState.Strategies);

            StrategyInfo strategy = locator.Locate("TestArticle", "PublicEntities", "TestCategory", String.Empty);

            Assert.IsNotNull(strategy, "No strategy found.");

            string expectedType = typeof(AuthoriseReferenceStrategy).FullName + ", " + typeof(AuthoriseReferenceStrategy).Assembly.GetName().Name;

            Assert.AreEqual(expectedType, strategy.StrategyType, "Wrong strategy info located.");
        }
        /// <summary>
        /// Creates a new authorise reference strategy.
        /// </summary>
        /// <param name="typeName"></param>
        /// <returns></returns>
        public IAuthoriseReferenceStrategy NewReferenceAuthoriser(string typeName1, string propertyName1, string typeName2, string propertyName2)
        {
            IAuthoriseReferenceStrategy strategy = null;

            using (LogGroup logGroup = LogGroup.StartDebug("Creating a new authorise reference strategy."))
            {
                LogWriter.Debug("Type name 1: " + typeName1);
                LogWriter.Debug("Property name 1: " + propertyName1);
                LogWriter.Debug("Type name 2: " + typeName2);
                LogWriter.Debug("Property name 2: " + propertyName2);

                AuthoriseReferenceStrategyLocator locator = new AuthoriseReferenceStrategyLocator(StrategyState.Strategies);

                StrategyInfo strategyInfo = locator.Locate(typeName1, propertyName1, typeName2, propertyName2);

                if (strategyInfo != null)
                {
                    strategy = strategyInfo.New <IAuthoriseReferenceStrategy>();
                }
            }

            return(strategy);
        }
        public void Test_TypesMatch_UserVsIEntity()
        {
            AuthoriseReferenceStrategyLocator locator = new AuthoriseReferenceStrategyLocator(StrategyState.Strategies);

            bool matches = locator.TypesMatch("User", "IEntity");

            Assert.IsTrue(matches, "Types don't match when they should.");
        }
        public void Test_PropertiesMatch_MocPropertyVsWildCard()
        {
            AuthoriseReferenceStrategyLocator locator = new AuthoriseReferenceStrategyLocator();
            bool propertiesMatch = locator.PropertiesMatch("MockProperty", "*");

            Assert.IsTrue(propertiesMatch, "Didn't match when they should have.");
        }