Exemplo n.º 1
0
        public void Test_IsStored_Reference_NotStored()
        {
            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(article);
                //DataAccess.Data.Saver.Save(category);

                EntityReferenceCollection collection = DataAccess.Data.Referencer.GetActiveReferences(article);
                //.Data.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(false, match, "Reference matched when it shouldn't have.");
                }
            }
        }
Exemplo n.º 2
0
        public void Test_IsMatch_And_True()
        {
            TestArticle article = new TestArticle();

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

            FilterGroup group = new FilterGroup();

            PropertyFilter filter1 = new PropertyFilter();

            filter1.AddType(typeof(TestArticle));
            filter1.PropertyName  = "Title";
            filter1.PropertyValue = article.Title;

            Assert.IsTrue(filter1.IsMatch(article), "filter1 failed to match article when it should.");


            PropertyFilter filter2 = new PropertyFilter();

            filter2.AddType(typeof(TestArticle));
            filter2.PropertyName  = "ID";
            filter2.PropertyValue = article.ID;

            Assert.IsTrue(filter2.IsMatch(article), "filter2 failed to match article when it should.");

            group.Add(filter1);
            group.Add(filter2);

            Assert.IsTrue(group.IsMatch(article), "group failed to match when it should");
        }
        public void Test_Index_PageIndex1_Size2()
        {
            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";

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

            PagingLocation location = new PagingLocation(1, 2);

            IIndexStrategy strategy = IndexStrategy.New <TestArticle>(location, "TitleAscending", false);

            strategy.TypeName     = "TestArticle";
            strategy.EnablePaging = true;

            TestArticle[] foundArticles = Collection <TestArticle> .ConvertAll(strategy.Index());

            Assert.IsNotNull(foundArticles);

            // There should be no articles found because it's requesting a page outside the available range
            Assert.AreEqual(0, foundArticles.Length, "Invalid number of test articles found.");
        }
        public void Test_Index_FilterValues()
        {
            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";

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

            IIndexStrategy strategy = IndexStrategy.New <TestArticle>(false);

            strategy.TypeName = "TestArticle";

            Dictionary <string, object> filterValues = new Dictionary <string, object>();

            filterValues.Add("Title", article.Title);

            TestArticle[] foundArticles = Collection <TestArticle> .ConvertAll(strategy.Index(filterValues));

            Assert.IsNotNull(foundArticles);

            Assert.AreEqual(1, foundArticles.Length, "Invalid number of test articles found.");
        }
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.");
        }
        public void Test_IsMatch()
        {
            using (LogGroup logGroup = LogGroup.Start("Testing the PropertyFilter.IsMatch function.", NLog.LogLevel.Debug))
            {
                TestArticle article = new TestArticle();
                article.ID    = Guid.NewGuid();
                article.Title = "Test Title 1";

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

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

                PropertyFilter filter = (PropertyFilter)DataAccess.Data.CreateFilter(typeof(PropertyFilter));
                filter.Operator      = FilterOperator.Equal;
                filter.PropertyName  = "Title";
                filter.PropertyValue = article.Title;
                filter.AddType(typeof(TestArticle));


                bool isMatch = filter.IsMatch(article);
                Assert.IsTrue(isMatch, "The IsMatch function returned false when it should have been true.");
            }
        }
Exemplo n.º 7
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.");
                }
            }
        }
        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);
            }
        }
        public void Test_IsMatch()
        {
            using (LogGroup logGroup = LogGroup.Start("Testing the ReferenceFilter.IsMatch function.", NLog.LogLevel.Debug))
            {
                TestArticle article = new TestArticle();
                article.ID = Guid.NewGuid();

                TestCategory category = new TestCategory();
                category.ID = Guid.NewGuid();


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

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

                ReferenceFilter filter = (ReferenceFilter)DataAccess.Data.CreateFilter(typeof(ReferenceFilter));
                filter.Operator           = FilterOperator.Equal;
                filter.PropertyName       = "Categories";
                filter.ReferencedEntityID = category.ID;
                filter.ReferenceType      = typeof(TestCategory);
                filter.AddType(typeof(TestArticle));


                bool isMatch = filter.IsMatch(article);
                Assert.IsTrue(isMatch, "The IsMatch function returned false when it should have been true.");
            }
        }
Exemplo n.º 10
0
        public void Test_IsMatch_Or_True_OneMatches()
        {
            TestArticle article = new TestArticle();

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

            FilterGroup group = new FilterGroup();

            group.Operator = FilterGroupOperator.Or;

            PropertyFilter filter1 = new PropertyFilter();

            filter1.AddType(typeof(TestArticle));
            filter1.PropertyName  = "Title";
            filter1.PropertyValue = article.Title;

            Assert.IsTrue(filter1.IsMatch(article), "filter1 failed to match article when it should.");


            PropertyFilter filter2 = new PropertyFilter();

            filter2.AddType(typeof(TestArticle));
            filter2.PropertyName  = "Title";
            filter2.PropertyValue = "MISMATCH";             // This one should fail

            Assert.IsFalse(filter2.IsMatch(article), "filter2 matched when it should fail.");

            group.Add(filter1);
            group.Add(filter2);

            Assert.IsTrue(group.IsMatch(article), "group failed when it should match");
        }
Exemplo n.º 11
0
        public void Test_Index_PageIndex0_Size1()
        {
            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";

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

            PagingLocation location = new PagingLocation(0, 1);

            IIndexStrategy strategy = IndexStrategy.New <TestArticle>(location, "TitleAscending", false);

            strategy.TypeName     = "TestArticle";
            strategy.EnablePaging = true;

            TestArticle[] foundArticles = Collection <TestArticle> .ConvertAll(strategy.Index());

            Assert.IsNotNull(foundArticles);

            Assert.AreEqual(2, location.AbsoluteTotal, "Absolute total invalid.");

            Assert.AreEqual(1, foundArticles.Length, "Invalid number of test articles found.");
        }
Exemplo n.º 12
0
        public void Test_GetPageOfEntitiesWithReference_Page1_PageSize1_SortAscending()
        {
            TestCategory category = new TestCategory();

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

            TestArticle article1 = new TestArticle();

            article1.ID         = Guid.NewGuid();
            article1.Title      = "Article C";
            article1.Categories = new TestCategory[] { category };

            TestArticle article2 = new TestArticle();

            article2.ID         = Guid.NewGuid();
            article2.Title      = "Article B";
            article2.Categories = new TestCategory[] { category };

            TestArticle article3 = new TestArticle();

            article3.ID         = Guid.NewGuid();
            article3.Title      = "Article A";
            article3.Categories = new TestCategory[] { category };

            DataAccess.Data.Saver.Save(category);
            DataAccess.Data.Saver.Save(article3);
            DataAccess.Data.Saver.Save(article2);
            DataAccess.Data.Saver.Save(article1);


            string[] titles = new String[]
            {
                article1.Title,
                article2.Title,
                article3.Title
            };

            PagingLocation pagingLocation = new PagingLocation(0, 1);

            string sortExpression = "TitleAscending";

            TestArticle[] entities = DataAccess.Data.Indexer.GetPageOfEntitiesWithReference <TestArticle>("Categories", typeof(TestCategory), category.ID, pagingLocation, sortExpression);

            Assert.IsNotNull(entities);

            foreach (TestArticle a in entities)
            {
                Assert.Greater(Array.IndexOf(titles, a.Title), -1, "The title of one of the retrieved entities doesn't match any of those expected.");
            }

            Assert.AreEqual(1, entities.Length, "Invalid number found.");

            Assert.AreEqual(article3.Title, entities[0].Title, "Sorting failed #1.");
            //Assert.AreEqual(article2.Title, entities[1].Title, "Sorting failed #2.");
            //Assert.AreEqual(article1.Title, entities[1].Title, "Sorting failed #3.");

            Assert.AreEqual(3, pagingLocation.AbsoluteTotal, "Invalid total");
        }
Exemplo n.º 13
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.");
        }
Exemplo n.º 14
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.º 15
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.º 16
0
        public void Test_IsMatch_EmptyGroup()
        {
            TestArticle article = new TestArticle();

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

            FilterGroup group = new FilterGroup();

            Assert.IsTrue(group.IsMatch(article), "group failed to match when it should match");
        }
Exemplo n.º 17
0
        public void Test_IsValid_EntityParameter_True()
        {
            TestArticle article = new TestArticle();

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

            bool isValid = DataAccess.Data.Importer.IsValid(article);

            Assert.IsTrue(isValid, "Should have returned true.");
        }
        public void RelationshipIdConverter_Converts_FromJsonApiFormat()
        {
            TestArticle testArticle = JsonConvert.DeserializeObject <TestArticle>(jsonApiLiteral, new JsonApiSerializerSettings());

            testArticle.Id.Should().Equals(1);
            testArticle.Title.Should().Equals("JSON API paints my bikeshed!");
            testArticle.Body.Should().Equals("The shortest article. Ever.");
            testArticle.Created.Should().Equals(Convert.ToDateTime("2015-05-22T14:56:29.000Z"));
            testArticle.Updated.Should().Equals(Convert.ToDateTime("2015-05-22T14:56:28.000Z"));
            testArticle.AuthorIds.Should().NotBeNullOrEmpty();
            testArticle.AuthorIds.Should().Contain(new [] { "42", "43", "44", "45" });
        }
Exemplo n.º 19
0
        public void Test_LoadEntitiesFileList()
        {
            TestUser user = new TestUser();

            user.ID        = Guid.NewGuid();
            user.FirstName = "Test";
            user.LastName  = "Test";

            TestRole role = new TestRole();

            role.ID   = Guid.NewGuid();
            role.Name = "Test Role";

            TestArticle article = new TestArticle();

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

            TestCategory category = new TestCategory();

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



            user.Roles = new TestRole[] { role };


            DataExporter exporter = (DataExporter)DataAccess.Data.InitializeDataExporter();

            exporter.ExportDirectoryPath = TestUtilities.GetTestingPath(this) + Path.DirectorySeparatorChar + "Exported";

            // IMPORTANT: Export the references before the entities, because the references are stripped from the entities upon export
            // Alternative is to reactivate the entities and their references using DataAccess.Data.Activator.
            EntityReferenceCollection references = DataAccess.Data.Referencer.GetActiveReferences(user);

            exporter.ExportEntity(references[0]);

            exporter.ExportEntity(user);
            exporter.ExportEntity(role);
            exporter.ExportEntity(article);
            exporter.ExportEntity(category);


            DataImporter importer = (DataImporter)DataAccess.Data.InitializeDataImporter();

            importer.ImportableDirectoryPath = exporter.ExportDirectoryPath;

            string[] fileList = importer.LoadEntitiesFileList();

            Assert.AreEqual(5, fileList.Length, "Incorrect number of files found.");
        }
Exemplo n.º 20
0
        public void Test_React()
        {
            TestArticle article = CreateStrategy.New <TestArticle>(false).Create <TestArticle>();

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

            MockSaveTestArticleStrategy strategy = MockSaveTestArticleStrategy.New(false);

            strategy.Save(article);

            Assert.IsTrue((bool)StateAccess.State.Session["MockSaveTestArticleReaction_Reacted"], "The reaction flag wasn't set to true.");
        }
Exemplo n.º 21
0
        public void Test_Retrieve_ByUniqueKey()
        {
            TestArticle article = new TestArticle();

            article.ID = Guid.NewGuid();

            DataAccess.Data.Saver.Save(article);

            IRetrieveStrategy strategy = RetrieveStrategy.New <TestArticle>(false);

            IEntity foundArticle = strategy.Retrieve <TestArticle>(article.UniqueKey);

            Assert.IsNotNull(foundArticle, "Test article wasn't retrieved.");
        }
Exemplo n.º 22
0
        public void Test_CopyTo_TestArticle()
        {
            TestArticle article1 = new TestArticle();

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


            TestArticle article2 = new TestArticle();

            article1.CopyTo(article2);

            Assert.AreEqual(article1.Title, article2.Title, "The title wasn't transferred.");
        }
Exemplo n.º 23
0
        public void Test_Save()
        {
            TestArticle article = CreateStrategy.New <TestArticle>(false).Create <TestArticle>();

            article.ID = Guid.NewGuid();

            StrategyInfo  info     = StrategyState.Strategies["Save", "IEntity"];
            ISaveStrategy strategy = SaveStrategy.New <TestArticle>(false);

            strategy.Save(article);

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

            Assert.IsNotNull(foundArticle);
        }
Exemplo n.º 24
0
        public void Test_Retrieve_ByCustomProperty()
        {
            TestArticle article = new TestArticle();

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

            DataAccess.Data.Saver.Save(article);

            IRetrieveStrategy strategy = RetrieveStrategy.New <TestArticle>(false);

            IEntity foundArticle = strategy.Retrieve <TestArticle>("Title", article.Title);

            Assert.IsNotNull(foundArticle, "Test article wasn't retrieved.");
        }
Exemplo n.º 25
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.");
                }
            }
        }
Exemplo n.º 26
0
        public void Test_Delete_Reorder()
        {
            using (LogGroup logGroup = LogGroup.StartDebug("Testing deletion of sub entities to ensure their position is updated."))
            {
                TestArticle article = CreateStrategy.New <TestArticle>(false).Create <TestArticle>();

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

                SaveStrategy.New(article, false).Save(article);

                Collection <TestArticlePage> pages = new Collection <TestArticlePage>();

                // Create and save 3 article pages associated with the article
                for (int i = 0; i < 3; i++)
                {
                    TestArticlePage page = CreateStrategy.New <TestArticlePage>(false).Create <TestArticlePage>();
                    page.Article    = article;
                    page.Title      = "Page " + (i + 1);
                    page.ID         = Guid.NewGuid();
                    page.PageNumber = i + 1;

                    pages.Add(page);

                    SaveStrategy.New(page, false).Save(page);
                }

                // Delete the second page (0 based position = 1)
                DeleteStrategy.New(pages[1], false).Delete(pages[1]);

                // Load the article from the store
                TestArticle foundArticle = RetrieveStrategy.New <TestArticle>(false).Retrieve <TestArticle>("ID", article.ID);

                // Activate the pages on the article
                ActivateStrategy.New(foundArticle, false).Activate(foundArticle, "Pages");

                Assert.IsNotNull(foundArticle.Pages, "Pages property isn't set.");

                Assert.AreEqual(2, foundArticle.Pages.Length, "Invalid number of pages.");

                foundArticle.Pages = Collection <TestArticlePage> .Sort(foundArticle.Pages, "PageNumberAscending");

                Assert.AreEqual(1, foundArticle.Pages[0].PageNumber, "First page has wrong number.");
                Assert.AreEqual("Page 1", foundArticle.Pages[0].Title, "First page has wrong title.");
                Assert.AreEqual(2, foundArticle.Pages[1].PageNumber, "Third page has wrong number (should now be 2 as it's moved up one spot).");
                Assert.AreEqual("Page 3", foundArticle.Pages[1].Title, "Third page has wrong title.");                 // Page 3 should now be at position 1 (ie. second place)
            }
        }
Exemplo n.º 27
0
        public void Test_Create_Parent()
        {
            MockProjection projection = new MockProjection();

            projection.RequireAuthorisation = false;
            projection.Command = new CreateComandInfo(typeof(TestArticlePage).Name);

            TestArticle article = CreateStrategy.New <TestArticle>(false).Create <TestArticle>();

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

            SaveStrategy.New <TestArticle>(false).Save(article);

            CreateController controller = CreateController.New(projection);

            Assert.IsTrue(controller is CreateSubEntityController, "Invalid controller type: " + controller.GetType().ToString());

            CreateSubEntityController createSubEntityController = (CreateSubEntityController)controller;

            ISubEntity subEntity = (ISubEntity)createSubEntityController.Create(article.ID, String.Empty);

            Assert.IsNotNull(subEntity, "No sub entity returned.");

            Assert.IsTrue((subEntity is TestArticlePage), "Wrong type returned: " + subEntity.GetType().ToString());

            Assert.IsNotNull(subEntity.Parent, "No parent assigned to sub entity.");

            Assert.AreEqual(article.ID.ToString(), subEntity.Parent.ID.ToString(), "Parent ID doesn't match expected.");

            Assert.AreEqual(1, subEntity.Number, "Sub entity has wrong number.");

            SaveStrategy.New(subEntity, false).Save(subEntity);


            ISubEntity subEntity2 = (ISubEntity)createSubEntityController.Create(Guid.Empty, article.UniqueKey);

            Assert.IsNotNull(subEntity2, "No sub entity returned.");

            Assert.IsTrue((subEntity2 is TestArticlePage), "Wrong type returned: " + subEntity.GetType().ToString());

            Assert.IsNotNull(subEntity2.Parent, "No parent assigned to sub entity.");

            Assert.AreEqual(article.ID.ToString(), subEntity2.Parent.ID.ToString(), "Parent ID doesn't match expected.");

            Assert.AreEqual(2, subEntity2.Number, "Sub entity has wrong number.");
        }
        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.");
        }
        public void Test_Create_FromParentID()
        {
            TestArticle article = CreateStrategy.New <TestArticle>(false).Create <TestArticle>();

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

            SaveStrategy.New <TestArticle>(false).Save(article);

            CreateSubEntityStrategy strategy = (CreateSubEntityStrategy)CreateStrategy.New("TestArticlePage", false);

            TestArticlePage page = strategy.Create <TestArticlePage>(article.ID, String.Empty);

            Assert.IsNotNull(page.Article, "The article wasn't assigned to the page.");

            Assert.AreEqual(article.Title, page.Article.Title, "Article titles don't match.");

            Assert.AreEqual(1, page.PageNumber, "Invalid page number");
        }