我的單元測試調用(使用MWSClientCsRuntime)亞馬遜MWS API在ListMatchingProducts
操作的C#.NET類。
問題
亞馬遜MWS API與產品數據隨時都在變化,所以我想能夠起訂量的ListMatchingProductsResponse
對象API返回一個移動的目標。我可以使用MWS暫存器獲取API響應,並將它們存儲在xml文件中。但隨後,在單元測試中,我需要從這些文件中的數據對象轉換成一個ListMatchingProductsResponse
對象。
問題
我怎麼能這個XML數據加載到ListMatchingProductsResponse
對象? (我注意到,對象具有ReadFragmentsFrom
方法,但我看不出這可能是使用)。
代碼
[TestClass]
public class PossibleAmazonProductMatchesTests
{
string testDataDirectory = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + @"\Test data";
[TestMethod]
public void FindSpanners()
{
// Arrange
ListMatchingProductsRequest request = new ListMatchingProductsRequest("secret key", "market id", "spanner");
ListMatchingProductsResult result = new ListMatchingProductsResult();
ListMatchingProductsResponse response = new ListMatchingProductsResponse();
string xmlString = File.ReadAllText(this.testDataDirectory + @"\Spanners Response.xml");
// *** The issue - How do I coerce xmlString into response? ***
var client = new Mock<MarketplaceWebServiceProductsClient>();
client.Setup(c => c.ListMatchingProducts(request)).Returns(response);
// Act
// This is the method being tested. It calls ListMatchingProducts which is being mocked.
PossibleAmazonProductMatches possibleAmazonProductMatches = new PossibleAmazonProductMatches("spanners", client);
// Assert
Assert.IsTrue(possibleAmazonProductMatches.SpannersFound == true);
}
}
提供一個[MCVE](代碼),演示場景,更好地解釋了你的問題。 – Nkosi
@Nkosi全部完成。 – ifinlay
這看起來像一個簡單的情況,必須讀取將XML從XML反序列化到所需對象類型的XML文件。只是想確保我明白你想做什麼。 – Nkosi