public void SelectingYes_AndLeavingRestBlank_IsValidInDraftAndFullModes(ITravelOrVisitorDetails details)
        {
            // Arrange
            var validationResults = new List <ValidationResult>();

            // Act
            var isValid = Validator.TryValidateObject(details, new ValidationContext(details), validationResults, true);

            // Assert
            Assert.True(isValid, "Expected details to be valid");
        }
 public void ClearTravelOrVisitorFields(ITravelOrVisitorDetails travelOrVisitorDetails)
 {
     travelOrVisitorDetails.TotalNumberOfCountries = null;
     travelOrVisitorDetails.Country1            = null;
     travelOrVisitorDetails.Country1Id          = null;
     travelOrVisitorDetails.StayLengthInMonths1 = null;
     travelOrVisitorDetails.Country2            = null;
     travelOrVisitorDetails.Country2Id          = null;
     travelOrVisitorDetails.StayLengthInMonths2 = null;
     travelOrVisitorDetails.Country3            = null;
     travelOrVisitorDetails.Country3Id          = null;
     travelOrVisitorDetails.StayLengthInMonths3 = null;
 }
        public void ProvidingTotalNumberOfCountriesAlone_IsValid(ITravelOrVisitorDetails details)
        {
            // Arrange
            var validationResults = new List <ValidationResult>();

            details.TotalNumberOfCountries = 3;

            // Act
            var isValid = Validator.TryValidateObject(details, new ValidationContext(details), validationResults, true);

            // Assert
            Assert.True(isValid, "Expected details to be valid");
        }
        public void ProvidingCountry_ButNotTotalNumberOfCountries_IsInvalid(ITravelOrVisitorDetails details)
        {
            // Arrange
            var validationResults = new List <ValidationResult>();

            details.Country1Id = 1;

            // Act
            var isValid = Validator.TryValidateObject(details, new ValidationContext(details), validationResults, true);

            // Assert
            Assert.False(isValid, "Expected details to be invalid");
            Assert.Equal(ValidationMessages.TravelOrVisitTotalNumberOfCountriesRequired, validationResults.First().ErrorMessage);
        }
        public void TotalNumberOfCountriesIsLessThanInputCountries_IsInvalid(ITravelOrVisitorDetails details)
        {
            // Arrange
            var validationResults = new List <ValidationResult>();

            details.TotalNumberOfCountries = 1;
            details.Country1Id             = 1;
            details.Country2Id             = 2;

            // Act
            var isValid = Validator.TryValidateObject(details, new ValidationContext(details), validationResults, true);

            // Assert
            Assert.False(isValid, "Expected details to be invalid");
        }
        public void ProvidingDurationsWithoutCountries_IsNotValid(ITravelOrVisitorDetails details)
        {
            // Arrange
            var validationResults = new List <ValidationResult>();

            details.TotalNumberOfCountries = 3;
            details.StayLengthInMonths1    = 1;
            details.StayLengthInMonths2    = 2;
            details.StayLengthInMonths3    = 3;

            // Act
            var isValid = Validator.TryValidateObject(details, new ValidationContext(details), validationResults, true);

            // Assert
            Assert.False(isValid, "Expected details to be invalid");
            Assert.Equal(3, validationResults.Count);
            validationResults.ForEach(result =>
                                      Assert.Equal(ValidationMessages.TravelOrVisitDurationHasCountry, result.ErrorMessage));
        }
        public void SumOfDurationsIsOver24_IsInvalid(ITravelOrVisitorDetails details)
        {
            // Arrange
            var validationResults = new List <ValidationResult>();

            details.TotalNumberOfCountries = 3;
            details.Country1Id             = 1;
            details.StayLengthInMonths1    = 10;
            details.Country2Id             = 2;
            details.StayLengthInMonths2    = 10;
            details.Country3Id             = 3;
            details.StayLengthInMonths3    = 10;

            // Act
            var isValid = Validator.TryValidateObject(details, new ValidationContext(details), validationResults, true);

            // Assert
            Assert.False(isValid, "Expected details to be invalid");
        }
예제 #8
0
        private static void RemoveDuplicateCountries(ITravelOrVisitorDetails details)
        {
            if (details.Country1Id != null && details.Country1Id == details.Country2Id)
            {
                if (details.StayLengthInMonths1 != null && details.StayLengthInMonths2 != null)
                {
                    details.StayLengthInMonths1 = Math.Max(details.StayLengthInMonths1.Value,
                                                           details.StayLengthInMonths2.Value);
                }

                details.Country2Id          = null;
                details.StayLengthInMonths2 = null;
            }

            if (details.Country1Id != null && details.Country1Id == details.Country3Id)
            {
                if (details.StayLengthInMonths1 != null && details.StayLengthInMonths3 != null)
                {
                    details.StayLengthInMonths1 = Math.Max(details.StayLengthInMonths1.Value,
                                                           details.StayLengthInMonths3.Value);
                }

                details.Country3Id          = null;
                details.StayLengthInMonths3 = null;
            }

            if (details.Country2Id != null && details.Country2Id == details.Country3Id)
            {
                if (details.StayLengthInMonths2 != null && details.StayLengthInMonths3 != null)
                {
                    details.StayLengthInMonths2 = Math.Max(details.StayLengthInMonths2.Value,
                                                           details.StayLengthInMonths3.Value);
                }

                details.Country3Id          = null;
                details.StayLengthInMonths3 = null;
            }
        }