public void TestScanForSingleFieldRepeateScanner() { var obj = new Simple1Field(); var ts = new TypeScanner(obj.GetType()); ValidationUnitCollection vc = ts.Scan(); Assert.AreEqual(1, vc.Count, "Wrong Number of Attributes scanned"); Assert.That(((SingleValidatorValidationUnit)vc[0]).Validator, Is.InstanceOf(typeof(RequiredValidator)), "Wrong Attribute Type"); ValidationUnitCollection anotherscan = ts.Scan(); Assert.AreEqual(1, anotherscan.Count, "Wrong Number of Attributes scanned"); Assert.That(((SingleValidatorValidationUnit)anotherscan[0]).Validator, Is.InstanceOf(typeof(RequiredValidator)), "Wrong Attribute Type"); }
public ConfigurationFactory() { _configurationType = ConfigurationManager.AppSettings["ConfigurationType"]; _configurationTypes = TypeScanner.Scan(cfg => { cfg.AssemblyContainingType(typeof(ICimplicityViewsConfiguration)); cfg.AddAllTypesOf <ICimplicityViewsConfiguration>(); }).ToList(); }
public void TestScanForTypeValidator() { var obj = new SimpleTypeValidation(); var ts = new TypeScanner(obj.GetType()); ValidationUnitCollection vc = ts.Scan(); Assert.AreEqual(1, vc.Count, "Wrong Number of Attributes scanned"); Assert.That(((SingleValidatorValidationUnit)vc[0]).Validator, Is.InstanceOf(typeof(ConstantResultValidator)), "Wrong Attribute Type"); }
public void ScannerInheritedTest() { var v = new Core.Validator(); ChildEntity bes = new ChildEntity(); var ts = new TypeScanner(bes.GetType()); ValidationUnitCollection vc = ts.Scan(); Assert.That(vc, Has.Count.EqualTo(2)); Assert.That(vc[1].ErrorMessage.Message, Is.EqualTo("This is a required field")); }
public void ScanForCounters() { var types = TypeScanner.Scan(scan => { scan.AssembliesFromApplicationBaseDirectory(); scan.AddAllTypesOf <CounterCategory>(); }); types.Each(Register); }
public void RegisterAllValidatorsInAssembly <T>() { var types = TypeScanner.Scan(cfg => { cfg.AddAllTypesOf <EnvironmentValidator>(); cfg.AssemblyContainingType <T>(); }); types.Each(_repository.AddCheck); }
internal static T FindController <T>(string root) where T : IController { try { var controllers = new List <Type>(); controllers.AddRange(Scanner.Scan <T>()); foreach (var controller in controllers) { var ctrl = (T)Activator.CreateInstance(controller); if (ctrl != null && ctrl.Path.Equals(root)) { return(ctrl); } } } catch { } return(ObjectExtensions.As <T>(null)); }
static void Main(string[] args) { XmlConfigurator.Configure(); var types = TypeScanner.Scan(x => { x.AssembliesFromApplicationBaseDirectory(); }).Where(x => x.Namespace == "V1Antlr.Sample").ToArray(); var metaModel = new MetaModel(); metaModel.RegisterTypes(types); var testTokens = new[] { "Product.ID", "Product.Title", "Product.BodyHtml", "Product.Variants.Price.@Min", "OrderLineItem.Order.Name", "OrderLineItem.Order.CreatedAt", "OrderLineItem.Quantity", "OrderLineItem.Title", "OrderLineItem.VariantTitle", "OrderLineItem.Order.CreatedAt", //"Product.Visible", "OrderLineItem.Product", "OrderLineItem.Order.ID", "Product.Images[(Position='1'|Position='2');(Position>'0')].Source", "OrderLineItem.Properties[Name='Add a Monogram'].Value", "OrderLineItem.Properties[Name='Custom Text'].Value", "OrderLineItem.Properties[Name='Font'].Value", "OrderLineItem.Properties[Name='Thread Color'].Value", "OrderLineItem.Properties[Name='Color'].Value", "Order.LineItems.Properties[Name='Color'].Value", "Order.LineItems[+Properties;Quantity>'0'].Properties[Value!=''].Value" //"Product.Url", // Calculated? }; foreach (var testToken in testTokens) { var attr = metaModel.GetAttributeDefinition(testToken); Console.WriteLine(attr.Token); } Query query = QueryBuilder.For("Product", metaModel) .Select("Variants.Title", "Variants.Images", "Variants.Images.@Count", "Variants.Product.ID") //.Where("ID='3'") //.Where("Variants;ID>'0'") //.Order("Title", "-BodyHtml", "+ID") //.Skip(1) //.Take(10) .ToQuery(); var products = new Product[] { new Product { ID = 1, Title = "Product #1", BodyHtml = "Product #1 Body", }, new Product { ID = 2, Title = "Product #2", BodyHtml = "Product #2 Body", }, new Product { ID = 3, Title = "Product #3", BodyHtml = "Product #3 Body", Variants = new List <ProductVariant> { new ProductVariant { ID = 30, Price = 30.30m, Quantity = 30, Title = "Variant 30", Images = new List <ProductImage> { new ProductImage { ID = 300, Position = 1, Source = "http://google.com" }, new ProductImage { ID = 301, Position = 2, Source = "http://microsoft.com" }, new ProductImage { ID = 302, Position = 3, Source = "http://amazon.com" } } }, new ProductVariant { ID = 31, Price = 31.31m, Quantity = 31, Title = "Variant 31" }, new ProductVariant { ID = 32, Price = 32.32m, Quantity = 32, Title = "Variant 32" }, } }, new Product { ID = 4, Title = "Product #4", BodyHtml = "Product #4 Body", Variants = new List <ProductVariant> { new ProductVariant { ID = 40, Price = 40.40m, Quantity = 40, Title = "Variant 40" }, new ProductVariant { ID = 41, Price = 41.41m, Quantity = 41, Title = "Variant 41" }, new ProductVariant { ID = 42, Price = 42.42m, Quantity = 42, Title = "Variant 42" }, new ProductVariant { ID = 43, Price = 43.43m, Quantity = 43, Title = "Variant 43" }, } }, }; var sortQuery = QueryBuilder.For("Product", metaModel).Select("ID").Order("-ID").ToQuery(); var sorted = products.AsQueryable().ApplyQuery(sortQuery); var selected = products.AsQueryable().ApplyQuery(query); foreach (var asset in selected.Assets) { Console.WriteLine("=========="); var titlesDef = metaModel.GetAttributeDefinition("Product.Variants.Title"); var imagesDef = metaModel.GetAttributeDefinition("Product.Variants.Images"); var titles = asset.GetAttributeValue <IEnumerable <string> >(titlesDef).ToList(); var images = asset.GetAttributeValue <IEnumerable <object> >(imagesDef).ToList(); foreach (var attributeDefinition in query.Selection) { var value = asset.GetAttributeValue <object>(attributeDefinition); Console.WriteLine("\t{0}={1}", attributeDefinition.Name, value); } } var singleRelationJoinQuery = QueryBuilder.For("ProductImage", metaModel).Select("Product.Title").ToQuery(); var testImages = new List <ProductImage> { new ProductImage { ID = 1, Product = new Product { ID = 11, Title = "Product #11" } }, new ProductImage { ID = 2, Product = new Product { ID = 22, Title = "Product #22" } }, new ProductImage { ID = 3, Product = new Product { ID = 33, Title = "Product #33" } }, }; var singleRelationJoinResults = testImages.AsQueryable().ApplyQuery(singleRelationJoinQuery); Console.WriteLine("Done"); Console.ReadLine(); }