Exemple #1
0
        public void Complete_Succeed()
        {
            ModelValidator.Test(
                () => new Rebel
            {
                Name    = "Luke",
                Surname = "Skywalker",
                Age     = 18,
                Weapon  = new Weapon
                {
                    Color = "Green"
                }
            },
                modelSetup =>
            {
                modelSetup.CheckClass(os => os.IsInvalidWith(r => r.Surname, "Organa"));
                modelSetup.CheckClass(os => os.IsInvalidWith(r => r.Age, 42));

                modelSetup.CheckProperty(r => r.Name, ps => ps.IsInvalidWith(null).IsInvalidWith("Lukelongname"));
                modelSetup.CheckProperty(r => r.Surname, ps => ps.IsInvalidWith(null));
                modelSetup.CheckProperty(r => r.Age, ps => ps.IsInvalidWith(901).IsInvalidWith(9));

                modelSetup.CheckProperty(r => r.Weapon, ps => ps.IsInvalidWithTransform(w =>
                {
                    w.Color = "Red";
                    return(w);
                }));
            });
        }
Exemple #2
0
 public void InRange_Succeed()
 {
     ModelValidator.Test(
         () => new Rebel
     {
         Name    = "Luke",
         Surname = "Skywalker",
         Age     = 18
     },
         modelSetup =>
     {
         modelSetup.CheckProperty(r => r.Age, ps => ps.InRange(10, 900));
     },
         _skipConverageChecksOptions);
 }
Exemple #3
0
 public void HasMaxLenght_Succeed()
 {
     ModelValidator.Test(
         () => new Rebel
     {
         Name    = "Luke",
         Surname = "Skywalker",
         Age     = 18
     },
         modelSetup =>
     {
         modelSetup.CheckProperty(r => r.Name, ps => ps.HasMaxLenght(10), false);
     },
         _skipConverageChecksOptions);
 }
Exemple #4
0
 public void ServiceNotRegisteredClass_Throws_ServiceNotFoundException()
 {
     _ = Assert.Throws <ServiceNotFoundException>(() =>
     {
         ModelValidator.Test(
             () => new Skywalker
         {
             Name   = "Luke",
             IsJedi = true
         },
             modelSetup =>
         {
             modelSetup.CheckProperty(r => r.IsJedi, ps => ps.IsInvalidWith(false));
         });
     });
 }
Exemple #5
0
 public void InvalidModelFunction_Throws_ModelIsInvalidException()
 {
     _ = Assert.Throws <ModelIsInvalidException>(() =>
     {
         ModelValidator.Test(
             () => new Stormtrooper
         {
             IsCloned = false,
             Leader   = "Palpatine"
         },
             modelSetup =>
         {
         },
             _skipConverageChecksOptions);
     });
 }
Exemple #6
0
        public void Complete_Succeed()
        {
            ModelValidator.Test(
                () => new Stormtrooper
            {
                IsCloned = true,
                Leader   = "Palpatine"
            },
                modelSetup =>
            {
                modelSetup.CheckClass(os => os.IsInvalidWith(r => r.IsCloned, false), "Trooper must be a clone.");

                modelSetup.CheckProperty(r => r.Leader, ps => ps.IsInvalidWith(null, "Sith leader is required."));
            },
                _skipConverageChecksOptions);
        }
Exemple #7
0
 public void InvalidModelFunction_Throws_ModelIsInvalidException()
 {
     _ = Assert.Throws <ModelIsInvalidException>(() =>
     {
         ModelValidator.Test(
             () => new Rebel
         {
             Name = "Luke",
             Age  = 9
         },
             modelSetup =>
         {
         },
             _skipConverageChecksOptions);
     });
 }
Exemple #8
0
 public void PropertyWrongMessage_Throws_PropertyIsValidException()
 {
     _ = Assert.Throws <InvalidErrorMessageException>(() =>
     {
         ModelValidator.Test(
             () => new Stormtrooper
         {
             IsCloned = true,
             Leader   = "Palpatine"
         },
             modelSetup =>
         {
             modelSetup.CheckProperty(r => r.Leader, ps => ps.IsInvalidWith(null, "Leader is required."));
         },
             _skipConverageChecksOptions);
     });
 }
Exemple #9
0
 public void ObjectWrongMessage_Throws_ModelIsValidException()
 {
     _ = Assert.Throws <InvalidErrorMessageException>(() =>
     {
         ModelValidator.Test(
             () => new Stormtrooper
         {
             IsCloned = true,
             Leader   = "Palpatine"
         },
             modelSetup =>
         {
             modelSetup.CheckClass(os => os.IsInvalidWith(r => r.IsCloned, false), "Trooper should be a clone.");
         },
             _skipConverageChecksOptions);
     });
 }
Exemple #10
0
 public void NotTestingPropertyAttribute_Throws_ValidationAttributeNotTestedException()
 {
     _ = Assert.Throws <ValidationAttributeNotTestedException>(() =>
     {
         ModelValidator.Test(
             () => new Rebel
         {
             Name    = "Luke",
             Surname = "Skywalker",
             Age     = 18
         },
             modelSetup =>
         {
             modelSetup.CheckProperty(r => r.Name, ps => ps.IsInvalidWith("Lukelongname"));     // Missing null check
         },
             _skipConverageChecksOptions);
     });
 }
Exemple #11
0
 public void ValidModelAfterUpdates_Throws_ModelIsValidException()
 {
     _ = Assert.Throws <ModelIsValidException>(() =>
     {
         ModelValidator.Test(
             () => new Stormtrooper
         {
             IsCloned = true,
             Leader   = "Palpatine"
         },
             modelSetup =>
         {
             modelSetup.CheckProperty(r => r.Leader, ps => ps
                                      .IsInvalidWith(null)            // Required
                                      .IsInvalidWith("Darth Vader")); // Valid
         },
             _skipConverageChecksOptions);
     });
 }
Exemple #12
0
 public void RequiredAttributeNotTested_Throws_ValidationAttributeNotTestedException()
 {
     _ = Assert.Throws <ValidationAttributeNotTestedException>(() =>
     {
         ModelValidator.Test(
             () => new Rebel
         {
             Name    = "Luke",
             Surname = "Skywalker",
             Age     = 18
         },
             modelSetup =>
         {
             modelSetup.CheckProperty(r => r.Name, ps => ps
                                      .IsInvalidWith("01234567890")); // MaxLenght
         },
             _skipConverageChecksOptions);
     });
 }
Exemple #13
0
 public void NotTestingClassAttribute_Throws_ValidationAttributeNotTestedException()
 {
     _ = Assert.Throws <ValidationAttributeNotTestedException>(() =>
     {
         ModelValidator.Test(
             () => new Rebel
         {
             Name    = "Luke",
             Surname = "Skywalker",
             Age     = 18
         },
             modelSetup =>
         {
         },
             new ModelValidatorOptions
         {
             CheckClassAttributesCoverage = true,
             CheckPropertiesCoverage      = false
         });
     });
 }
Exemple #14
0
 public void ValidModelAfterUpdates_Throws_ModelIsValidException()
 {
     _ = Assert.Throws <ModelIsValidException>(() =>
     {
         ModelValidator.Test(
             () => new Rebel
         {
             Name    = "Luke",
             Surname = "Skywalker",
             Age     = 18
         },
             modelSetup =>
         {
             modelSetup.CheckProperty(r => r.Name, ps => ps
                                      .IsInvalidWith(null)          // Required
                                      .IsInvalidWith("01234567890") // MaxLenght
                                      .IsInvalidWith("Anakin"));    // Valid
         },
             _skipConverageChecksOptions);
     });
 }
Exemple #15
0
        public void Complete_Succeed()
        {
            ModelValidator.Test(
                () => new Skywalker
            {
                Name   = "Luke",
                IsJedi = true
            },
                modelSetup =>
            {
                modelSetup.CheckClass(os => os.IsInvalidWith(r => r.IsJedi, false));

                modelSetup.CheckProperty(r => r.IsJedi, ps => ps.IsInvalidWith(false));
            },
                new ModelValidatorOptions
            {
                ServiceProviderSetupAction = (s) =>
                {
                    s.AddService <IJediService, JediService>();
                }
            });
        }
Exemple #16
0
 public void NotTestingProperty_Throws_PropertiesNotTestedException()
 {
     _ = Assert.Throws <PropertiesNotTestedException>(() =>
     {
         ModelValidator.Test(
             () => new Rebel
         {
             Name    = "Luke",
             Surname = "Skywalker",
             Age     = 18
         },
             modelSetup =>
         {
             modelSetup.CheckProperty(r => r.Name, ps => ps.IsInvalidWith(null).IsInvalidWith("Lukelongname"));
             modelSetup.CheckProperty(r => r.Surname, ps => ps.IsInvalidWith(null));
         },
             new ModelValidatorOptions
         {
             CheckClassAttributesCoverage = false,
             CheckPropertiesCoverage      = true
         });
     });
 }