Пример #1
0
        public void CanValidateModelTest()
        {
            // Arrange
            var grantAllocation           = TestFramework.TestGrantAllocation.Create();
            var viewModel                 = new EditGrantAllocationViewModel(grantAllocation);
            var nameOfGrantAllocationName = GeneralUtility.NameOf(() => viewModel.GrantAllocationName);

            ICollection <ValidationResult> validationResults;

            // Act
            DataAnnotationsValidator.TryValidate(viewModel, out validationResults);

            // Assert
            Assert.That(validationResults.Count, Is.EqualTo(1), "Expecting certain number of errors");
            TestFramework.AssertFieldRequired(validationResults, nameOfGrantAllocationName);

            // Act
            // Set string fields to string longer than their max lengths
            viewModel.GrantAllocationName = TestFramework.MakeTestNameLongerThan(nameOfGrantAllocationName, Models.GrantAllocation.FieldLengths.GrantAllocationName);
            DataAnnotationsValidator.TryValidate(viewModel, out validationResults);

            // Assert
            Assert.That(validationResults.Count, Is.EqualTo(1), "Expecting certain number of errors");
            TestFramework.AssertFieldStringLength(validationResults, nameOfGrantAllocationName, Models.GrantAllocation.FieldLengths.GrantAllocationName);

            // Act
            // Happy path
            viewModel.GrantAllocationName = TestFramework.MakeTestName(nameOfGrantAllocationName, Models.GrantAllocation.FieldLengths.GrantAllocationName);
            var isValid = DataAnnotationsValidator.TryValidate(viewModel, out validationResults);

            // Assert
            Assert.That(isValid, Is.True, "Should pass validation");
        }
Пример #2
0
        public void TestProjectAuditLogging()
        {
            // This test can become sluggish and fail when the table is very full, which suggests the table likely needs to be trimmed regularly.
            AuditLog.ClearAuditLogTable();

            // Get an arbitrary real-word person to do these actions
            var firmaUser = HttpRequestStorage.DatabaseEntities.People.First();

            // Create audit logging
            // --------------------

            // Make a test object and save it
            var dbContext = HttpRequestStorage.DatabaseEntities;

            var testProject = TestFramework.TestProject.Create(dbContext);

            HttpRequestStorage.DatabaseEntities.SaveChanges(firmaUser);

            // Check that the audit log mentions this object
            System.Diagnostics.Trace.WriteLine($"Looking for {FieldDefinition.Project.GetFieldDefinitionLabel()} named \"{testProject.ProjectName}\" in Audit Log database entries.");
            Check.Assert(HttpRequestStorage.DatabaseEntities.AuditLogs.Any(al => al.OriginalValue.Contains(testProject.ProjectName)));

            // Change audit logging
            // --------------------

            // Make changes to the original object
            var newProjectName = TestFramework.MakeTestName($"New {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Name", Project.FieldLengths.ProjectName);

            testProject.ProjectName = newProjectName;
            HttpRequestStorage.DatabaseEntities.SaveChanges(firmaUser);

            // Check that the audit log mentions this NEW name
            Check.Assert(HttpRequestStorage.DatabaseEntities.AuditLogs.Any(al => al.NewValue.Contains(newProjectName)));

            // Delete audit logging
            // --------------------

            // Stash for later; we'll need to clean these up
            var testRegion    = testProject.FocusArea.DNRUplandRegion;
            var testFocusArea = testProject.FocusArea;

            testProject.DeleteFull(dbContext);
            HttpRequestStorage.DatabaseEntities.SaveChanges(firmaUser);
            // Check that the audit log mentions this Project name as deleted
            Check.Assert(
                HttpRequestStorage.DatabaseEntities.AuditLogs.SingleOrDefault(
                    al => al.TableName == "Project" && al.AuditLogEventTypeID == AuditLogEventType.Deleted.AuditLogEventTypeID && al.RecordID == testProject.ProjectID) != null,
                $"Could not find deleted {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} record");

            // Cleanup
            testRegion.DeleteFull(dbContext);
            testFocusArea.DeleteFull(dbContext);
            HttpRequestStorage.DatabaseEntities.SaveChanges(firmaUser);
        }
        public void UpdateModelTest()
        {
            // Arrange
            var projectNote = TestFramework.TestProjectNote.Create();
            var viewModel   = new EditNoteViewModel(projectNote.Note);

            viewModel.Note = TestFramework.MakeTestName(GeneralUtility.NameOf(() => viewModel.Note), Models.ProjectNote.FieldLengths.Note);

            // Act
            viewModel.UpdateModel(projectNote, TestFramework.TestPerson.Create());

            // Assert
            Assert.That(projectNote.Note, Is.EqualTo(viewModel.Note));
        }
        public void UpdateModelTest()
        {
            // Arrange
            var tag       = TestFramework.TestTag.Create();
            var viewModel = new EditViewModel(tag);

            viewModel.TagName = TestFramework.MakeTestName(GeneralUtility.NameOf(() => viewModel.TagName), Models.Tag.FieldLengths.TagName);

            // Act
            viewModel.UpdateModel(tag, TestFramework.TestPerson.Create());

            // Assert
            Assert.That(tag.TagName, Is.EqualTo(viewModel.TagName));
        }
        public void UpdateModelTest()
        {
            // Arrange
            var projectUpdate = TestFramework.TestProjectUpdate.Create();
            var person        = TestFramework.TestPerson.Create();
            var viewModel     = new BasicsViewModel(projectUpdate, null);

            viewModel.ProjectDescription = TestFramework.MakeTestName(GeneralUtility.NameOf(() => viewModel.ProjectDescription), Models.ProjectUpdate.FieldLengths.ProjectDescription);

            // Act
            viewModel.UpdateModel(projectUpdate, person);

            // Assert
            Assert.That(projectUpdate.ProjectDescription, Is.EqualTo(viewModel.ProjectDescription));
        }
Пример #6
0
        public void TestClassificationAuditLogging()
        {
            // This test can become sluggish and fail when the table is very full, which suggests the table likely needs to be trimmed regularly.
            AuditLog.ClearAuditLogTable();

            // Get an arbitrary real-word person to do these actions
            var firmaUser = HttpRequestStorage.DatabaseEntities.People.First();

            // Create audit logging
            // --------------------

            // Make a test object and save it
            var dbContext = HttpRequestStorage.DatabaseEntities;

            var testClassification = TestFramework.TestClassification.Create(dbContext);

            HttpRequestStorage.DatabaseEntities.SaveChanges(firmaUser);

            // Check that the audit log mentions this object
            System.Diagnostics.Trace.WriteLine($"Looking for Classification \"{testClassification.DisplayName}\" in Audit Log database entries.");
            Check.Assert(HttpRequestStorage.DatabaseEntities.AuditLogs.Any(al => al.OriginalValue.Contains(testClassification.DisplayName)));

            // Change audit logging
            // --------------------

            // Make changes to the original object
            var newClassificationName        = TestFramework.MakeTestName("New Classification", Classification.FieldLengths.DisplayName);
            var newClassificationDescription = TestFramework.MakeTestName("New ClassificationDescription");

            testClassification.DisplayName = newClassificationName;
            testClassification.ClassificationDescription = newClassificationDescription;
            HttpRequestStorage.DatabaseEntities.SaveChanges(firmaUser);

            // Check that the audit log mentions this NEW name
            Check.Assert(HttpRequestStorage.DatabaseEntities.AuditLogs.Any(al => al.NewValue.Contains(newClassificationName)));

            // Delete audit logging
            // --------------------

            testClassification.DeleteFull(dbContext);
            HttpRequestStorage.DatabaseEntities.SaveChanges(firmaUser);
            // Check that the audit log mentions this Classification name as deleted
            Check.Assert(
                HttpRequestStorage.DatabaseEntities.AuditLogs.SingleOrDefault(
                    al => al.TableName == "Classification" && al.AuditLogEventTypeID == AuditLogEventType.Deleted.AuditLogEventTypeID && al.RecordID == testClassification.ClassificationID) !=
                null,
                "Could not find deleted Classification record");
        }
        public void UpdateModelTest()
        {
            // Arrange
            var organization = TestFramework.TestOrganization.Create();
            var viewModel    = new EditViewModel(organization);

            viewModel.OrganizationName      = TestFramework.MakeTestName(GeneralUtility.NameOf(() => viewModel.OrganizationName), Models.Organization.FieldLengths.OrganizationName);
            viewModel.OrganizationShortName = TestFramework.MakeTestName(GeneralUtility.NameOf(() => viewModel.OrganizationShortName), Models.Organization.FieldLengths.OrganizationShortName);

            // Act
            viewModel.UpdateModel(organization, TestFramework.TestPerson.Create());

            // Assert
            Assert.That(organization.OrganizationName, Is.EqualTo(viewModel.OrganizationName));
            Assert.That(organization.OrganizationShortName, Is.EqualTo(viewModel.OrganizationShortName));
        }
Пример #8
0
        public void UpdateModelTest()
        {
            // Arrange
            var project   = TestFramework.TestProject.Create();
            var person    = TestFramework.TestPerson.Create();
            var viewModel = new EditProjectViewModel(project, false);

            viewModel.ProjectName        = TestFramework.MakeTestName(GeneralUtility.NameOf(() => viewModel.ProjectName), Models.Project.FieldLengths.ProjectName);
            viewModel.ProjectDescription = TestFramework.MakeTestName(GeneralUtility.NameOf(() => viewModel.ProjectDescription), Models.Project.FieldLengths.ProjectDescription);

            // Act
            viewModel.UpdateModel(project, person);

            // Assert
            Assert.That(project.ProjectName, Is.EqualTo(viewModel.ProjectName));
            Assert.That(project.ProjectDescription, Is.EqualTo(viewModel.ProjectDescription));
        }
        public void CanValidateModelTest()
        {
            // Arrange
            var tag = TestFramework.TestTag.Create();

            // Inducing an error in Tag
            tag.TagName = null;
            var viewModel     = new EditViewModel(tag);
            var nameOfTagName = GeneralUtility.NameOf(() => viewModel.TagName);

            ICollection <ValidationResult> validationResults;

            // Act
            DataAnnotationsValidator.TryValidate(viewModel, out validationResults);

            // Assert
            Assert.That(validationResults.Count, Is.EqualTo(1), "Expecting certain number of errors");
            TestFramework.AssertFieldRequired(validationResults, nameOfTagName);

            // Act
            // Set string fields to string longer than their max lengths
            viewModel.TagName = TestFramework.MakeTestNameLongerThan(nameOfTagName, Models.Tag.FieldLengths.TagName);
            DataAnnotationsValidator.TryValidate(viewModel, out validationResults);

            // Assert
            Assert.That(validationResults.Count, Is.AtLeast(1), "Expecting certain number of errors");
            TestFramework.AssertFieldStringLength(validationResults, nameOfTagName, Models.Tag.FieldLengths.TagName);

            // Act
            // Set string fields to string longer than their max lengths
            viewModel.TagName = TestFramework.MakeTestName(string.Format("{0}&", nameOfTagName), Models.Tag.FieldLengths.TagName);
            DataAnnotationsValidator.TryValidate(viewModel, out validationResults);


            // Assert
            Assert.That(validationResults.Count, Is.AtLeast(1), "Expecting certain number of errors");
            TestFramework.AssertInvalidCharacters(validationResults);

            // Act
            // Happy path
            viewModel.TagName = TestFramework.MakeTestNameWithoutCertainCharacters(nameOfTagName, Models.Tag.FieldLengths.TagName, @"[^a-zA-Z0-9-_\s]");
            var isValid = DataAnnotationsValidator.TryValidate(viewModel, out validationResults);

            // Assert
            Assert.That(isValid, Is.True, "Should pass validation");
        }
Пример #10
0
        public void TestOrganizationAuditLogging()
        {
            AssertCustom.IgnoreOnBuildServer();

            // Get an arbitrary real-word person to do these actions
            var neptuneUser = HttpRequestStorage.DatabaseEntities.People.First();

            // Create audit logging
            // --------------------

            // Make a test object and save it
            var dbContext = HttpRequestStorage.DatabaseEntities;

            var testOrganization = TestFramework.TestOrganization.Create(dbContext);

            HttpRequestStorage.DatabaseEntities.SaveChanges(neptuneUser);

            // Check that the audit log mentions this object
            System.Diagnostics.Trace.WriteLine(string.Format("Looking for Organization named \"{0}\" in Audit Log database entries.", testOrganization.OrganizationName));
            Check.Assert(HttpRequestStorage.DatabaseEntities.AuditLogs.Any(al => al.OriginalValue.Contains(testOrganization.OrganizationName)));

            // Change audit logging
            // --------------------

            // Make changes to the original object
            var newOrganizationName = TestFramework.MakeTestName("New Organization Name", Organization.FieldLengths.OrganizationName);

            testOrganization.OrganizationName = newOrganizationName;
            HttpRequestStorage.DatabaseEntities.SaveChanges(neptuneUser);

            // Check that the audit log mentions this NEW name
            Check.Assert(HttpRequestStorage.DatabaseEntities.AuditLogs.Any(al => al.NewValue.Contains(newOrganizationName)));

            // Delete audit logging
            // --------------------

            HttpRequestStorage.DatabaseEntities.Organizations.DeleteOrganization(testOrganization);
            HttpRequestStorage.DatabaseEntities.SaveChanges(neptuneUser);
            // Check that the audit log mentions this Organization name as deleted
            Check.Assert(
                HttpRequestStorage.DatabaseEntities.AuditLogs.SingleOrDefault(
                    al => al.TableName == "Organization" && al.AuditLogEventTypeID == AuditLogEventType.Deleted.AuditLogEventTypeID && al.RecordID == testOrganization.OrganizationID) != null,
                "Could not find deleted Organization record");
        }
Пример #11
0
        public void UpdateModelTest()
        {
            // Arrange
            var organization    = TestFramework.TestOrganization.Create();
            var grantAllocation = TestFramework.TestGrantAllocation.Create();
            var viewModel       = new EditGrantAllocationViewModel(grantAllocation);

            viewModel.GrantAllocationName = TestFramework.MakeTestName(GeneralUtility.NameOf(() => viewModel.GrantAllocationName), Models.GrantAllocation.FieldLengths.GrantAllocationName);
            viewModel.OrganizationID      = organization.OrganizationID;
            //viewModel.IsActive = true;

            // Act
            viewModel.UpdateModel(grantAllocation, TestFramework.TestPerson.Create());

            // Assert
            Assert.That(grantAllocation.GrantAllocationName, Is.EqualTo(viewModel.GrantAllocationName));
            Assert.That(grantAllocation.OrganizationID, Is.EqualTo(viewModel.OrganizationID));
            //Assert.That(grantAllocation.IsActive, Is.EqualTo(viewModel.IsActive));
        }
Пример #12
0
        public void TestGrantAllocationAuditLogging()
        {
            // Get an arbitrary real-word person to do these actions
            var firmaUser = HttpRequestStorage.DatabaseEntities.People.First();

            // Create audit logging
            // --------------------

            // Make a test grant allocation and save it
            var dbContext           = HttpRequestStorage.DatabaseEntities;
            var testGrantAllocation = TestFramework.TestGrantAllocation.Create(dbContext);
            var testOrganization    = TestFramework.TestOrganization.Create(dbContext);

            HttpRequestStorage.DatabaseEntities.SaveChanges(firmaUser);

            // Check that the audit log mentions this GrantAllocation
            System.Diagnostics.Trace.WriteLine($"Looking for {FieldDefinition.GrantAllocation.GetFieldDefinitionLabel()} named \"{testGrantAllocation.GrantAllocationName}\" in Audit Log database entries.");
            Check.Assert(HttpRequestStorage.DatabaseEntities.AuditLogs.Any(al => al.OriginalValue.Contains(testGrantAllocation.GrantAllocationName)));

            // Change audit logging
            // --------------------

            // Make changes to the grant allocation
            var newGrantAllocationName = TestFramework.MakeTestName("New Grant Allocation Name");

            testGrantAllocation.GrantAllocationName = newGrantAllocationName;
            testGrantAllocation.Organization        = testOrganization;
            HttpRequestStorage.DatabaseEntities.SaveChanges(firmaUser);

            // Check that the audit log mentions this NEW GrantAllocation name
            Check.Assert(HttpRequestStorage.DatabaseEntities.AuditLogs.Any(al => al.NewValue.Contains(newGrantAllocationName)));

            // Delete audit logging
            // --------------------

            testGrantAllocation.DeleteFull(dbContext);
            HttpRequestStorage.DatabaseEntities.SaveChanges(firmaUser);
            // Check that the audit log mentions this GrantAllocation name as deleted
            Check.Assert(
                HttpRequestStorage.DatabaseEntities.AuditLogs.SingleOrDefault(
                    al => al.TableName == "GrantAllocation" && al.AuditLogEventTypeID == AuditLogEventType.Deleted.AuditLogEventTypeID && al.RecordID == testGrantAllocation.GrantAllocationID) != null,
                "Could not find deleted Grant Allocation record");
        }