Мой модульный тест выглядит следующим образом
[TestMethod]
public async Task TestMethod1()
{
SvcRestClient client =
new SvcRestClient(new Uri("http://localhost:44395"),
new AnonymousCredential());
var tokenRequest = new TokenRequest
{
Username = "myusername",
Password = "p@ssword1"
};
tokenRequest.Validate();
var tokenResponse = await client.ApiRequestTokenPostWithHttpMessagesAsync(tokenRequest);
var content = await tokenResponse.Response.Content.ReadAsStringAsync();
Console.WriteLine(content); // displays {"token":"XXX"} where XXX is the token string
var authorisation = content;
var result = client.ApiJobByIdGet(4, authorisation); // errors here
}
Ошибка
Test method ClientSideTests.UnitTest1.TestMethod1 threw exception:
Microsoft.Rest.SerializationException: Unable to deserialize the response. ---> Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0
, когда сгенерированный код из клиента Add REST API VS2017 равен
/// <summary>
/// Returns Job Header for Id
/// </summary>
/// <param name='operations'>
/// The operations group for this extension method.
/// </param>
/// <param name='id'>
/// </param>
/// <param name='authorization'>
/// access token
/// </param>
public static JobHeader ApiJobByIdGet(this ISvcRestClient operations, int id, string authorization)
{
return Task.Factory.StartNew(s => ((ISvcRestClient)s).ApiJobByIdGetAsync(id, authorization), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
}
JobHeader - это просто документ, связанный с моим кодом.