2010-12-03 5 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), он работает. Кстати, если тест I блок Sqlite, это не вызывает каких-либо ошибок слишком

+0

Похоже, ваша программа пытается подключиться через сокет, а не через порт. Можете ли вы сконфигурировать разъем для использования порта Postgres TCP/IP? – 2010-12-03 10:10:02

ответ

0

нашел ответ, я пытался запускать MonoDevelop от терминала (/Applications/MonoDevelop.app/Contents/MacOS/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/2868/Npgsql2.0.11-bin-ms.net4.0.zip) до http://pgfoundry.org/frs/download.php/2860/Npgsql2.0.11-bin-mono2.0.zip После этого, нет более Unix транспортной ошибки^_^

Урока, используйте Моно версия компонента, который вы используете, если вы работаете над Mono

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 
Смежные вопросы