public void GetInvalidValuesOfProperty() { IClassValidator cv = GetClassValidator(typeof(Address)); cv.GetInvalidValues(null, "blacklistedZipCode").Should().Be.Empty(); ActionAssert.Throws <ArgumentException>(() => cv.GetInvalidValues(new Suricato(), "blacklistedZipCode")); }
public void Dictionary() { IClassValidator validator = GetClassValidator(typeof(Tv)); Tv tv = new Tv(); tv.name = "France 2"; Show showOk = new Show(); showOk.name = "Tout le monde en parle"; Show showNok = new Show(); showNok.name = null; tv.shows.Add("Midnight", showOk); tv.shows.Add("Primetime", showNok); tv.shows.Add("Nothing", null); var values = validator.GetInvalidValues(tv).ToArray(); values.Should().Not.Be.Empty(); values.Single().PropertyPath.Should().Be.EqualTo("shows[Primetime].name"); //Inverted dictionary tv = new Tv(); tv.name = "France 2"; tv.validatableInKey = new Dictionary <Simple, string>(); tv.validatableInKey.Add(new Simple("Exalibur"), "Coll1"); tv.validatableInKey.Add(new Simple(), "Coll2"); values = validator.GetInvalidValues(tv).ToArray(); values.Should().Not.Be.Empty(); values.Single().PropertyPath.Should().Be.EqualTo("validatableInKey[null].name"); }
public void PastAndFuture() { IClassValidator validator = GetClassValidator(typeof(FooDate)); FooDate f = new FooDate(); f.Past = DateTime.MinValue; f.Future = DateTime.MaxValue; validator.GetInvalidValues(f).Should().Be.Empty(); f.Future = DateTime.Today.AddDays(1); //tomorrow f.Past = DateTime.Today.AddDays(-1); //yesterday validator.GetInvalidValues(f).Should().Be.Empty(); f.Future = DateTime.Today.AddDays(-1); //yesterday validator.GetInvalidValues(f).Should().Have.Count.EqualTo(1); f.Future = DateTime.Today.AddDays(1); //tomorrow f.Past = DateTime.Today.AddDays(1); //tomorrow validator.GetInvalidValues(f).Should().Have.Count.EqualTo(1); // note: using Milliseconds the Past constraint mail fail depending on the speed of your machine f.Future = DateTime.Now.AddMilliseconds(-1); f.Past = DateTime.Now.AddMilliseconds(+5); validator.GetInvalidValues(f).Should().Have.Count.EqualTo(2); }
public void Collection() { Tv tv = new Tv(); tv.name = "France 2"; Presenter presNok = new Presenter(); presNok.name = null; Presenter presOk = new Presenter(); presOk.name = "Thierry Ardisson"; tv.presenters.Add(presOk); tv.presenters.Add(presNok); IClassValidator validator = GetClassValidator(typeof(Tv)); var values = validator.GetInvalidValues(tv).ToArray(); values.Should().Not.Be.Empty(); values.Single().PropertyPath.Should().Be.EqualTo("presenters[1].name"); tv.presenters.Clear(); tv.dontNeedDeepValidation = new List <string>(); tv.dontNeedDeepValidation.Add("something"); values = validator.GetInvalidValues(tv).ToArray(); values.Should().Be.Empty(); tv.dontNeedDeepValidation.Add("something else"); values = validator.GetInvalidValues(tv).ToArray(); values.Should().Not.Be.Empty(); values.Single().PropertyPath.Should().Be.EqualTo("dontNeedDeepValidation"); }
protected override IEnumerable <IValidationError> InternalValidate(object source) { foreach (var iv in m_CV.GetInvalidValues(source)) { yield return(new InvalidValueValidationError(iv)); } }
public void GetInvalidValuesOfEntity() { IClassValidator cv = GetClassValidator(typeof(Address)); cv.GetInvalidValues(null).Should().Be.Empty(); ActionAssert.Throws <ArgumentException>(() => cv.GetInvalidValues(new Suricato())); }
public void TestInh() { IClassValidator classValidator = GetClassValidator(typeof(Dog)); Dog dog = new Dog(); classValidator.GetInvalidValues(dog).Should().Have.Count.EqualTo(3); dog.FavoriteBone = "DE"; //failure classValidator.GetInvalidValues(dog).Should().Have.Count.EqualTo(3); }
public void ValidatorAttribute() { IClassValidator userValidator = GetClassValidator(typeof(User)); var user = new User(); user.Oib = "84833009251"; IEnumerable <InvalidValue> iv = userValidator.GetInvalidValues(user); iv.Should().Not.Be.Empty(); iv.Single().Message.Should().Be.EqualTo("OIB nije ispravan."); user.Oib = "84833009254"; userValidator.GetInvalidValues(user).Should().Be.Empty(); }
public void ImageValidationTest() { WebImage webImage = new WebImage(); webImage.position = 1; webImage.filename = "testunknown"; IClassValidator validator = GetClassValidator(typeof(WebImage)); validator.GetInvalidValues(webImage).Should().Not.Be.Empty(); webImage.filename = Path.GetTempFileName(); validator.GetInvalidValues(webImage).Should().Be.Empty(); }
public void ValidatorAttribute() { IClassValidator userValidator = GetClassValidator(typeof(Usuario)); var u = new Usuario(); userValidator.GetInvalidValues(u).Should().Be.Empty(); u.Cep = "40280902x"; var iv = userValidator.GetInvalidValues(u); iv.Should().Not.Be.Empty(); iv.Single().Message.Should().Be.EqualTo("Número de CEP inválido."); u.Cep = "40280902"; userValidator.GetInvalidValues(u).Should().Be.Empty(); }
public void TestInvalidIPAddresses() { var computer = new Computer(); IClassValidator classValidator = GetClassValidator(typeof(Computer)); computer.IpAddress = "aaa.bbb.ccc"; classValidator.GetInvalidValues(computer).Should("aaa.bbb.ccc is not a valid IP").Not.Be.Empty(); computer.IpAddress = "260.255.255.255"; classValidator.GetInvalidValues(computer).Should("260.255.255.255 is not a valid IP").Not.Be.Empty(); computer.IpAddress = "192.999.0.0"; classValidator.GetInvalidValues(computer).Should("192.999.0.0 is not a valid IP").Not.Be.Empty(); }
public void ValidatorAttribute() { IClassValidator userValidator = GetClassValidator(typeof(Cliente)); Cliente c = new Cliente(); userValidator.GetInvalidValues(c).Should().Be.Empty(); c.Piva = "00007016322"; var iv = userValidator.GetInvalidValues(c); iv.Should().Not.Be.Empty(); iv.Single().Message.Should().Be.EqualTo("Partita IVA incorretta."); c.Piva = "00523580520"; userValidator.GetInvalidValues(c).Should().Be.Empty(); }
public void ValidatorAttribute() { IClassValidator userValidator = GetClassValidator(typeof(Cliente)); Cliente c = new Cliente(); userValidator.GetInvalidValues(c).Should().Be.Empty(); c.CodiceFiscale = "BRTLSS45H06L840Y"; var iv = userValidator.GetInvalidValues(c); iv.Should().Not.Be.Empty(); iv.Single().Message.Should().Be.EqualTo("Codica fiscale FORMALMENTE incorretto."); c.CodiceFiscale = "BRTLSS45H06L840X"; userValidator.GetInvalidValues(c).Should().Be.Empty(); }
public void SizeArrayWithValid() { HasArrayWithValid hsc = new HasArrayWithValid(); IClassValidator vtor = GetClassValidator(typeof(HasArrayWithValid)); hsc.Shows = new Show[] { new Show("s1"), new Show("s2") }; vtor.GetInvalidValues(hsc).Should().Be.Empty(); hsc.Shows = new Show[] { new Show("s1"), new Show(null) }; vtor.GetInvalidValues(hsc).Should().Not.Be.Empty(); hsc.Shows = new Show[] { new Show("s1"), new Show("s2"), new Show("s3"), new Show("s4"), new Show("s5") }; vtor.GetInvalidValues(hsc).Should().Have.Count.EqualTo(1); }
public void ValidatorAttribute() { IClassValidator userValidator = GetClassValidator(typeof(Persona)); Persona p = new Persona(); userValidator.GetInvalidValues(p).Should().Be.Empty(); p.Cedula = "44443333"; var iv = userValidator.GetInvalidValues(p); iv.Should().Not.Be.Empty(); iv.Single().Message.Should().Be.EqualTo("Cedula de identidad incorrecta."); p.Cedula = "11748364"; userValidator.GetInvalidValues(p).Should().Be.Empty(); }
public void Size() { HasCollection hc = new HasCollection(); IClassValidator vtor = GetClassValidator(typeof(HasCollection)); hc.StringCollection = new List <string>(new string[] { "cuidado", "con", "el", "carancho!" }); vtor.GetInvalidValues(hc).Should().Be.Empty(); hc.StringCollection = new List <string>(new string[] { "pombero" }); vtor.GetInvalidValues(hc).Should().Not.Be.Empty(); hc.StringCollection = new List <string>(new string[] { "Los", "Pekes", "Chicho", "Nino", "Nono", "Fito" }); vtor.GetInvalidValues(hc).Should().Not.Be.Empty(); }
public void TestValidIPAddresses() { var computer = new Computer { IpAddress = "192.168.0.1" }; IClassValidator classValidator = GetClassValidator(typeof(Computer)); classValidator.GetInvalidValues(computer).Should().Be.Empty(); computer.IpAddress = "255.255.255.255"; classValidator.GetInvalidValues(computer).Should().Be.Empty(); computer.IpAddress = "192.168.0.0"; classValidator.GetInvalidValues(computer).Should().Be.Empty(); }
public void FieldIsNotNullNotEmpty() { Boo boo = new Boo(); boo.field = null; IClassValidator validator = GetClassValidator(typeof(Boo)); var invalids = validator.GetInvalidValues(boo); invalids.Should("null value cannot be valid").Not.Be.Empty(); boo.field = string.Empty; invalids = validator.GetInvalidValues(boo); invalids.Should("empty value cannot be valid").Not.Be.Empty(); }
public void ValidatorAttribute() { IClassValidator personValidator = GetClassValidator(typeof(Person)); var p = new Person(); personValidator.GetInvalidValues(p).Should().Be.Empty(); p.NIP = "7792125257"; var iv = personValidator.GetInvalidValues(p); iv.Should().Not.Be.Empty(); iv.Single().Message.Should().Be.EqualTo("Nieprawidlowy numer NIP."); p.NIP = "77-92-125-257"; personValidator.GetInvalidValues(p).Should().Be.Empty(); }
public void TestDeepValid() { IClassValidator formValidator = GetClassValidator(typeof(Form)); Address a = new Address(); Member m = new Member(); m.Address = a; Form f = new Form(); f.Member = m; formValidator.GetInvalidValues(f).Should().Have.Count.EqualTo(1); m.Address.City = "my city"; formValidator.GetInvalidValues(f).Should().Be.Empty(); }
public void GetCombinedDefinition() { Person person = new Person(); person.Name = "MyName"; person.IsMale = true; person.Address = "Address"; person.friends = 21; IClassValidator validator = GetClassValidator(typeof(Person)); validator.GetInvalidValues(person).Should("Person cannot have more than 20 friends by Xml").Have.Count.EqualTo(1); person.friends = 1; validator.GetInvalidValues(person).Should("Person cannot have less than 2 friends by Attribute").Have.Count.EqualTo(1); }
public void LengthTest() { IClassValidator validator = GetClassValidator(typeof(FooLength)); FooLength f1 = new FooLength(1, "hola"); validator.GetInvalidValues(f1).Should().Be.Empty(); FooLength f2 = new FooLength(1, string.Empty); validator.GetInvalidValues(f2).Should().Not.Be.Empty(); FooLength f3 = new FooLength(1, null); validator.GetInvalidValues(f3).Should().Not.Be.Empty(); }
public void IPIsInSubnetByPrefix() { Controller controller = new Controller(); controller.Name = null; controller.IP = "192.168.1.1"; IClassValidator validator = GetClassValidator(typeof(Controller)); validator.GetInvalidValues(controller).Should().Have.Count.EqualTo(2); controller.IP = "192.168.2.1"; validator.GetInvalidValues(controller).Should().Have.Count.EqualTo(1); controller.Name = "Controller"; validator.GetInvalidValues(controller).Should().Be.Empty(); }
public void ValidatorAttribute() { IClassValidator personValidator = GetClassValidator(typeof(Person)); var p = new Person(); personValidator.GetInvalidValues(p).Should().Be.Empty(); p.PostalCode = "1234"; var iv = personValidator.GetInvalidValues(p); iv.Should().Not.Be.Empty(); iv.Single().Message.Should().Be.EqualTo("Nieprawidlowy kod pocztowy."); p.PostalCode = "12-345"; personValidator.GetInvalidValues(p).Should().Be.Empty(); }
public void ValidatorAttribute() { IClassValidator personValidator = GetClassValidator(typeof(Person)); var p = new Person(); personValidator.GetInvalidValues(p).Should().Be.Empty(); p.PESEL = "4904050158"; var iv = personValidator.GetInvalidValues(p); iv.Should().Not.Be.Empty(); iv.Single().Message.Should().Be.EqualTo("Nieprawidlowy numer PESEL."); p.PESEL = "49040501580"; personValidator.GetInvalidValues(p).Should().Be.Empty(); }
public void ValidatorAttribute() { IClassValidator personValidator = GetClassValidator(typeof(Person)); var p = new Person(); personValidator.GetInvalidValues(p).Should().Be.Empty(); p.REGON = "590094654"; var invalidValues = personValidator.GetInvalidValues(p); invalidValues.Should().Not.Be.Empty(); invalidValues.Single().Message.Should().Be.EqualTo("Nieprawidlowy numer REGON."); p.REGON = "590096454"; personValidator.GetInvalidValues(p).Should().Be.Empty(); }
public void OneToOneValid() { IClassValidator vtor = GetClassValidator(typeof(Blog)); Blog b = new Blog(); b.Author = new Author(); vtor.GetInvalidValues(b).Should().Have.Count.EqualTo(2); }
public void NullString() { FooNotEmpty f = new FooNotEmpty(null); IClassValidator vtor = GetClassValidator(typeof(FooNotEmpty)); vtor.GetInvalidValues(f).Should().Not.Be.Empty(); }
public void ValidatorAttribute() { IClassValidator userValidator = GetClassValidator(typeof(Cliente)); Cliente c = new Cliente(); var iv = userValidator.GetInvalidValues(c); iv.Should().Be.Empty(); c.Cuit = "AA"; iv = userValidator.GetInvalidValues(c); iv.Should().Not.Be.Empty(); iv.Single().Message.Should().Be.EqualTo("CUIT no valido."); c.Cuit = "20017391322"; userValidator.GetInvalidValues(c).Should().Be.Empty(); c.CustomCuit = "AA"; iv = userValidator.GetInvalidValues(c); iv.Should().Not.Be.Empty(); iv.Single().Message.Should().Be.EqualTo("Not valid CUIT."); }
public void Circularity() { Brother emmanuel = new Brother(); emmanuel.Name = "Emmanuel"; Address.blacklistedZipCode = "666"; Address address = new Address(); address.InternalValid = true; address.Country = "France"; address.Id = 3; address.Line1 = "Rue des rosiers"; address.State = "NYC"; address.Zip = "33333"; address.floor = 4; emmanuel.Address = address; Brother christophe = new Brother(); christophe.Name = "Christophe"; christophe.Address = address; emmanuel.YoungerBrother = christophe; christophe.Elder = emmanuel; IClassValidator classValidator = GetClassValidator(typeof(Brother)); var invalidValues = classValidator.GetInvalidValues(emmanuel); invalidValues.Should().Be.Empty(); christophe.Name = null; invalidValues = classValidator.GetInvalidValues(emmanuel).ToArray(); invalidValues.Should("Name cannot be null").Not.Be.Empty(); Assert.AreEqual(emmanuel, invalidValues.First().RootEntity); Assert.AreEqual("YoungerBrother.Name", invalidValues.First().PropertyPath); christophe.Name = "Christophe"; address = new Address(); address.InternalValid = true; address.Country = "France"; address.Id = 4; address.Line1 = "Rue des plantes"; address.State = "NYC"; address.Zip = "33333"; address.floor = -100; christophe.Address = address; invalidValues = classValidator.GetInvalidValues(emmanuel); invalidValues.Should("Floor cannot be less than -2").Not.Be.Empty(); }
private static void RunSerializationTest(IClassValidator cv) { Address a = new Address(); Address.blacklistedZipCode = null; a.Country = "Australia"; a.Zip = "1221341234123"; a.State = "Vic"; a.Line1 = "Karbarook Ave"; a.Id = 3; var validationMessages = cv.GetInvalidValues(a); // All work before serialization validationMessages.Should().Have.Count.EqualTo(2); //static field is tested also validationMessages.Select(iv => iv.Message).Satisfy(vm => vm.All(m => m.StartsWith("prefix_"))); // Serialize and deserialize ClassValidator cvAfter = (ClassValidator)SerializationHelper.Deserialize(SerializationHelper.Serialize(cv)); validationMessages = cvAfter.GetInvalidValues(a); // Now test after validationMessages.Should().Have.Count.EqualTo(2); //static field is tested also validationMessages.Select(iv => iv.Message).Satisfy(vm => vm.All(m => m.StartsWith("prefix_"))); }
private static void RunSerializationTest(IClassValidator cv) { Address a = new Address(); Address.blacklistedZipCode = null; a.Country = "Australia"; a.Zip = "1221341234123"; a.State = "Vic"; a.Line1 = "Karbarook Ave"; a.Id = 3; InvalidValue[] validationMessages = cv.GetInvalidValues(a); // All work before serialization Assert.AreEqual(2, validationMessages.Length); //static field is tested also Assert.IsTrue(validationMessages[0].Message.StartsWith("prefix_")); Assert.IsTrue(validationMessages[1].Message.StartsWith("prefix_")); // Serialize and deserialize ClassValidator cvAfter = (ClassValidator)SerializationHelper.Deserialize(SerializationHelper.Serialize(cv)); validationMessages = cvAfter.GetInvalidValues(a); // Now test after Assert.AreEqual(2, validationMessages.Length); //static field is tested also Assert.IsTrue(validationMessages[0].Message.StartsWith("prefix_")); Assert.IsTrue(validationMessages[1].Message.StartsWith("prefix_")); }