开发者

Implicitly typed array of triplets

开发者 https://www.devze.com 2023-01-30 02:40 出处:网络
I have a unit test method: private bool TestCompatibility(string type1, string type2, bool should开发者_如何学运维BeCompatible)

I have a unit test method:

private bool TestCompatibility(string type1, string type2, bool should开发者_如何学运维BeCompatible)
{
}

As it "knows" which types are (designed) compatible, it makes a call to the unit that is being tested and looks for errors. Errors should appear for incompatible types only, so the method tests, is units type-checking code right-implemented or not.

The question: how have I write the triplets collection?

I want something like:

var ar = { { "Num", "Num", true }, { "Num", "Datetime", false } };
foreach (var triplet in ar)
{
    // ???
}

with implicit typing.

P.S. I know that I can use attributes along with NUnit. Nevertheless, I want to see, how it can be written without libraries.

Regards,


I don't know if this is what you are looking for, but you could make use of anonymous types:

var ar = new[] { 
    new { Type1 = "Num", Type2 = "Num", Compatible = true }, 
    new { Type1 = "Num", Type2 = "Datetime", Compatible = false } 
};
foreach (var triplet in ar)
{
    TestCompatibility(triplet.Type1, triplet.Type2, triplet.Compatible);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号