示例#1
0
        public void CanValidateModelTest()
        {
            // Arrange
            var taxonomyBranch           = TestFramework.TestTaxonomyBranch.Create();
            var viewModel                = new EditViewModel(taxonomyBranch);
            var nameOfTaxonomyBranchName = GeneralUtility.NameOf(() => viewModel.TaxonomyBranchName);

            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, nameOfTaxonomyBranchName);

            // Act
            // Set string fields to string longer than their max lengths
            viewModel.TaxonomyBranchName = TestFramework.MakeTestNameLongerThan(nameOfTaxonomyBranchName, ProjectFirmaModels.Models.TaxonomyBranch.FieldLengths.TaxonomyBranchName);
            DataAnnotationsValidator.TryValidate(viewModel, out validationResults);

            // Assert
            Assert.That(validationResults.Count, Is.EqualTo(1), "Expecting certain number of errors");
            TestFramework.AssertFieldStringLength(validationResults, nameOfTaxonomyBranchName, ProjectFirmaModels.Models.TaxonomyBranch.FieldLengths.TaxonomyBranchName);

            // Act
            // Happy path
            viewModel.TaxonomyBranchName = TestFramework.MakeTestName(nameOfTaxonomyBranchName, ProjectFirmaModels.Models.TaxonomyBranch.FieldLengths.TaxonomyBranchName);
            var isValid = DataAnnotationsValidator.TryValidate(viewModel, out validationResults);

            // Assert
            Assert.That(isValid, Is.True, "Should pass validation");
        }
示例#2
0
        public void UpdateModelTest()
        {
            // Arrange
            var projectNote = TestFramework.TestProjectNote.Create();
            var viewModel   = new EditNoteViewModel(projectNote.Note);

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

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

            // Assert
            Assert.That(projectNote.Note, Is.EqualTo(viewModel.Note));
        }
示例#3
0
        public void UpdateModelTest()
        {
            // Arrange
            var taxonomyLeaf = TestFramework.TestTaxonomyLeaf.Create();
            var viewModel    = new EditViewModel(taxonomyLeaf);

            viewModel.TaxonomyLeafName = TestFramework.MakeTestName(GeneralUtility.NameOf(() => viewModel.TaxonomyLeafName), ProjectFirmaModels.Models.TaxonomyLeaf.FieldLengths.TaxonomyLeafName);

            // Act
            viewModel.UpdateModel(taxonomyLeaf, TestFramework.TestFirmaSession.Create());

            // Assert
            Assert.That(taxonomyLeaf.TaxonomyLeafName, Is.EqualTo(viewModel.TaxonomyLeafName));
        }
示例#4
0
        public void UpdateModelTest()
        {
            // Arrange
            var projectUpdate = TestFramework.TestProjectUpdate.Create();
            var viewModel     = new BasicsViewModel(projectUpdate, null);

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

            // Act
            viewModel.UpdateModel(projectUpdate, TestFramework.TestFirmaSession.Create());

            // Assert
            Assert.That(projectUpdate.ProjectDescription, Is.EqualTo(viewModel.ProjectDescription));
        }
示例#5
0
        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, ProjectFirmaModels.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, ProjectFirmaModels.Models.Tag.FieldLengths.TagName);

            // Act
            // Set string fields to string longer than their max lengths
            viewModel.TagName = TestFramework.MakeTestName(string.Format("{0}&", nameOfTagName), ProjectFirmaModels.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, ProjectFirmaModels.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");
        }
示例#6
0
        public void UpdateModelTest()
        {
            // Arrange
            var organization  = TestFramework.TestOrganization.Create();
            var fundingSource = TestFramework.TestFundingSource.Create();
            var viewModel     = new EditViewModel(fundingSource);

            viewModel.FundingSourceName = TestFramework.MakeTestName(GeneralUtility.NameOf(() => viewModel.FundingSourceName), ProjectFirmaModels.Models.FundingSource.FieldLengths.FundingSourceName);
            viewModel.OrganizationID    = organization.OrganizationID;
            viewModel.IsActive          = true;

            // Act
            viewModel.UpdateModel(fundingSource, TestFramework.TestFirmaSession.Create());

            // Assert
            Assert.That(fundingSource.FundingSourceName, Is.EqualTo(viewModel.FundingSourceName));
            Assert.That(fundingSource.OrganizationID, Is.EqualTo(viewModel.OrganizationID));
            Assert.That(fundingSource.IsActive, Is.EqualTo(viewModel.IsActive));
        }