Exemplo n.º 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");
        }
Exemplo n.º 2
0
        // Some fields can't be serialized to JSON which is needed for the Angular controller,
        // so this creates a clone without those fields
        public EditGrantAllocationViewModel SerializableClone()
        {
            var clone = new EditGrantAllocationViewModel
            {
                GrantAllocationID            = GrantAllocationID,
                GrantModificationID          = GrantModificationID,
                GrantAllocationName          = GrantAllocationName,
                OrganizationID               = OrganizationID,
                ProgramIndexProjectCodeJsons = ProgramIndexProjectCodeJsons,
                FederalFundCodeID            = FederalFundCodeID,
                DivisionID                   = DivisionID,
                DNRUplandRegionID            = DNRUplandRegionID,
                AllocationAmount             = AllocationAmount,
                GrantAllocationChangeLogNote = GrantAllocationChangeLogNote,
                StartDate = StartDate,
                EndDate   = EndDate,
                ProgramManagerPersonIDs          = ProgramManagerPersonIDs,
                GrantManagerID                   = GrantManagerID,
                GrantAllocationFileResourceDatas = new List <HttpPostedFileBase>()
            };

            // HttpPostedFileBase cannot be serialize by the default serializer

            return(clone);
        }
Exemplo n.º 3
0
        public void AllViewModelFieldsAreSetFromConstructorTest()
        {
            // Arrange
            var grantAllocation = TestFramework.TestGrantAllocation.Create();

            // Act
            var viewModel = new EditGrantAllocationViewModel(grantAllocation);

            // Assert
            Assert.That(viewModel.GrantAllocationID, Is.EqualTo(grantAllocation.GrantAllocationID));
            Assert.That(viewModel.GrantAllocationName, Is.EqualTo(grantAllocation.GrantAllocationName));
            Assert.That(viewModel.OrganizationID, Is.EqualTo(grantAllocation.OrganizationID));
            //Assert.That(viewModel.IsActive, Is.EqualTo(grantAllocation.IsActive));
        }
Exemplo n.º 4
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));
        }