mardi 7 avril 2015

How to mock or test this method with sample values?

I have a method :



public IPlayerResponse GetPlayerStats(IPlayerRequest playerRequest)
{
string playerId = playerRequest.PlayerId;

string requestUri = playerId + "/evaluate";

var request = new HttpRequestMessage(HttpMethod.Post, requestUri)
{
Content = new StringContent
(JsonConvert.SerializeObject(playerRequest),
System.Text.Encoding.UTF8,
"application/json")
};

var response = _client
.SendAsync(request, CancellationToken.None)
.Result;
var responseContent = response.
Content
.ReadAsStringAsync()
.Result;



var playerResponseModel =
JsonConvert.DeserializeObject<PlayerResponseModel>(responseContent);
var playerResponse = _mapper
.Map<IPlayerResponse>(playerResponseModel);

return playerResponse;
}


The request interface:



public interface IPlayerRequest
{
IEnumerable<IPlayerStatsItem> Items { get; set; }
string PlayerId { get; set; }
}


I plan to write a test for this method and send the sample data for IPlayerRequest to get the response against a deployed end point. I have the TestSetup ready for hitting the endpoint.


What is the ideal way to mock the IPlayerRequest and populate it with some data to get a response?


Aucun commentaire:

Enregistrer un commentaire