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."); } } }
public void Update(TestCategoryDTO entity) { TestCategory category = _mapper.Map <TestCategory>(entity); _unitOfWork.TestCategories.Update(category); _unitOfWork.SaveChanges(); }
public async Task <TestCategory> PostTestCategory(TestCategory testCategory) { db.testCategory.Add(testCategory); await db.SaveChangesAsync(); return(testCategory); }
/// <summary> /// Returns number of failed tests for given test category. /// </summary> /// <param name="category">The test category of interest.</param> /// <returns>The score</returns> public int GetCategoryFailedCount(TestCategory category) { if (category == TestCategory.MessageSerialization) { int count = 0; foreach (MessageTestState testState in MessageTestStates.Values) { if (testState.Result == false) { count++; } } return(count); } else { int count = 0; foreach (TestState testState in TestStates[category].Values) { if (testState.Result == false) { count++; } } return(count); } }
public async Task <ActionResult> AddTestCategory(TestCategory testCat) { ModelState.Remove(nameof(testCat.Id)); ModelState.Remove(nameof(testCat.Created)); ModelState.Remove(nameof(testCat.LastChange)); ModelState.Remove(nameof(testCat.ChangedBy)); if (ModelState.IsValid) { var userRepository = new ApplicationUserRepository <Admin>(); var currentUser = userRepository.GetByUserNameAsync(User.Identity.Name); TestCategory _testCat = new TestCategory() { Name = testCat.Name, Description = testCat.Description, Valid = testCat.Valid, Created = DateTime.Now, LastChange = DateTime.Now, ChangedBy = await currentUser }; new TestCategoryRepository().Create(_testCat); TempData["success"] = "Test category was added"; } else { return(View("CreateTestCategory", testCat)); } return(RedirectToAction("TestCategories")); }
public async Task <ActionResult> UpdateTestCategory(TestCategory testCat) { ModelState.Remove(nameof(testCat.Id)); ModelState.Remove(nameof(testCat.Created)); ModelState.Remove(nameof(testCat.LastChange)); ModelState.Remove(nameof(testCat.ChangedBy)); if (ModelState.IsValid) { var userRepository = new ApplicationUserRepository <Admin>(); var testCatRepo = new TestCategoryRepository(); var currentUser = userRepository.GetByUserNameAsync(User.Identity.Name); testCat.LastChange = DateTime.Now; testCat.ChangedBy = await currentUser; testCatRepo.Update(testCat); TempData["success"] = "Test category was edited"; } else { return(View("EditTestCategory", testCat)); } return(RedirectToAction("TestCategories")); }
public ActionResult <long> CreateCategory(CreateCategoryCommand cmd) { if (cmd == null) { return(BadRequest("Incorrect command sent")); } var parentCategory = _db.TestCategories.Find(cmd.ParentCategoryId); if (parentCategory == null) { return(BadRequest($"Parent test category with id={cmd.ParentCategoryId} doesn't exist")); } var category = new TestCategory() { Name = cmd.Name, ParentId = cmd.ParentCategoryId }; _db.TestCategories.Add(category); _db.SaveChanges(); return(category.Id); }
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."); } }
private static int MakeTestCategory(TestCategory category, string baseTestFilesDir) { //Does folder with test files exist? if (!Directory.Exists(category.testPath)) { Console.WriteLine($"Skipping {category.categoryName} category as its test folder doesn't exist."); return(0); } //Create folder to put test files into string testFilesDir = Path.Combine(baseTestFilesDir, category.categoryName); Directory.CreateDirectory(testFilesDir); //Create folder to put tests into string testFilesPath = Path.Combine(Directory.GetCurrentDirectory(), "TestTexts"); Directory.CreateDirectory(testFilesPath); List <TestInfo> foundTests = FindTests(category.testPath); List <TestInfo> movedTests = CopyTestsIntoFolder(foundTests, testFilesDir); int testsMade = MakeTestCode(movedTests, category, testFilesDir, testFilesPath); Console.WriteLine($"Created {testsMade} tests for the category: {category.categoryName}"); return(testsMade); }
public override int GetHashCode() { int hash = 1; if (payloadCase_ == PayloadOneofCase.ProtobufPayload) { hash ^= ProtobufPayload.GetHashCode(); } if (payloadCase_ == PayloadOneofCase.JsonPayload) { hash ^= JsonPayload.GetHashCode(); } if (RequestedOutputFormat != 0) { hash ^= RequestedOutputFormat.GetHashCode(); } if (MessageType.Length != 0) { hash ^= MessageType.GetHashCode(); } if (TestCategory != 0) { hash ^= TestCategory.GetHashCode(); } hash ^= (int)payloadCase_; if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public async Task <IHttpActionResult> PutTestCategory(Guid id, TestCategory testCategory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != testCategory.Id) { return(BadRequest()); } try { await testCategoryRepository.PutTestCategory(id, testCategory); } catch (DbUpdateConcurrencyException) { if (!testCategoryRepository.TestCategoryExists(id)) { return(NotFound()); } else { throw; } } catch (Exception ex) { throw; } return(StatusCode(HttpStatusCode.NoContent)); }
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_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."); }
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 async Task AddTestCategoriesAsync(int testId, List <TestCategoryAC> categoryAcList) { var testCategoryList = new List <TestCategory>(); foreach (var categoryAc in categoryAcList) { // to check whether the category already exists var testCategoryObj = await _dbContext.TestCategory.FirstOrDefaultAsync(x => x.CategoryId == categoryAc.CategoryId && x.TestId == testId); // If the category exists and is deselected from the test if (testCategoryObj != null && !categoryAc.IsSelect) { _dbContext.TestCategory.Remove(testCategoryObj); } if (testCategoryObj == null && categoryAc.IsSelect) { // If category does not exists var testCategory = new TestCategory(); testCategory.TestId = testId; testCategory.CategoryId = categoryAc.CategoryId; //If the category does not exists and is selected by user, then it will be added testCategoryList.Add(testCategory); } } if (testCategoryList.Any()) { await _dbContext.TestCategory.AddRangeAsync(testCategoryList); } await _dbContext.SaveChangesAsync(); }
public IActionResult CreateAjax(TestCategory testCategory) { if (ModelState.IsValid) { if (_TestCategoryManager.IsExists(testCategory)) { return(Json(new { status = false, message = $"{nameof(TestCategory.Name)} Already exists" })); } else { int uId = User.Id(); testCategory.CreatorId = uId; _TestCategoryManager.Add(testCategory); return(Json(new { status = true, message = "Successfully created, the list will refresh again in 1 second." })); } } else { string errors = ""; foreach (var modelState in ModelState.Values) { foreach (var error in modelState.Errors) { if (errors.Length > 0) { errors += "\r\n"; } errors += error.ErrorMessage; } } return(Json(new { status = false, message = errors })); } }
public IActionResult UpdateAjax(TestCategory testCategory) { if (ModelState.IsValid) { _TestCategoryManager.Update(testCategory); return(Json(new { status = true, message = "Successfully updated, the list will refresh again in 1 second." })); } else { string errors = ""; foreach (var modelState in ModelState.Values) { foreach (var error in modelState.Errors) { if (errors.Length > 0) { errors += "\r\n"; } errors += error.ErrorMessage; } } return(Json(new { status = false, message = errors })); } }
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."); } }
public async Task <Test> DuplicateTest(int testId, Test newTest) { //Fetch categories present in that particular test and store them in a variable of type list var testCategoryList = _dbContext.TestCategory.Where(x => x.TestId == testId); // Fetch questions present in that particular test and store them in a variable of type list var testQuestionList = _dbContext.TestQuestion.Where(x => x.TestId == testId); var test = await _dbContext.Test.FindAsync(newTest.Id); //Fetch Ip Addresses in that particular test and store them in a variable of type list var testIpAddressList = await _dbContext.TestIpAddresses.Where(x => x.TestId == testId).ToListAsync(); if (testCategoryList.Any()) { var categoryList = new List <TestCategory>(); foreach (TestCategory categoryObject in testCategoryList) { var categoryObj = new TestCategory(); categoryObj.CategoryId = categoryObject.CategoryId; categoryObj.Test = test; categoryObj.TestId = test.Id; categoryList.Add(categoryObj); } await _dbContext.TestCategory.AddRangeAsync(categoryList); await _dbContext.SaveChangesAsync(); var questionList = new List <TestQuestion>(); if (testQuestionList.Any()) { foreach (TestQuestion questionObject in testQuestionList) { var questionObj = new TestQuestion(); questionObj.QuestionId = questionObject.QuestionId; questionObj.Test = test; questionObj.TestId = test.Id; questionList.Add(questionObj); } await _dbContext.TestQuestion.AddRangeAsync(questionList); await _dbContext.SaveChangesAsync(); } var ipAddressList = new List <TestIpAddress>(); if (testIpAddressList.Any()) { foreach (TestIpAddress testIpAddressObject in testIpAddressList) { var ipAddressObject = new TestIpAddress(); ipAddressObject.Test = test; ipAddressObject.TestId = test.Id; ipAddressObject.IpAddress = testIpAddressObject.IpAddress; ipAddressList.Add(ipAddressObject); } await _dbContext.TestIpAddresses.AddRangeAsync(ipAddressList); await _dbContext.SaveChangesAsync(); } } return(test); }
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"); }
public IActionResult Part2Create() { return(View($"{nameof(Part2)}/{nameof(Part2Create)}", new WritingCombined { TestCategory = TestCategory.WritingCategory(2), })); }
public IActionResult Create() { ViewBag.Error = false; ViewBag.ErrorMessage = ""; TestCategory newTestCategory = new TestCategory(); return(View("CreateOrUpdate", newTestCategory)); }
public IActionResult EmbedCreate() { return(View($"{nameof(Embed)}/{nameof(EmbedCreate)}", new SpeakingEmbedCombined { TestCategory = TestCategory.SpeakingCategory(Config.SPEAKING_EMBED_PART_ID), })); }
/// <summary> /// Marks test as failed with given error message. /// </summary> /// <param name="category">Category of the test</param> /// <param name="testKey">Key of the test</param> /// <param name="errorMessage">Message describing why test failed.</param> public void MarkTestFailure(TestCategory category, TestKey testKey, string errorMessage) { lock (TestStates) { TestStates[category][testKey].Result = false; TestStates[category][testKey].ErrorMessage = errorMessage; } }
/// <summary> /// Marks test as successfull. /// </summary> /// <param name="category">Category of the test</param> /// <param name="testKey">Key of the test</param> public void MarkTestSuccess(TestCategory category, TestKey testKey) { lock (TestStates) { TestStates[category][testKey].Result = true; TestStates[category][testKey].ErrorMessage = ""; } }
static XElement WriteTestCategory(TestCategory instance) { var element = new XElement("TestCategory"); element.SetAttributeValue("Name", instance.Name); element.SetAttributeValue("IsBuiltin", instance.IsBuiltin); element.SetAttributeValue("IsExplicit", instance.IsExplicit); return(element); }
public void TestCategoryTest_Will_Ignore_Invalid_Input() { TestCategory category = new TestCategory(null); Confirm.IsNull(category.Categories); category = new TestCategory(string.Empty); Confirm.IsNull(category.Categories); }
public void TestCategoryTest_Will_Parse_List_Of_Attributes() { TestCategory category = new TestCategory("Cat1,Cat2"); Confirm.IsTrue(category.Categories.Count == 2); Confirm.Equal("Cat1", category.Categories[0]); Confirm.Equal("Cat2", category.Categories[1]); }
public async Task <ActionResult> DeleteConfirmed(int id) { TestCategory testCategory = await db.TestCategories.FindAsync(id); db.TestCategories.Remove(testCategory); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public IActionResult Part1Create() { return(View($"{nameof(Part1)}/{nameof(Part1Create)}", new ListeningBaseCombined { TestCategory = TestCategory.ListeningCategory(1), ListeningMedia = ListeningMedia.Generate(), ListeningBaseQuestions = ListeningBaseQuestion.Generate(Config.MAX_LISTENING_PART_1_QUESTION, 3) })); }
public IActionResult Part4Create() { return(View($"{nameof(Part4)}/{nameof(Part4Create)}", new ReadingCombined { TestCategory = TestCategory.ReadingCategory(4), ReadingPartTwos = ReadingPartTwo.Generate(Config.MAX_READING_PART_4_QUESTION) })); }
/// <summary> /// Gets the Test Category /// </summary> /// <returns>text</returns> public string GetTestCategory() { TestCategory.Wait(2); if (Driver.GetType() == typeof(DummyDriver)) { TestCategory.Text = FakeText; } return(TestCategory.Text.Trim()); }
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."); }
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."); } }
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."); } } }
public void Test_ZipToFile() { 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(); 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."); DirectoryZipper zipper = new DirectoryZipper(exporter.ExportDirectoryPath); string zipFileName = @"Backup--" + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "--" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + ".zip"; string zipFilePath = TestUtilities.GetTestingPath(this) + Path.DirectorySeparatorChar + "Backups" + Path.DirectorySeparatorChar + zipFileName; //zipShortPath;//Config.Application.PhysicalApplicationPath + zipShortPath; zipper.ZipToFile(zipFilePath); Assert.IsTrue(File.Exists(zipFilePath), "The zip file wasn't created."); // TODO: Open the zip file and check the contents }
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 virtual void Test_ImportFromXml() { Version currentVersion = new Version(1, 0, 0, 0); Version legacyVersion = new Version(0, 9, 0, 0); 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}; // 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); if (references.Count <= 0) Assert.Fail("No active references found."); DataExporter exporter = (DataExporter)DataAccess.Data.InitializeDataExporter(); exporter.ExportDirectoryPath = TestUtilities.GetTestingPath(this) + Path.DirectorySeparatorChar + "Exported"; exporter.ExportEntity(references[0]); exporter.ExportEntity(user); exporter.ExportEntity(role); exporter.ExportEntity(article); exporter.ExportEntity(category); DataAccess.Data.Schema.LegacyVersion = legacyVersion; DataAccess.Data.Schema.ApplicationVersion = currentVersion; DataImporter importer = (DataImporter)DataAccess.Data.InitializeDataImporter(); importer.ImportableDirectoryPath = exporter.ExportDirectoryPath; importer.ImportedDirectoryPath = TestUtilities.GetTestingPath(this) + Path.DirectorySeparatorChar + "Imported"; importer.ImportFromXml(); TestUser foundUser = DataAccess.Data.Reader.GetEntity<TestUser>("ID", user.ID); Assert.IsNotNull(foundUser, "foundUser == null"); Assert.AreEqual(user.ID.ToString(), foundUser.ID.ToString(), "The ID of the found user doesn't match the ID of the original user."); DataAccess.Data.Activator.Activate(foundUser, "Roles"); Assert.IsNotNull(foundUser.Roles, "user.Roles == null"); Assert.AreEqual(1, foundUser.Roles.Length, "Invalid number of roles found."); TestRole foundRole = DataAccess.Data.Reader.GetEntity<TestRole>("ID", role.ID); Assert.IsNotNull(foundRole, "foundRole == null"); Assert.AreEqual(role.ID.ToString(), foundRole.ID.ToString(), "The ID of the found role doesn't match the ID of the original role."); TestCategory foundCategory = DataAccess.Data.Reader.GetEntity<TestCategory>("ID", category.ID); Assert.IsNotNull(foundCategory, "foundCategory == null"); Assert.AreEqual(category.ID.ToString(), foundCategory.ID.ToString(), "The ID of the found category doesn't match the ID of the original category."); TestArticle foundArticle = DataAccess.Data.Reader.GetEntity<TestArticle>("ID", article.ID); Assert.IsNotNull(foundArticle, "foundArticle == null"); Assert.AreEqual(article.ID.ToString(), foundArticle.ID.ToString(), "The ID of the found article doesn't match the ID of the original article."); }
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."); }
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"); }
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 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."); } } }
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 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); } }
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); } }