本文整理汇总了C#中Article.SetAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# Article.SetAttribute方法的具体用法?C# Article.SetAttribute怎么用?C# Article.SetAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Article
的用法示例。
在下文中一共展示了Article.SetAttribute方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteArticleAsyncTest
public async Task DeleteArticleAsyncTest()
{
// Create article
var now = DateTime.Now;
dynamic obj = new Article("object");
obj.intfield = 1;
obj.decimalfield = 10.0m;
obj.datefield = "2012-12-20";
obj.datetimefield = now.ToString("o");
obj.stringfield = "string value";
obj.textfield = "text value";
obj.boolfield = false;
obj.geofield = "11.5,12.5";
obj.listfield = "a";
obj.SetAttribute("attr1", "value1");
obj.SetAttribute("attr2", "value2");
CreateArticleResponse response = null;
response = await (new CreateArticleRequest()
{
Article = obj
}).ExecuteAsync();
Assert.IsNotNull(response);
Assert.IsNotNull(response.Status);
Assert.IsTrue(response.Status.IsSuccessful);
Assert.IsNotNull(response.Article);
Console.WriteLine("Created article id {0}", response.Article.Id);
Console.WriteLine("Time taken: {0} seconds", response.TimeTaken);
// Delete the article
var deleteArticleResponse = await (new DeleteArticleRequest()
{
Id = response.Article.Id,
Type = response.Article.Type
}).ExecuteAsync();
Assert.IsNotNull(deleteArticleResponse, "Delete articler response is null.");
Assert.IsTrue(deleteArticleResponse.Status.IsSuccessful == true,
deleteArticleResponse.Status.Message ?? "Delete article operation failed.");
// Try get the deleted article
var getArticleResponse = await (
new GetArticleRequest()
{
Id = response.Article.Id,
Type = response.Article.Type
}).ExecuteAsync();
Assert.IsNotNull(getArticleResponse, "Get article response is null.");
Assert.IsNull(getArticleResponse.Article, "Should not be able to get a deleted article.");
Assert.IsTrue(getArticleResponse.Status.Code == "404", "Error code expected was not 404.");
}
示例2: NewInstance
public static Article NewInstance()
{
Console.WriteLine("Creating new article instance without saving");
var now = DateTime.Now;
dynamic obj = new Article("object");
obj.intfield = 1;
obj.decimalfield = 10.0m;
obj.datefield = "2012-12-20";
obj.datetimefield = now.ToString("o");
obj.stringfield = "string value";
obj.textfield = "text value";
obj.boolfield = false;
obj.geofield = "11.5,12.5";
obj.listfield = "a";
obj.SetAttribute("attr1", "value1");
obj.SetAttribute("attr2", "value2");
return obj as Article;
}
示例3: DeleteArticleAsyncTest
public void DeleteArticleAsyncTest()
{
Exception fault = null;
var waitHandle = new ManualResetEvent(false);
var action = new Action(async () =>
{
try
{
// Create article
var now = DateTime.Now;
dynamic obj = new Article("object");
obj.intfield = 1;
obj.decimalfield = 10.0m;
obj.datefield = "2012-12-20";
obj.datetimefield = now.ToString("o");
obj.stringfield = "string value";
obj.textfield = "text value";
obj.boolfield = false;
obj.geofield = "11.5,12.5";
obj.listfield = "a";
obj.SetAttribute("attr1", "value1");
obj.SetAttribute("attr2", "value2");
var service = ObjectFactory.Build<IArticleService>();
CreateArticleResponse response = null;
response = await service.CreateArticleAsync(new CreateArticleRequest()
{
Article = obj
});
Assert.IsNotNull(response);
Assert.IsNotNull(response.Status);
Assert.IsTrue(response.Status.IsSuccessful);
Assert.IsNotNull(response.Article);
Console.WriteLine("Created article id {0}", response.Article.Id);
Console.WriteLine("Time taken: {0} seconds", response.TimeTaken);
// Delete the article
Status deleteArticleResponse = null;
deleteArticleResponse = await service.DeleteArticleAsync(new DeleteArticleRequest()
{
Id = response.Article.Id,
Type = response.Article.Type
});
Assert.IsNotNull(deleteArticleResponse, "Delete articler response is null.");
Assert.IsTrue(deleteArticleResponse.IsSuccessful == true, deleteArticleResponse.Message ?? "Delete article operation failed.");
// Try get the deleted article
var getArticleResponse = await service.GetArticleAsync(
new GetArticleRequest()
{
Id = response.Article.Id,
Type = response.Article.Type
});
Assert.IsNotNull(getArticleResponse, "Get article response is null.");
Assert.IsNull(getArticleResponse.Article, "Should not be able to get a deleted article.");
Assert.IsTrue(getArticleResponse.Status.Code == "404", "Error code expected was not 404.");
}
catch (Exception ex)
{
fault = ex;
}
finally
{
waitHandle.Set();
}
});
action();
waitHandle.WaitOne();
Assert.IsNull(fault);
}
示例4: UpdateArticleAttributeAsyncTest
public async Task UpdateArticleAttributeAsyncTest()
{
string attrToRemove = "one";
string attrPersist = "two";
string attrToAdd = "three";
// Create the article
dynamic article = new Article("object");
decimal pi = 22.0m / 7.0m;
article.intfield = 1;
article.decimalfield = pi;
//Add Attributes
article.SetAttribute(attrToRemove, attrToRemove);
article.SetAttribute(attrPersist, attrPersist);
var saved = await ObjectHelper.CreateNewAsync(article as Article);
// Get the newly created article
var afterFirstUpdate = await Articles.GetAsync("object", saved.Id);
Assert.IsNotNull(afterFirstUpdate);
Assert.IsTrue(afterFirstUpdate.Attributes.Count(tag => string.Equals(tag.Key, attrPersist, StringComparison.OrdinalIgnoreCase)) == 1);
Assert.IsTrue(afterFirstUpdate.Attributes.Count(tag => string.Equals(tag.Key, attrToRemove, StringComparison.OrdinalIgnoreCase)) == 1);
Assert.IsTrue(afterFirstUpdate.Attributes.Count() == 2);
//Add/Remove Attribute
afterFirstUpdate.RemoveAttribute(attrToRemove);
afterFirstUpdate.SetAttribute(attrToAdd, attrToAdd);
await afterFirstUpdate.SaveAsync();
var afterSecondUpdate = await Articles.GetAsync("object", saved.Id);
Assert.IsTrue(afterSecondUpdate.Attributes.Count(tag => string.Equals(tag.Key, attrPersist, StringComparison.OrdinalIgnoreCase)) == 1);
Assert.IsTrue(afterSecondUpdate.Attributes.Count(tag => string.Equals(tag.Key, attrToAdd, StringComparison.OrdinalIgnoreCase)) == 1);
Assert.IsTrue(afterSecondUpdate.Attributes.Count() == 2);
//Cleanup
await Articles.DeleteAsync(afterSecondUpdate.Type, afterSecondUpdate.Id);
}