Код: Выделить всё
actualResponse
Вот краткое описание сценария:
Класс TestSteps.cs, в котором вызываются эти методы:
Код: Выделить всё
public class TestSteps : BaseTest
{
// _result holds the actual results coming from context get cal
private Context _result = new();
// _SolutionExpectedResponse have expected response from json file.
private readonly Context _SolutionExpectedResponse = new();
public TestSteps()
{
string jsonstring = File.ReadAllText(@Path of response.json file);
_SolutionExpectedResponse = JsonConvert.DeserializeObject(jsonstring);
}
[When(@Call context api)]
public void WhenCallContextAPI()
{
_result = Context.GetAsync(token,resource).Result;
}
[Then(@Verify the response Values)]
public void ThenVerifyTheResponseValues()
{
ValidateDataValues(_result.Data, _SolutionExpectedResponse.Data, new string[] {"data"})
ValidateSensitiveDataValues(_result.SensitiveData, _SolutionExpectedResponse.SensitiveData, new string[] {"sensitiveData"})
}
}
Метод № 1:
Код: Выделить всё
Protected void ValidateDataValues(List actualResponse, List expectedResponse, string[] filterParams)
{
if (filterParams.contains("data"))
{
if(actualResponse !=null)
{
for(int i=0; i < expectedResponse.Count; i++)
{
if((actualResponse[i].Key !=null)
{
actualResponse[i].Key.Value.ToString().Should.BeEquivalentTo(expectedResponse[i].Key.Value.ToString());
}
}
return;
}
else
{
actualResponse.Should().BeNull();
}
}
}
Код: Выделить всё
Protected void ValidateSensitiveDataValues(List actualResponse, List expectedResponse, string[] filterParams)
{
if (filterParams.contains("sensitiveData"))
{
if(actualResponse !=null)
{
for(int i=0; i < expectedResponse.Count; i++)
{
if((actualResponse[i].Key !=null)
{
actualResponse[i].Key.Value.ToString().Should.BeEquivalentTo(expectedResponse[i].Key.Value.ToString());
}
}
return;
}
else
{
actualResponse.Should().BeNull();
}
}
}
ИЛИ< /p>
Вызвав метод №1 из метода №2 путем преобразования типа данных?
Подробнее здесь: https://stackoverflow.com/questions/752 ... t-datatype