logo
logo

Testing

The Fluent SDK provides a better way for developers to update a CH instance and then checks the results of their test.

Using Fluent SDK testing library through the Web Client SDK

The following example creates a new M.Tag entity and asserts the entity's properties once it's saved

var endpoint = new Uri("https://your.m.endpoint.com");
var oath = new OAuthPasswordGrant
{
    ClientId = "client_id",
    ClientSecret = "client_secret",
    UserName = "username",
    Password = "password" 
};

var fluentClient = new FluentClient(MClientFactory.CreateMClient(endpoint, oauth));

var culture = new CultureInfo("en-US");
var name = "A.Tag";
var label = "Tag Label";
var synonyms = "Tag 1, Tag 2, Tag 3";

var newTag =
    fluentClient.EntityFactory.Create("M.Tag")
        .SetPropertyValue("TagName", name)
        .SetPropertyValue("TagLabel", culture, label)
        .SetPropertyValue("Synonyms", culture, synonyms)
        .Save();

fluentClient.Entities.Get(newTag.Id.Value)
    .AssertPropertyEqual("TagName", name)
    .AssertPropertyEqual("TagLabel", culture, label)
    .AssertPropertyEqual("Synonyms", culture, synonyms);

The following example creates a new M.Tag entity with a child relation and asserts the entity's relations once it's saved

var endpoint = new Uri("https://your.m.endpoint.com");
var oath = new OAuthPasswordGrant
{
    ClientId = "client_id",
    ClientSecret = "client_secret",
    UserName = "username",
    Password = "password" 
};

var fluentClient = new FluentClient(MClientFactory.CreateMClient(endpoint, oauth));

var culture = new CultureInfo("en-US");

var parentTag =
    fluentClient.EntityFactory.Create("M.Tag")
        .SetPropertyValue("TagName", "IntegrationTest.TestParentTag1")
        .SetPropertyValue("TagLabel", culture, "Test Parent Label")
        .Save();

var childTag =
    fluentClient.EntityFactory.Create("M.Tag")
        .SetPropertyValue("TagName", "IntegrationTest.TestChildTag1")
        .SetPropertyValue("TagLabel", culture, "Test Child Label")
        .Save();

parentTag
    .Children(
        "TagToSelf",
        relation => relation.Children.Add(childTag.Id.Value))
    .Save();

parentTag.AssertRelation("TagToSelf", RelationRole.Parent, childTag);

A more detailed Walkthrough

Can we improve this article ? Provide feedback