2010-12-03 75 views
2

我在做單元測試(使用NUnit)PostgreSQL的,不幸的是它會導致一個錯誤:什麼原因導致:Unix傳輸錯誤?

Internal error 
    RemotingException: Unix transport error. 

注:如果我使用SQLite的錯誤不會發生

代碼:

using System; 
using ncfg = NHibernate.Cfg; 
using System.Collections.Generic; 
using System.Reflection; 
using NHibernate; 
using System.Data; 
using NHibernate.Tool.hbm2ddl; 
using NHibernate.Dialect; 
using NHibernate.Driver; 
using NHibernate.ByteCode.LinFu; 
using NUnit.Framework; 
using NHibernate.Mapping; 



namespace RuntimeNhibernate 
{ 
    class MainClass 
    { 
    public static void Main (string[] args) 
    { 


    using(var c = new BlogTestFixture()) 
    { 
    c.CanSaveAndLoadBlog(); 

    } 

    } 
    } 



    public class InMemoryDatabaseTest : IDisposable 
    { 
    private static ncfg.Configuration Configuration; 
    private static ISessionFactory SessionFactory; 
    protected ISession session; 

    public InMemoryDatabaseTest(Assembly assemblyContainingMapping) 
    { 
    if (Configuration == null) 
    { 

    Configuration = new ncfg.Configuration() 
     .SetProperty(ncfg.Environment.ReleaseConnections,"on_close") 
     .SetProperty(ncfg.Environment.Dialect, typeof (SQLiteDialect).AssemblyQualifiedName) 
     .SetProperty(ncfg.Environment.ConnectionDriver, typeof(SQLite20Driver).AssemblyQualifiedName) 
     .SetProperty(ncfg.Environment.ConnectionString, "data source=:memory:") 
     .SetProperty(ncfg.Environment.ProxyFactoryFactoryClass, typeof (ProxyFactoryFactory).AssemblyQualifiedName) 
     .AddAssembly(assemblyContainingMapping); 


    /*Configuration = new ncfg.Configuration() 
     .SetProperty(ncfg.Environment.ReleaseConnections,"on_close") 
     .SetProperty(ncfg.Environment.Dialect, typeof (PostgreSQLDialect).AssemblyQualifiedName) 
     .SetProperty(ncfg.Environment.ConnectionDriver, typeof(NpgsqlDriver).AssemblyQualifiedName) 
     .SetProperty(ncfg.Environment.ConnectionString, "Server=127.0.0.1;Database=memdb;User ID=postgres;Password=password;Pooling=false;") 
     .SetProperty(ncfg.Environment.ProxyFactoryFactoryClass, typeof (ProxyFactoryFactory).AssemblyQualifiedName) 
     .AddAssembly(assemblyContainingMapping);*/ 

    SessionFactory = Configuration.BuildSessionFactory(); 
    } 

    session = SessionFactory.OpenSession(); 

    new SchemaExport(Configuration).Execute(true, true, false, session.Connection, Console.Out); 
    } 

    public void Dispose() 
    { 
    session.Dispose(); 
    } 
    }//class InMemory 

    public class Blog 
    { 
    public virtual int BlogId { get; set; } 
    public virtual bool AllowsComments { set; get; } 
    public virtual DateTime CreatedAt { get; set; } 
    public virtual string Subtitle { get; set; } 
    public virtual string Title { get; set; } 
    } 

    [TestFixture] 
    public class BlogTestFixture : InMemoryDatabaseTest 
    { 
    public BlogTestFixture() : base(typeof(Blog).Assembly) 
    { 
    } 


    [Test] 
    public void IsOK() 
    { 
    Assert.AreEqual(true, true); 
    return; 
    } 

    [Test]  
    public void CanSaveAndLoadBlog() 
    { 


    object id; 




    using (var tx = session.BeginTransaction()) 
    { 
    id = session.Save(new Blog 
    { 
     AllowsComments = true, 
     CreatedAt = new DateTime(2000,1,1), 
     Subtitle = "Hello", 
     Title = "World", 
    }); 

    tx.Commit(); 
    } 

    session.Clear(); 

    Console.WriteLine("Hello {0}", id); 


    using (var tx = session.BeginTransaction()) 
    { 
    var blog = session.Get<Blog>(id); 




    Assert.AreEqual(new DateTime(2000, 1, 1), blog.CreatedAt); 
    Assert.AreEqual("Hello", blog.Subtitle); 
    Assert.AreEqual("World", blog.Title); 
    Assert.AreEqual(true, blog.AllowsComments); 

    tx.Commit(); 
    } 
    } 
    }//Test 


}//namespace 

什麼可能是我單元測試Postgresql時可能的原因,結果爲RemotingException:Unix傳輸錯誤。

如果我在單元測試(例如Main)之外運行代碼,它可以工作。順便說一句,如果我的單元測試SQLite的,它不會引起找到答案的任何錯誤太

+0

聽起來像你的程序試圖通過套接字而不是端口連接。你能配置連接器使用Postgres TCP/IP端口嗎? – 2010-12-03 10:10:02

回答

0

,我試圖從終端(/Applications/MonoDevelop.app/Contents/MacOS/monodevelop)推出MonoDevelop中,我看到了當我運行單元測試時,命令行中有更詳細的錯誤。

Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for Npgsql.NpgsqlConnection ---> System.TypeLoadException: Could not load type 'System.Runtime.Versioning.TargetFrameworkAttribute' from assembly 'Npgsql'. 
    at (wrapper managed-to-native) System.MonoCustomAttrs:GetCustomAttributesInternal (System.Reflection.ICustomAttributeProvider,System.Type,bool) 
    at System.MonoCustomAttrs.GetCustomAttributesBase (ICustomAttributeProvider obj, System.Type attributeType) [0x00000] in <filename unknown>:0 
    at System.MonoCustomAttrs.GetCustomAttributes (ICustomAttributeProvider obj, System.Type attributeType, Boolean inherit) [0x00000] in <filename unknown>:0 
    at System.Reflection.Assembly.GetCustomAttributes (System.Type attributeType, Boolean inherit) [0x00000] in <filename unknown>:0 
    at System.Resources.ResourceManager.GetNeutralResourcesLanguage (System.Reflection.Assembly a) [0x00000] in <filename unknown>:0 
    at System.Resources.ResourceManager..ctor (System.Type resourceSource) [0x00000] in <filename unknown>:0 
    at Npgsql.NpgsqlConnection..cctor() [0x00000] in <filename unknown>:0 
    --- End of inner exception stack trace --- 
    at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod*,object,object[],System.Exception&) 
    at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 

然後我試圖改變Npgsql的版本http://pgfoundry.org/frs/download.php/2860/Npgsql2.0.11-bin-mono2.0.zip之後(即導致從http://pgfoundry.org/frs/download.php/2868/Npgsql2.0.11-bin-ms.net4.0.zip來了一個錯誤的),有沒有更多的Unix的傳輸錯誤^_^

獲得的經驗,使用如果您在單聲道上運行的組件,則使用的組件的單聲道版本

0

當MonoDevelop中的單元測試引發異常時,會發生此異常,該異常無法被測試運行器捕獲(即,當測試啓動某些線程他們崩潰了)。

如果你有這樣一個測試,是灰色的,甚至運行

not executable test

和單元測試墊後顯示了內部錯誤

enter image description here

你應該嘗試在運行測試您的控制檯與nunit-console(應該在您的發行版的mono來自回購),並泄漏例外。

在我的情況下,它是我測試的子線程中的一個簡單的多重枚舉異常。

Unhandled exceptions: 
1) Residata.Platform.Server.Message.Test.MemoryBrokerTest.AssertThatReceiveMethodWaitsUntilPublish : System.InvalidOperationException: Collection was modified; enumeration operation may not execute. 
    at System.Collections.Generic.List`1+Enumerator[Residata.Platform.Contract.Message.IPackage].MoveNext() [0x00000] in <filename unknown>:0 
相關問題