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); })); }); }
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); }
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); }
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)); }); }); }
public void InvalidModelFunction_Throws_ModelIsInvalidException() { _ = Assert.Throws <ModelIsInvalidException>(() => { ModelValidator.Test( () => new Stormtrooper { IsCloned = false, Leader = "Palpatine" }, modelSetup => { }, _skipConverageChecksOptions); }); }
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); }
public void InvalidModelFunction_Throws_ModelIsInvalidException() { _ = Assert.Throws <ModelIsInvalidException>(() => { ModelValidator.Test( () => new Rebel { Name = "Luke", Age = 9 }, modelSetup => { }, _skipConverageChecksOptions); }); }
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); }); }
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); }); }
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); }); }
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); }); }
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); }); }
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 }); }); }
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); }); }
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>(); } }); }
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 }); }); }