我的单元测试调用(使用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