'u serileştirirken tüm özellikleri sıfır olarak döndürür RestSharp'ın Execute yöntemini bir dinlenme bitiş noktası sorgulama ve bir POCO'ya serileştirme yöntemini kullanmanın çok basit bir örneğini yapmaya çalışıyorum. Ancak, çalıştığım her şey, NULL değeri olan tüm özelliklere sahip bir response.Data nesnesiyle sonuçlanır. İşte RestSharp istemcisi, JSON yanıtı
JSON yanıttır: Burada{
"Result":
{
"Location":
{
"BusinessUnit": "BTA",
"BusinessUnitName": "CASINO",
"LocationId": "4070",
"LocationCode": "ZBTA",
"LocationName": "Name of Casino"
}
}
}
burada benim test kodu
[TestMethod]
public void TestLocationsGetById()
{
//given
var request = new RestRequest();
request.Resource = serviceEndpoint + "/{singleItemTestId}";
request.Method = Method.GET;
request.AddHeader("accept", Configuration.JSONContentType);
request.RootElement = "Location";
request.AddParameter("singleItemTestId", singleItemTestId, ParameterType.UrlSegment);
request.RequestFormat = DataFormat.Json;
//when
Location location = api.Execute<Location>(request);
//then
Assert.IsNotNull(location.LocationId); //fails - all properties are returned null
}
Ve benim API kodu
public T Execute<T>(RestRequest request) where T : new()
{
var client = new RestClient();
client.BaseUrl = Configuration.ESBRestBaseURL;
//request.OnBeforeDeserialization = resp => { resp.ContentLength = 761; };
var response = client.Execute<T>(request);
return response.Data;
}
Ve nihayet, işte POCO
olduğunupublic class Location
{
public string BusinessUnit { get; set; }
public string BusinessUnitName { get; set; }
public string LocationId { get; set; }
public string LocationCode { get; set; }
public string LocationName { get; set; }
}
Ayrıca, yanıt üzerindeki ErrorException ve ErrorResponse özellikleri NULL.
Bu çok basit bir durum gibi gözüküyor, ancak bütün gün etrafta dolaşıyordum! Teşekkürler.
"requestParameter" seçeneğine sahip olmak yerine 'request.AddUrlSegment ("singleItemTestId", singleItemTestId) 'seçeneğini çağırdığınızda ne olur? –