[英]Can't load images from project during vs2012 load test
我正在嘗試使用Web性能和負載測試項目從Visual Studio 2012負載測試我的WCF服務。 我添加了如下所示的單元測試文件,並通過負載測試執行它們。 除了在我的測試對象中填充圖像byte []之外,其他所有內容似乎都可以正常工作。
單元測試
[TestMethod, TestCategory("WCF - Primary Tests")]
public void EventItem_Insert()
{
//Arrange
var service = new EventServiceReference.ServiceContractClient();
var item = UnitTestHelpers.EventItemFactory(Guid.NewGuid(), Guid.NewGuid());
Debug.WriteLine(item.Data.Length.ToString());
//Act
Guid pk = service.SaveEventItem(item);
//Assert
Assert.AreNotEqual(Guid.Empty, pk, "The key returned is empty");
}
從EventItemFactory調用圖像加載例程的代碼段。
EventItem.Data = (byte[])LoadTestImageFromProject();
編碼問題所在。 當我從“測試資源管理器”中運行單元測試時,此方法有效,但從“負載測試”中調用時,拋出了無效的參數。
public static byte[] LoadTestImageFromProject()
{
FileInfo fileInfo = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
string file = Path.Combine(fileInfo.DirectoryName, @"Assets\bg.JPG");
Bitmap bmp = new Bitmap(file);
ImageConverter converter = new ImageConverter();
byte[] byteArray = (byte[])converter.ConvertTo(bmp, typeof(byte[]));
return byteArray;
}
先謝謝您的幫助。
我沒有找到一個很好的解決方法,因此無法弄清楚如何在負載測試期間從項目中引用文件。
我將圖像添加到資源文件中,效果很好。
它與虛擬用戶如何進行測試有關,資源文件可用,但項目工件不可用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.