[英]Gallio can't run test from console
i'm having a problem running an integration test through Gallio. 我在通过Gallio进行集成测试时遇到问题。 The test works fine when I run it with Testdrive.NET or through the integrated Gallio in Visual Studio.
当我使用Testdrive.NET或通过Visual Studio中的集成Gallio运行该测试时,它运行良好。 When I'm trying to run it through the console (like our nant scripts do) it fails.
当我尝试通过控制台运行它时(就像我们的nant脚本一样),它失败了。 The message received is this:
收到的消息是这样的:
[failed] Test TenForce.Execution.Api2.OData.Tests/AttachmentIntegrationTests/Att achmentUpload Execute System.ServiceModel.CommunicationObjectFaultedException: The communication objec t, System.Data.Services.DataServiceHost, cannot be used for communication becaus e it is in the Faulted state.
[失败]测试TenForce.Execution.Api2.OData.Tests / AttachmentIntegrationTests / AttachmentUpload执行System.ServiceModel.CommunicationObjectFaultedException:通信对象System.Data.Services.DataServiceHost由于存在故障,因此无法用于通信州。 at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout) at System.ServiceModel.ServiceHostBase.System.IDisposable.Dispose() at TenForce.Execution.Api2.OData.Tests.IntegrationTests.AttachmentIntegration Tests.AttachmentUpload() in D:\\Users\\arne.de.herdt.TENFORCE2\\Documents\\Developme nt\\Projects\\Robinson\\TenForce.Execution.Api2.OData.Tests\\IntegrationTests\\Attach mentIntegrationTests.cs:line 83
D: \\ Users \\ arne.de.herdt.TENFORCE2 \\ Documents \\ Developme nt \\ Projects \\ Robinson \\ TenForce.Execution.Api2.OData.Tests \\ IntegrationTests \\ Attach mentIntegrationTests.cs:line 83
Disposing the test runner.
处置测试运行器。 Stop time: 16:45 (Total execution time: 20,515 seconds)
停止时间:16:45(总执行时间:20515秒)
1 run, 0 passed, 1 failed, 0 inconclusive, 0 skipped
运行1次,通过0次,失败1次,不确定0次,跳过0次
The complete commandline is the following: 完整的命令行如下:
Gallio.Echo.exe /r:IsolatedProcess TenFor ce.Execution.Api2.OData.Tests.dll /f:Namespace:TenForce.Execution.Api2.OData.Tes ts.IntegrationTests
Gallio.Echo.exe / r:IsolatedProcess TenFor ce.Execution.Api2.OData.Tests.dll / f:命名空间:TenForce.Execution.Api2.OData.Tes ts.IntegrationTests
I have no idea what is causing this problem in Gallio. 我不知道是什么导致了Gallio中的问题。 It works from VS but not on the build agent or console.
它可以从VS运行,但不能在构建代理或控制台上使用。 The source code of the test is this:
测试的源代码是这样的:
using System.Data.Services;
using System.ServiceModel;
using System.ServiceModel.Description;
namespace TenForce.Execution.Api2.OData.Tests.IntegrationTests
{
using System;
using System.Collections.Generic;
using System.ServiceModel.Web;
using MbUnit.Framework;
using Objects;
using Helpers;
using Test.Attributes;
/// <summary>
/// <para>This class contains all the integration tests to verify the correct working conditions for attachment entities.</para>
/// </summary>
public class AttachmentIntegrationTests : BaseIntegrationTest
{
/// <summary>
/// <para>This test will try to create a new attachment on an item using a local file.</para>
/// </summary>
[Test, MaxDuration]
public void AttachmentUpload()
{
#region Test Preparation
// Prepare a Workspace
var workspace = CreateWorkspaceObject();
Assert.IsTrue(Factory.CreateApi().Workspaces.Create(workspace), "Expected the test workspace to be created.");
// Prepare a List
var list = CreateList();
list.Workspace = workspace;
list.ItemType = new ItemType {Id = 5};
Assert.IsTrue(Factory.CreateApi().Lists.Create(list), "Expected the test list to be created.");
// Prepare an Item.
var itemFields = new List<ItemField>
{
new ItemField {FieldId = "SF19", Type = "List", ValueId = list.Id},
new ItemField {FieldId = "SF2", Type = "Title", Value = string.Format("I {0}", DateTime.Now)},
new ItemField {FieldId = "SF4", Type = "AssignedTo", ValueId = 1}
};
var item = new Item { ItemFields = itemFields.ToArray() };
Assert.IsTrue(Factory.CreateApi().Items.Create(item), "Expected the test item to be created.");
#endregion
using (var host = new DataServiceHost(typeof (Web.Api), new[] {BaseUri}))
{
// Start the host
host.Open();
// Create a new WebClient to create a call to the attachments resource
var client = new ODataClient {BaseUri = BaseUri, Username = "sadmin", Password = string.Empty};
// Send the file contents to the service using the correct url.
string response = client.UploadAttachment(GetTestFileLocation("ReportingTest.xls"), item.Id);
var parser = new ODataParser();
parser.LoadResponse(response);
// Fetch the Id of the Attachment, this should be greater than 0.
int attachmentId = parser.GetEntityId();
Assert.IsTrue(attachmentId > 0, "Expected the Id to be greater than zero.");
// Verify if the item is coupled to the correct Item.
response = client.GetResource(string.Format("Attachments({0})/Item", attachmentId));
parser.LoadResponse(response);
int itemId = parser.GetEntityId();
Assert.IsTrue(itemId == item.Id, "Expected the linked item to have a matching Id.");
// Change the filename of the uploaded file and verify whether the file is properly renamed.
client.UpdateProperty(string.Format("Items({0})/Attachments({1})/Filename/$value", itemId, attachmentId), "uploaded_excel.xls");
// Verify if the changes made it to the database.
Attachment att = Factory.CreateApi().Attachments.Read(attachmentId);
Assert.AreEqual("uploaded_excel.xls", att.Filename, "Expected the data to be changed on the entity.");
Assert.IsTrue(System.IO.File.Exists(Factory.CreateApi().Attachments.GetAttachmentPath(att, false)), "Expected the file to be present on the hard drive.");
// Close the host properly
host.Close();
}
}
}
}
Am I missing something in regards to hosting the DataService in the unit test? 我是否在单元测试中缺少有关托管DataService的内容?
EDIT 1 Running the following command: 编辑1运行以下命令:
netsh http add urlacl url=http://+:60000/ODataService/ user=administrator
netsh http添加urlacl url = http:// +:60000 / ODataService / user = administrator
Solved part of the problem. 解决了部分问题。 I can now run the test without problems fine on my development system through the console, but the build agents still can't run the test.
现在,我可以通过控制台在开发系统上顺利运行测试,但是构建代理仍然无法运行测试。 They push the following output:
他们推送以下输出:
failed Execute System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
失败Execute System.Net.WebException:远程服务器返回错误:(500)内部服务器错误。 Status: ProtocolError Response: System.Net.HttpWebResponse at System.Net.WebClient.UploadFile(Uri address, String method, String fileName) at System.Net.WebClient.UploadFile(Uri address, String fileName) at System.Net.WebClient.UploadFile(String address, String fileName) at TenForce.Execution.Api2.OData.Tests.Helpers.ODataClient.UploadAttachment(String path, Int32 itemId) in c:\\Robinson\\trunk\\Projects\\Robinson\\TenForce.Execution.Api2.OData.Tests\\Helpers\\ODataClient.cs:line 69 at TenForce.Execution.Api2.OData.Tests.IntegrationTests.AttachmentIntegrationTests.AttachmentUpload() in c:\\Robinson\\trunk\\Projects\\Robinson\\TenForce.Execution.Api2.OData.Tests\\IntegrationTests\\AttachmentIntegrationTests.cs:line 89 ------- Stdout: ------- Unable to read configuration section common/logging.
状态:ProtocolError响应:System.Net.WebClient.UploadFile(用户地址,System.Net.WebClient.UploadFile(Uri地址,字符串,文件名)在System.Net.WebClient处,System.Net.HttpWebResponse。 TenForce.Execution.Api2.OData.Tests.Helpers.ODataClient.UploadAttachment(String path,Int32 itemId)在c:\\ Robinson \\ trunk \\ Projects \\ Robinson \\ TenForce.Execution.Api2.OData中的UploadFile(字符串地址,字符串fileName) .Tests \\ Helpers \\ ODataClient.cs:TenForce.Execution.Api2.OData.Tests.IntegrationTests.AttachmentIntegrationTests.AttachmentUpload()中的69行位于c:\\ Robinson \\ trunk \\ Projects \\ Robinson \\ TenForce.Execution.Api2.OData.Tests \\ IntegrationTests \\ AttachmentIntegrationTests.cs:第89行-------标准输出:-------无法读取配置节common / logging。 Using no-op implemenation.
使用无操作实现。
Took me quite some time to figure this out, but the problem is not Gallio. 花了我很多时间来解决这个问题,但问题不在于Gallio。 The problem is the toolkit used to develop the OData service.
问题是用于开发OData服务的工具箱。 This toolkit is not able to run from a console hosting environment.
该工具包无法从控制台托管环境中运行。
After moving the service to a remote server and writing tests to call the functions remotely and parse the responses, we got the intended behavior working. 将服务移至远程服务器并编写测试以远程调用函数并解析响应后,我们得到了预期的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.