public void CloseAnAssetTest() { IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl)); IServices services = new Services( metaModel, new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password)); // create a new story var projectId = Oid.FromToken("Scope:0", metaModel); var assetType = metaModel.GetAssetType("Story"); var story = services.New(assetType, projectId); var nameAttribute = assetType.GetAttributeDefinition("Name"); story.SetAttributeValue(nameAttribute, "My New Story"); services.Save(story); // closes the story var closeOperation = metaModel.GetOperation("Story.Inactivate"); var closeId = services.ExecuteOperation(closeOperation, story.Oid); var query = new Query(closeId.Momentless); var assetName = metaModel.GetAttributeDefinition("Story.Name"); var assetState = metaModel.GetAttributeDefinition("Story.AssetState"); query.Selection.Add(assetState); query.Selection.Add(assetName); QueryResult result = services.Retrieve(query); Asset closedStory = result.Assets[0]; Assert.AreEqual("Closed", closedStory.GetAttribute(assetState).Value.ToString()); }
public void GetSingleAssetTest() { IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl)); IServices services = new Services( metaModel, new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password)); var memberId = Oid.FromToken("Member:20", metaModel); var query = new Query(memberId); var nameAttribute = metaModel.GetAttributeDefinition("Member.Name"); var emailAttribute = metaModel.GetAttributeDefinition("Member.Email"); query.Selection.Add(nameAttribute); query.Selection.Add(emailAttribute); var result = services.Retrieve(query); Asset member = result.Assets[0]; Assert.IsNotNull(member); Assert.AreEqual("Administrator", member.GetAttribute(nameAttribute).Value); Assert.AreEqual("*****@*****.**", member.GetAttribute(emailAttribute).Value); }
public void full_working_example_with_basic_authentication() { // Setting up a basic connection with the connector and retrieving the Member with the ID 20 var dataConnector = new VersionOneAPIConnector(_prefix + "rest-1.v1/") .WithVersionOneUsernameAndPassword(_username, _password); var metaConnector = new VersionOneAPIConnector(_prefix + "meta.v1/"); IMetaModel metaModel = new MetaModel(metaConnector); IServices services = new Services(metaModel, dataConnector); var memberId = Oid.FromToken("Member:20", metaModel); var query = new Query(memberId); var memberName = metaModel.GetAttributeDefinition("Member.Name"); query.Selection.Add(memberName); var result = services.Retrieve(query); }
public void ReOpenAnAssetTest() { IMetaModel metaModel = new MetaModel(new VersionOneAPIConnector(_metaUrl)); IServices services = new Services( metaModel, new VersionOneAPIConnector(_dataUrl).WithVersionOneUsernameAndPassword(_username, _password)); // create a new story var projectId = Oid.FromToken("Scope:0", metaModel); var assetType = metaModel.GetAssetType("Story"); var story = services.New(assetType, projectId); var nameAttribute = assetType.GetAttributeDefinition("Name"); story.SetAttributeValue(nameAttribute, "My New Story"); services.Save(story); // closes the story var closeOperation = metaModel.GetOperation("Story.Inactivate"); var closeId = services.ExecuteOperation(closeOperation, story.Oid); //reopens the story var activateOperation = metaModel.GetOperation("Story.Reactivate"); var activeId = services.ExecuteOperation(activateOperation, story.Oid); var query = new Query(activeId.Momentless); var assetState = metaModel.GetAttributeDefinition("Story.AssetState"); query.Selection.Add(assetState); var result = services.Retrieve(query); Asset activeStory = result.Assets[0]; Assert.AreEqual("Active", activeStory.GetAttribute(assetState).Value.ToString()); }
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(); }