2011-09-08 66 views
0

我在通過Gallio運行集成測試時遇到問題。 當我通過Testdrive.NET或Visual Studio中的集成Gallio運行測試時,測試正常工作。當我試圖通過控制檯運行它時(就像我們的nant腳本一樣),它會失敗。接收到的消息是這樣的:Gallio無法從控制檯運行測試

[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. 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

Disposing the test runner. Stop time: 16:45 (Total execution time: 20,515 seconds)

1 run, 0 passed, 1 failed, 0 inconclusive, 0 skipped

完整的命令行如下:

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

我不知道什麼是加利奧導致此問題。它適用於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 add urlacl url=http://+:60000/ODataService/ user=administrator

解決問題的一部分。我現在可以通過控制檯在我的開發系統上正常運行測試,但是構建代理仍然無法運行測試。他們推出以下輸出:

failed Execute System.Net.WebException: The remote server returned an error: (500) Internal Server Error. 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. Using no-op implemenation.

回答

0

花了我相當一些時間來解決這個問題,但問題不是加利奧。 問題是用於開發OData服務的工具包。此工具包無法從控制檯託管環境運行。

將服務移動到遠程服務器並編寫測試以遠程調用函數並解析響應之後,我們得到了預期的行爲。