0

I am having a brain freeze.

The response I am getting back from a web api post is;

<string>985c4198-8892-4738-8f85-d9adf5ff474a</string>

which is sent back using;

return myGuid.ToString();

I want to be able to unit test the response, but for the life of me cannot think of how to do it. I need to be able to check that it is a Guid. I believe I am missing a step to 'deserialize' the response into a typeof(string) and then I can TryParse(), but this is where my mind is going wrong tonight.

4

1 に答える 1

0

何かのようなもの

Guid g = Guid.Empty();

string webApiResult = GetApiResult();

webApiResult = webApiResult.Replace("<string>", string.Empty);
webApiResult = webApiResult.Replace("</string>", string.Empty);

Assert.IsTrue(Guid.TryParse(webApiResult , out g));

重要なのは、解析が成功したかどうかを示すブール値を返す TryParse を使用することです。

于 2012-12-14T20:42:12.997 に答える