コード例 #1
0
        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.");

            }
        }
コード例 #2
0
        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.");
        }
コード例 #3
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.");
        }
コード例 #4
0
        public void Test_CountFiles()
        {
            string applicationName = "TestApplication";

            string applicationPath = TestUtilities.GetTestApplicationPath(this, applicationName);

            string dataDirectoryPath = TestUtilities.GetTestDataPath(this, applicationName);

            string backupDirectoryPath = dataDirectoryPath + Path.DirectorySeparatorChar + "Backup";

            string exportDirectoryPath = dataDirectoryPath + Path.DirectorySeparatorChar + "Export";

            string legacyDirectoryPath = dataDirectoryPath + Path.DirectorySeparatorChar + "Legacy";

            VersionTestUtilities.CreateDummyVersion(dataDirectoryPath, "testing");

            CreateDummyFiles(dataDirectoryPath);

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

            DataAccess.Data.Saver.Save(user);

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

            DataAccess.Data.Saver.Save(role);

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

            DataAccess.Data.Saver.Save(article);

            TestCategory category = new TestCategory();
            category.Name = "Test";

            DataAccess.Data.Saver.Save(category);

            // Export data
            ApplicationBackup backup = new ApplicationBackup();
            backup.BackupDirectoryPath = backupDirectoryPath;
            backup.ExportDirectoryPath = exportDirectoryPath;
            backup.DataDirectoryPath = dataDirectoryPath;

            string zipFilePath = backup.Backup();

            Assert.IsTrue(File.Exists(zipFilePath), "The zip file wasn't created.");

            long total = 0;
            using (ZipAnalyzer analyzer = new ZipAnalyzer(zipFilePath))
            {
                total = analyzer.CountFiles();
            }

            Assert.AreEqual(7, total, "The total number of files in the the zip.");
        }
コード例 #5
0
        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.");

            }
        }
コード例 #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.");
        }
コード例 #7
0
        public void Test_ExportToXml()
        {
            TestUser user = new TestUser();
            user.ID = Guid.NewGuid();
            user.FirstName = "Test";
            user.LastName = "Test";

            DataAccess.Data.Saver.Save(user);

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

            DataAccess.Data.Saver.Save(role);

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

            DataAccess.Data.Saver.Save(article);

            TestCategory category = new TestCategory();
            category.Name = "Test";

            DataAccess.Data.Saver.Save(category);

            string outputDirectory = TestUtilities.GetTestingPath(this) + Path.DirectorySeparatorChar + "Exported";

            int expectedCount = 0;

            foreach (string dataStoreName in DataAccess.Data.GetDataStoreNames())
            {
                foreach (IEntity entity in DataAccess.Data.Stores[dataStoreName].Indexer.GetEntities())
                    expectedCount ++;
            }

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

            exporter.ExportToXml();

            Assert.IsTrue(Directory.Exists(outputDirectory), "The output directory doesn't exist.");

            int fileCount = 0;
            foreach (string directory in Directory.GetDirectories(outputDirectory))
            {
                foreach (String file in Directory.GetFiles(directory))
                {
                    fileCount++;
                }
            }

            Assert.AreEqual(expectedCount, fileCount, "Incorrect number of files found.");
        }
コード例 #8
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.");
        }
コード例 #9
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.");
        }
コード例 #10
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.");
        }
コード例 #11
0
        public void Test_Delete()
        {
            TestArticle article = new TestArticle();
            article.ID = Guid.NewGuid();

            IDeleteStrategy strategy = DeleteStrategy.New<TestArticle>(false);

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

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

            Assert.IsNotNull(foundArticle);

            strategy.Delete(article);

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

            Assert.IsNull(foundArticle2, "The article wasn't deleted.");
        }
コード例 #12
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.");
            }
        }
コード例 #13
0
        public void Test_Index()
        {
            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);

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

            Assert.IsNotNull(foundArticles);

            Assert.AreEqual(2, foundArticles.Length, "Invalid number of test articles found.");
        }
コード例 #14
0
        public void Test_IsMatch_2SubGroups_True()
        {
            TestArticle article = new TestArticle();
            article.ID = Guid.NewGuid();
            article.Title = "Article1";

            // Outer group
            FilterGroup group = new FilterGroup();
            group.Operator = FilterGroupOperator.And; // BOTH child groups MUST match

            FilterGroup subGroup1 = new MockMatchingFilterGroup();
            FilterGroup subGroup2 = new MockMatchingFilterGroup();

            group.Add(subGroup1);
            group.Add(subGroup2);

            Assert.IsTrue(subGroup1.IsMatch(article), "First sub group doesn't match when it should.");
            Assert.IsTrue(subGroup2.IsMatch(article), "Second sub group doesn't match when it should.");

            Assert.IsTrue(group.IsMatch(article), "Entire group failed to match.");
        }
コード例 #15
0
        public void Test_IsMatch_Exclude()
        {
            using (LogGroup logGroup = LogGroup.Start("Testing the PropertyFilter.IsMatch function.", NLog.LogLevel.Debug))
            {
                TestArticle article = new TestArticle();
                article.ID = Guid.NewGuid();

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

                PropertyFilter filter = (PropertyFilter)DataAccess.Data.CreateFilter(typeof(PropertyFilter));
                filter.Operator = FilterOperator.Equal;
                filter.PropertyName = "Title";
                filter.PropertyValue = "MISMATCH"; // Should fail to match
                filter.AddType(typeof(TestArticle));

                bool isMatch = filter.IsMatch(article);
                Assert.IsFalse(isMatch, "The IsMatch function returned true when it should have been false.");

            }
        }
コード例 #16
0
        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.");
        }
コード例 #17
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.");
                }

            }
        }
コード例 #18
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");
        }
コード例 #19
0
        public void Test_GetEntitiesPage_Page1_PageSize2_SortDescending()
        {
            TestArticle article1 = new TestArticle();
            article1.ID = Guid.NewGuid();
            article1.Title = "Article C";

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

            TestArticle article3 = new TestArticle();
            article3.ID = Guid.NewGuid();
            article3.Title = "Article A";

            List<string> titles = new List<string>();
            titles.Add(article1.Title);
            titles.Add(article2.Title);
            titles.Add(article3.Title);

            List<Guid> ids = new List<Guid>();
            ids.Add(article1.ID);
            ids.Add(article2.ID);
            ids.Add(article3.ID);

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

            PagingLocation pagingLocation = new PagingLocation(0, 2);

            string sortExpression = "TitleDescending";

            TestArticle[] entities = DataAccess.Data.Indexer.GetPageOfEntities<TestArticle>(pagingLocation, sortExpression);

            Assert.IsNotNull(entities);

            List<string> titlesFound = new List<string>();
            List<Guid> idsFound = new List<Guid>();

            foreach (TestArticle a in entities)
            {
                Assert.IsFalse(idsFound.Contains(a.ID), "The returned entities list includes more than one entity with the same ID'.");

                Assert.IsFalse(titlesFound.Contains(a.Title), "The returned entities list includes more than one entity with the same title: '" + a.Title + "'.");

                Assert.IsTrue(titles.Contains(a.Title), "The title of one of the retrieved entities doesn't match any of those expected.");

                Assert.IsTrue(ids.Contains(a.ID), "The ID of one of the retrieved entities doesn't match any of those expected.");

                titlesFound.Add(a.Title);
                idsFound.Add(a.ID);
            }

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

            Assert.AreEqual(article1.Title, entities[0].Title, "Sorting failed #1.");
            Assert.AreEqual(article2.Title, entities[1].Title, "Sorting failed #2.");
        }
コード例 #20
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.");
                }
            }
        }
コード例 #21
0
        public void Test_GetEntitiesMatchReference_MultipleReferencedEntities_NoMatch()
        {
            using (LogGroup logGroup = LogGroup.Start("Testing the GetEntitiesMatchReference function and passing multiple referenced entities to ensure it finds entities properly.", NLog.LogLevel.Debug))
            {
                TestArticle article = new TestArticle();
                article.ID = Guid.NewGuid();
                article.Title = "Test Article";

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

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

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

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

                IEntity[] categories = new TestCategory[] { category, category2 };

                TestArticle[] results = DataAccess.Data.Indexer.GetEntitiesWithReference<TestArticle>("Categories", categories);

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

                if (results != null)
                {
                    Assert.AreEqual(0, results.Length, "Incorrect number of results found.");
                }
            }
        }
コード例 #22
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.");
                }
            }
        }
コード例 #23
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.");

            }
        }
コード例 #24
0
        public void Test_Activate_SingleReference()
        {
            using (LogGroup logGroup = LogGroup.Start("Testing the activate function with a single reference.", NLog.LogLevel.Debug))
            {
                TestArticle article = new TestArticle();
                Guid articleID = article.ID = Guid.NewGuid();
                article.Title = "Test";

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

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

                DataAccess.Data.Saver.Save(page);

                DataAccess.Data.Saver.Save(article);

                page = null;
                article = null;

                TestArticlePage page2 = DataAccess.Data.Reader.GetEntity<TestArticlePage>("ID", pageID);

                DataAccess.Data.Activator.Activate(page2, "Article");

                Assert.IsNotNull(page2.Article, "The page2.Article property is null.");

                if (page2.Article != null)
                {

                    Assert.AreEqual(articleID.ToString(), page2.Article.ID.ToString(), "ID of referenced article after activating doesn't match the original.");
                }
            }
        }
コード例 #25
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.");

                }
            }
        }
コード例 #26
0
        public void Test_IsMatch_And_False()
        {
            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 = "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.IsFalse(group.IsMatch(article), "group matched when it should fail");
        }
コード例 #27
0
        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);
            }
        }
コード例 #28
0
        public void Test_IsMatch_Or_True_BothMatch()
        {
            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 = "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");
        }
コード例 #29
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");
        }
コード例 #30
0
        public void Test_Update_DontDuplicate()
        {
            TestArticle article = new TestArticle();
            article.ID = Guid.NewGuid();
            article.Title = "Mock Title";

            DataAccess.Data.Saver.Save(article);

            string newTitle = "Updated";
            article.Title = newTitle;

            DataAccess.Data.Updater.Update(article);

            TestArticle[] foundArticles = DataAccess.Data.Indexer.GetEntities<TestArticle>();

            Assert.IsNotNull(foundArticles);

            Assert.AreEqual(1, foundArticles.Length, "Incorrect number of articles found.");
        }