【问题标题】:Gallio can't run test from consoleGallio 无法从控制台运行测试
【发布时间】:2011-09-08 14:50:54
【问题描述】:

我在通过 Gallio 运行集成测试时遇到问题。 当我使用 Testdrive.NET 或通过 Visual Studio 中的集成 Gallio 运行测试时,测试工作正常。当我试图通过控制台运行它时(就像我们的 nant 脚本一样)它失败了。收到的消息是这样的:

[失败] 测试 TenForce.Execution.Api2.OData.Tests/AttachmentIntegrationTests/Att achment上传执行 System.ServiceModel.CommunicationObjectFaultedException: 通信对象 System.Data.Services.DataServiceHost 不能 用于通信,因为它处于故障状态。在 System.ServiceModel.Channels.CommunicationObject.Close(时间跨度 超时)在 System.ServiceModel.ServiceHostBase.System.IDisposable.Dispose() 在 TenForce.Execution.Api2.OData.Tests.IntegrationTests.AttachmentIntegration Tests.AttachmentUpload() 在 D:\Users\arne.de.herdt.TENFORCE2\Documents\Developme nt\Projects\Robinson\TenForce.Execution.Api2.OData.Tests\IntegrationTests\Attach mentIntegrationTests.cs:第 83 行

处理测试运行器。停止时间:16:45(总执行时间: 20,515 秒)

1 次运行,0 次通过,1 次失败,0 次不确定,0 次跳过

完整的命令行如下:

Gallio.Echo.exe /r:IsolatedProcess TenFor ce.Execution.Api2.OData.Tests.dll /f:Namespace:TenForce.Execution.Api2.OData.Tests.IntegrationTests

我不知道是什么导致了 Gallio 出现此问题。它适用于 VS,但不适用于构建代理或控制台。测试的源码是这样的:

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();
            }
        }
    }
}

我是否遗漏了有关在单元测试中托管 DataService 的内容?

编辑 1 运行以下命令:

netsh http 添加 urlacl url=http://+:60000/ODataService/ 用户=管理员

解决了部分问题。我现在可以通过控制台在我的开发系统上正常运行测试,但构建代理仍然无法运行测试。他们推送以下输出:

执行 System.Net.WebException 失败:远程服务器返回一个 错误:(500)内部服务器错误。状态:协议错误响应: System.Net.HttpWebResponse 在 System.Net.WebClient.UploadFile(Uri 地址,字符串方法,字符串文件名)在 System.Net.WebClient.UploadFile(Uri address, String fileName) at System.Net.WebClient.UploadFile(字符串地址,字符串文件名)在 TenForce.Execution.Api2.OData.Tests.Helpers.ODataClient.UploadAttachment(字符串 路径,Int32 itemId)在 c:\Robinson\trunk\Projects\Robinson\TenForce.Execution.Api2.OData.Tests\Helpers\ODataClient.cs:line 69 在 TenForce.Execution.Api2.OData.Tests.IntegrationTests.AttachmentIntegrationTests.AttachmentUpload() 在 c:\Robinson\trunk\Projects\Robinson\TenForce.Execution.Api2.OData.Tests\IntegrationTests\AttachmentIntegrationTests.cs:line 89 ------- 标准输出:-------- 无法读取配置部分 常见/日志记录。使用无操作实现。

【问题讨论】:

    标签: .net c#-4.0 odata wcf-data-services


    【解决方案1】:

    我花了很长时间才弄明白,但问题不在于 Gallio。 问题在于用于开发 OData 服务的工具包。此工具包无法在控制台托管环境中运行。

    在将服务移动到远程服务器并编写测试以远程调用函数并解析响应后,我们得到了预期的行为。

    【讨论】:

      猜你喜欢
      • 2010-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-06
      • 1970-01-01
      • 2011-07-02
      • 2016-02-27
      相关资源
      最近更新 更多