示例#1
0
 public SkierLogic(
     ISkierManager skierManager,
     SkierValidator validator)
 {
     this.skierManager = skierManager ?? throw new ArgumentNullException(nameof(skierManager));
     this.validator    = validator ?? throw new ArgumentNullException(nameof(validator));
 }
        public void ValidateCountryCodeInvalidSkierTest(string countryCode, string expectedError)
        {
            // Arrange
            var validators = new SkierValidator();
            var skier      = GetValidSkier();

            // Act
            skier.CountryCode = countryCode;
            var resultCountryCodeNull = validators.Validate(skier);

            // Assert
            Assert.Equal(expectedError, resultCountryCodeNull.ErrorCodeFor(nameof(Skier.CountryCode)));
        }
        public void ValidateBirthdateInvalidSkierTest()
        {
            // Arrange
            var validators = new SkierValidator();
            var skier      = GetValidSkier();

            // Act
            skier.BirthDate = DateTime.Now.AddYears(-81);
            var resultBirthDateTooOld = validators.Validate(skier);

            skier.BirthDate = DateTime.Now.AddYears(-1);
            var resultBirthDateTooYoung = validators.Validate(skier);

            // Assert
            Assert.Equal(ErrorCode.DateTimeNotInRange, resultBirthDateTooOld.ErrorCodeFor(nameof(Skier.BirthDate)));
            Assert.Equal(ErrorCode.DateTimeNotInRange, resultBirthDateTooYoung.ErrorCodeFor(nameof(Skier.BirthDate)));
        }
        public void ValidateDefaultSkierTest()
        {
            // Arrange
            var validators = new SkierValidator();
            var skier      = new Skier();

            // Act
            var result = validators.Validate(skier);

            // Assert
            Assert.False(result.IsValid);
            Assert.Equal(3, result.Errors.Count);

            Assert.Equal(ErrorCode.NotEmpty, result.ErrorCodeFor(nameof(Skier.FirstName)));
            Assert.Equal(ErrorCode.NotEmpty, result.ErrorCodeFor(nameof(Skier.LastName)));
            Assert.Equal(ErrorCode.NotEmpty, result.ErrorCodeFor(nameof(Skier.CountryCode)));
        }