Exemplo n.º 1
0
        public void Test_IsMultipleReference_True()
        {
            TestArticle article = new TestArticle();

            PropertyInfo property = article.GetType().GetProperty("Categories");

            Assert.IsTrue(EntitiesUtilities.IsMultipleReference(article.GetType(), property), "Returned false when it should have returned true.");
        }
Exemplo n.º 2
0
        public void Test_IsReference_False()
        {
            TestArticle article = new TestArticle();

            PropertyInfo property = article.GetType().GetProperty("ID");

            Assert.IsFalse(EntitiesUtilities.IsReference(article.GetType(), property), "Returned true when it should have returned false.");
        }
        public void Test_MatchReference_Opposite()
        {
            using (LogGroup logGroup = LogGroup.Start("Testing the MatchReference function to ensure matches properly.", NLog.LogLevel.Debug))
            {
                TestArticle article = new TestArticle();
                article.ID    = Guid.NewGuid();
                article.Title = "Test Article";

                TestCategory category = new TestCategory();
                category.ID   = Guid.NewGuid();
                category.Name = "Test Category";

                article.Categories = new TestCategory[] { category };

                DataAccess.Data.Saver.Save(category);
                DataAccess.Data.Saver.Save(article);

                bool match  = DataAccess.Data.Referencer.MatchReference(article.GetType(), article.ID, "Categories", category.GetType(), category.ID, "Articles");
                bool match2 = DataAccess.Data.Referencer.MatchReference(category.GetType(), category.ID, "Articles", article.GetType(), article.ID, "Categories");

                Assert.IsTrue(match, "Didn't match on standard check.");
                Assert.IsTrue(match2, "Didn't match on reverse check.");


                DataAccess.Data.Deleter.Delete(article);
                DataAccess.Data.Deleter.Delete(category);
            }
        }
Exemplo n.º 4
0
        public void Test_GetEntitiesMatchReference()
        {
            using (LogGroup logGroup = LogGroup.Start("Testing the GetEntitiesMatchReference function to ensure it finds entities properly.", NLog.LogLevel.Debug))
            {
                TestArticle article = new TestArticle();
                article.ID    = Guid.NewGuid();
                article.Title = "Test Article";

                TestCategory category = new TestCategory();
                category.ID   = Guid.NewGuid();
                category.Name = "Test Category";

                article.Categories = new TestCategory[] { category };

                DataAccess.Data.Saver.Save(category);
                DataAccess.Data.Saver.Save(article);

                IEntity[] results = DataAccess.Data.Indexer.GetEntitiesWithReference <TestArticle>("Categories", typeof(TestCategory), category.ID);

                Assert.IsNotNull(results, "The results were null.");

                if (results != null)
                {
                    Assert.AreEqual(1, results.Length, "Incorrect number of results found.");

                    IEntity entity = results[0];

                    Assert.AreEqual(article.GetType().FullName, entity.GetType().FullName, "The types don't match.");
                }
            }
        }
Exemplo n.º 5
0
        public void Test_IsEntity_True()
        {
            TestArticle article = new TestArticle();


            Assert.IsTrue(EntitiesUtilities.IsEntity(article.GetType()), "Returned false when it should have returned true.");
        }
Exemplo n.º 6
0
        public void Test_GetFieldName()
        {
            TestArticle article = new TestArticle();

            article.ID = Guid.NewGuid();

            string fieldName = EntitiesUtilities.GetFieldName(article.GetType(), "Title");

            Assert.AreEqual("title", fieldName, "Incorrect field name returned.");
        }
Exemplo n.º 7
0
        public virtual void Test_GetEntitiesPageMatchReference()
        {
            using (LogGroup logGroup = LogGroup.Start("Testing the GetEntitiesPageMatchReference function to ensure it finds entities properly.", NLog.LogLevel.Debug))
            {
                TestArticle article = new TestArticle();
                article.ID    = Guid.NewGuid();
                article.Title = "Test Article";

                TestCategory category = new TestCategory();
                category.ID   = Guid.NewGuid();
                category.Name = "Test Category";

                TestArticle article2 = new TestArticle();
                article2.ID    = Guid.NewGuid();
                article2.Title = "Test Article 2";

                TestCategory category2 = new TestCategory();
                category2.ID   = Guid.NewGuid();
                category2.Name = "Test Category 2";

                article.Categories = new TestCategory[] { category, category2 };

                article2.Categories = new TestCategory[] { category, category2 };

                DataAccess.Data.Saver.Save(category2);
                DataAccess.Data.Saver.Save(category);
                DataAccess.Data.Saver.Save(article);
                DataAccess.Data.Saver.Save(article2);


                PagingLocation location = new PagingLocation(0, 10);

                IEntity[] results = DataAccess.Data.Indexer.GetPageOfEntitiesWithReference <TestArticle>("Categories", typeof(TestCategory), category.ID, location, "TitleAscending");

                Assert.IsNotNull(results, "The results were null.");

                Assert.AreEqual(2, location.AbsoluteTotal, "The absolute total count is incorrect.");

                if (results != null)
                {
                    Assert.AreEqual(2, results.Length, "Incorrect number of results found.");

                    IEntity entity = results[0];

                    Assert.AreEqual(article.GetType().FullName, entity.GetType().FullName, "The types don't match.");
                }
            }
        }
        public virtual void Test_MatchReference()
        {
            using (LogGroup logGroup = LogGroup.Start("Testing the MatchReference function to ensure matches properly.", NLog.LogLevel.Debug))
            {
                TestArticle article = new TestArticle();
                article.ID    = Guid.NewGuid();
                article.Title = "Test Article";

                TestCategory category = new TestCategory();
                category.ID   = Guid.NewGuid();
                category.Name = "Test Category";

                TestArticle article2 = new TestArticle();
                article2.ID    = Guid.NewGuid();
                article2.Title = "Test Article 2";

                TestCategory category2 = new TestCategory();
                category2.ID   = Guid.NewGuid();
                category2.Name = "Test Category 2";

                article.Categories = new TestCategory[] { category };

                EntityReference originalReference = DataAccess.Data.Referencer.GetActiveReferences(article)[0];

                LogWriter.Debug("Original reference - Entity 1 ID: " + originalReference.Entity1ID.ToString());
                LogWriter.Debug("Original reference - Entity 2 ID: " + originalReference.Entity2ID.ToString());
                LogWriter.Debug("Original reference - Property 1 name: " + originalReference.Property1Name);
                LogWriter.Debug("Original reference - Property 2 name: " + originalReference.Property2Name);
                LogWriter.Debug("Original reference - Type 1 name: " + originalReference.Type1Name);
                LogWriter.Debug("Original reference - Type 2 name: " + originalReference.Type2Name);

                foreach (EntityReference r in DataAccess.Data.Referencer.GetActiveReferences(article))
                {
                    DataAccess.Data.Saver.Save(r);
                }

                string mirrorPropertyName = EntitiesUtilities.GetMirrorPropertyName(article,
                                                                                    EntitiesUtilities.GetProperty(article.GetType(), "Categories", typeof(TestCategory[])));

                bool match = DataAccess.Data.Referencer.MatchReference(article.GetType(), article.ID, "Categories", category.GetType(), category.ID, mirrorPropertyName);

                Assert.IsTrue(match, "Didn't match when it should have.");

                DataAccess.Data.Deleter.Delete(article);
                DataAccess.Data.Deleter.Delete(category);
            }
        }
        public void Test_Validate()
        {
            TestArticle article = new TestArticle();

            article.ID    = Guid.NewGuid();
            article.Title = "Test Title";

            TestArticle article2 = new TestArticle();

            article2.ID    = Guid.NewGuid();
            article2.Title = "Test Title 2";

            TestArticle article3 = new TestArticle();

            article3.ID    = Guid.NewGuid();
            article3.Title = article2.Title;

            DataAccess.Data.Saver.Save(article);
            DataAccess.Data.Saver.Save(article2);

            IValidateUniqueStrategy strategy = new ValidateUniqueStrategy();

            // Check that the strategy was found
            Assert.IsNotNull(strategy);

            PropertyInfo titleProperty = article2.GetType().GetProperty("Title");

            // Execute the validate function on the strategy
            bool isUnique = strategy.IsValid(article2, titleProperty, new UniqueAttribute());

            // Check that the validate function returned true
            Assert.IsTrue(isUnique, "The Validate function returned false when it shouldn't have.");

            article3.Title = article2.Title;

            PropertyInfo titleProperty2 = article3.GetType().GetProperty("Title");

            // Execute the validate function on the strategy and expect it to fail
            bool isNotUnique = strategy.IsValid(article3, titleProperty2, new UniqueAttribute());

            // Check that the validate function returned false when it's supposed to
            Assert.IsFalse(isNotUnique, "The Validate function returned true when it shouldn't have.");
        }
Exemplo n.º 10
0
        public void Test_GetDataStoreName_FromNames()
        {
            using (LogGroup logGroup = LogGroup.Start("Testing the GetDataStoreName function from a provided type.", NLog.LogLevel.Debug))
            {
                TestArticle e1 = new TestArticle();
                e1.ID    = Guid.NewGuid();
                e1.Title = "Test 1";


                TestArticlePage e2 = new TestArticlePage();
                e2.ID    = Guid.NewGuid();
                e2.Title = "Test 2";

                //e2.ArticleID = e1.ID;

                string name = DataUtilities.GetDataStoreName(e1.GetType().Name, e2.GetType().Name);


                Assert.AreEqual(e1.ShortTypeName + "-" + e2.ShortTypeName, name, "The wrong data store name was returned.");
            }
        }
        public virtual void Test_MatchReference_Exclusion()
        {
            using (LogGroup logGroup = LogGroup.Start("Testing the MatchReference function to ensure excludes properly.", NLog.LogLevel.Debug))
            {
                TestArticle article = new TestArticle();
                article.ID    = Guid.NewGuid();
                article.Title = "Test Article";

                TestCategory category = new TestCategory();
                category.ID   = Guid.NewGuid();
                category.Name = "Test Category";

                TestArticle article2 = new TestArticle();
                article2.ID    = Guid.NewGuid();
                article2.Title = "Test Article 2";

                TestCategory category2 = new TestCategory();
                category2.ID   = Guid.NewGuid();
                category2.Name = "Test Category 2";

                // Must remain commented out to test exclusion
                article.Categories  = new TestCategory[] { category };
                article2.Categories = new TestCategory[] { category2 };

                DataAccess.Data.Saver.Save(category2);
                DataAccess.Data.Saver.Save(category);
                DataAccess.Data.Saver.Save(article);
                DataAccess.Data.Saver.Save(article2);

                bool match = DataAccess.Data.Referencer.MatchReference(article.GetType(), article.ID, "Categories", category2.GetType(), category2.ID);

                Assert.IsFalse(match, "Matched when it shouldn't have.");

                DataAccess.Data.Deleter.Delete(article);
                DataAccess.Data.Deleter.Delete(category);
            }
        }
Exemplo n.º 12
0
        public virtual void Test_Activate_SingleProperty_2References()
        {
            using (LogGroup logGroup = LogGroup.Start("Testing the Activate function with 2 references.", NLog.LogLevel.Debug))
            {
                TestArticle article = new TestArticle();
                article.ID = Guid.NewGuid();
                Guid articleID = article.ID;
                article.Title = "Test";

                TestArticlePage page = new TestArticlePage();
                page.ID = Guid.NewGuid();
                Guid pageID = page.ID;
                page.Title = "Test Page";

                TestArticlePage page2 = new TestArticlePage();
                page2.ID = Guid.NewGuid();
                Guid page2ID = page2.ID;
                page2.Title = "Test Page 2";

                article.Pages = new TestArticlePage[] { page, page2 };
                //user.Roles = Collection<TestRole>.Add(user.Roles, role);

                DataAccess.Data.Saver.Save(page);
                DataAccess.Data.Saver.Save(page2);

                DataAccess.Data.Saver.Save(article);

                //  TODO: Check if needed
                //page = null;
                //page2 = null;
                //article = null;

                EntityReferenceCollection references = DataAccess.Data.Referencer.GetReferences(article.GetType().Name, page.GetType().Name);

                Assert.IsNotNull(references, "references == null");

                Assert.AreEqual(2, references.Count, "Invalid number of references found.");


                TestArticle foundArticle = DataAccess.Data.Reader.GetEntity <TestArticle>("ID", articleID);

                Assert.IsNotNull(foundArticle, "The foundArticle variable is null.");

                DataAccess.Data.Activator.Activate(foundArticle, "Pages");



                Assert.IsNotNull(foundArticle.Pages, "The article.Pages property is null.");
                Assert.AreEqual(2, foundArticle.Pages.Length, "article.Pages.Length != 2.");

                if (foundArticle.Pages != null && foundArticle.Pages.Length == 2)
                {
                    TestArticlePage foundPage1 = foundArticle.Pages[0];
                    TestArticlePage foundPage2 = foundArticle.Pages[1];

                    //if (foundPage2.ID.ToString() == pageID.ToString())
                    //{
                    //	TestArticlePage tmp = foundPage2;
                    //	foundPage2 = foundPage1;
                    //	foundPage1 = tmp;
                    //}

                    // Use an array and IndexOf function so the match will work in any order
                    Guid[] pageIDs = new Guid[] { pageID, page2ID };

                    Assert.IsTrue(Array.IndexOf(pageIDs, foundPage1.ID) > -1, "First found page has the wrong ID.");
                    Assert.IsTrue(Array.IndexOf(pageIDs, foundPage2.ID) > -1, "Second found page has the wrong ID.");

                    //Assert.AreEqual(pageID.ToString() + "---" + page2ID.ToString(), foundPage1.ID.ToString() + "---" + foundPage2.ID.ToString(), "IDs of the reference don't match.");
                }
            }
        }
Exemplo n.º 13
0
        public void Test_Activate_2References_Async_Converging()
        {
            using (LogGroup logGroup = LogGroup.Start("Testing the Activate function with 2 asynchronous, converging references.", NLog.LogLevel.Debug))
            {
                TestArticle article = new TestArticle();
                article.ID = Guid.NewGuid();
                Guid articleID = article.ID;
                article.Title = "Test";

                TestUser user = new TestUser();
                user.ID = Guid.NewGuid();
                Guid userID = user.ID;
                user.FirstName = "First";
                user.LastName  = "Last";
                user.Username  = "******";
                user.Password  = "******";

                /*TestArticlePage page = new TestArticlePage();
                 * page.ID = Guid.NewGuid();
                 * Guid pageID = page.ID;
                 * page.Title = "Test Page";
                 *
                 * TestArticlePage page2 = new TestArticlePage();
                 * page2.ID = Guid.NewGuid();
                 * Guid page2ID = page2.ID;
                 * page2.Title = "Test Page 2";
                 */
                //article.Pages = new TestArticlePage[] {page, page2};
                //user.Roles = Collection<TestRole>.Add(user.Roles, role);

                article.Editors = new TestUser[] { user };

                //DataAccess.Data.Saver.Save(page);
                //DataAccess.Data.Saver.Save(page2);

                DataAccess.Data.Saver.Save(user);
                DataAccess.Data.Saver.Save(article);

                //  TODO: Check if needed
                //page = null;
                //page2 = null;
                //article = null;

                EntityReferenceCollection references = DataAccess.Data.Referencer.GetReferences(article.GetType().Name, user.GetType().Name);

                Assert.IsNotNull(references, "references == null");

                Assert.AreEqual(1, references.Count, "Invalid number of references found.");


                TestArticle foundArticle = DataAccess.Data.Reader.GetEntity <TestArticle>("ID", articleID);

                Assert.IsNotNull(foundArticle, "The foundArticle variable is null.");

                DataAccess.Data.Activator.Activate(foundArticle, "Editors");
                DataAccess.Data.Activator.Activate(foundArticle, "Authors");



                Assert.IsNotNull(foundArticle.Editors, "The article.Editors property is null.");
                Assert.AreEqual(1, foundArticle.Editors.Length, "article.Editors.Length != 1.");

                if (foundArticle.Editors != null && foundArticle.Editors.Length == 1)
                {
                    TestUser foundUser1 = foundArticle.Editors[0];

                    // Use an array and IndexOf function so the match will work in any order
                    Guid[] userIDs = new Guid[] { userID };

                    Assert.AreEqual(userID.ToString(), foundUser1.ID.ToString(), "The IDs of the user in Editors property doesn't match expected.");
                }

                Assert.AreEqual(0, foundArticle.Authors.Length, "Authors found when they shouldn't be. The two properties must be getting mixed up.");
            }
        }
Exemplo n.º 14
0
        public void Test_IsStored_Reference()
        {
            using (LogGroup logGroup = LogGroup.Start("Testing the IsStored function on a reference object", NLog.LogLevel.Debug))
            {
                TestArticle article = new TestArticle();
                article.ID    = Guid.NewGuid();
                article.Title = "Test Article";

                TestCategory category = new TestCategory();
                category.ID   = Guid.NewGuid();
                category.Name = "Test Category";

                article.Categories = new TestCategory[] { category };

                DataAccess.Data.Saver.Save(category);
                DataAccess.Data.Saver.Save(article);

                EntityReferenceCollection collection = DataAccess.Data.Referencer.GetReferences(article.GetType(), article.ID, "Categories", category.GetType(), false);

                Assert.IsNotNull(collection, "Reference collection is null.");

                if (collection != null)
                {
                    Assert.AreEqual(1, collection.Count, "Incorrect number of references found.");
                }

                foreach (EntityReference reference in collection)
                {
                    bool match = DataAccess.Data.IsStored(reference);

                    Assert.AreEqual(true, match, "Reference wasn't detected.");
                }
            }
        }