簡體   English   中英

單元測試項目orleans文件未找到異常

[英]Unit testing project orleans file not found exception

我正在嘗試對我制作的一個相當簡單的應用程序進行單元測試,但是在運行測試時遇到一個非常奇怪的錯誤。

我所做的就是:

  • 創建一個新的類庫
  • 添加了對Microsoft.Orleans.TestingHostMicrosoft.Orleans.OrleansProviders版本1.1.2引用
  • 運行測試並獲得file not found exception

測試文件如下所示:

[TestFixture]
public class HelloWorldTests : TestingSiloHost
{
    //public HelloWorldTests()
    //    : base(new TestingSiloOptions
    //           {
    //               SiloConfigFile = new FileInfo(@"C:\_Foo\Host\Tests\OrleansConfigurationForTesting.xml")
    //           },
    //          new TestingClientOptions
    //          {
    //              ClientConfigFile = new FileInfo(@"C:\_Foo\Host\Tests\ClientConfigurationForTesting.xml")
    //          })
    //{
    //}

    [Test]
    public async Task When()
    {
        var grain = GrainFactory.GetGrain<IHelloGrain>(0);
        var reply = await grain.SayHello("Hello");

        Assert.That(reply, Is.EqualTo("Hello World"));
    }
}

^^從以上我什至嘗試對配置文件的位置進行硬編碼。

堆棧跟蹤(有趣的是,它在我的appdata文件夾中尋找配置文件:

OneTimeSetUp: System.Exception : Exception during test initialization: 
Exc level 0: System.Runtime.Serialization.SerializationException: Type is not resolved for member 'Orleans.Runtime.Silo+SiloType,OrleansRuntime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
   at System.AppDomain.CreateInstanceFromAndUnwrap(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at Orleans.TestingHost.TestingSiloHost.LoadSiloInNewAppDomain(String siloName, SiloType type, ClusterConfiguration config, AppDomain& appDomain)
   at Orleans.TestingHost.TestingSiloHost.StartOrleansSilo(SiloType type, TestingSiloOptions options, Int32 instanceCount, AppDomain shared)
   at Orleans.TestingHost.TestingSiloHost.<InitializeAsync>d__16.MoveNext()

Exception doesn't have a stacktrace

OneTimeSetUp: System.Exception : Exception during test initialization: 
Exc level 0: System.IO.FileNotFoundException: Could not find file 'C:\Users\***\AppData\Local\JetBrains\Installations\ReSharperPlatformVs12\OrleansConfigurationForTesting.xml'.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean checkHost)
   at System.IO.StreamReader..ctor(String path)
   at System.IO.File.OpenText(String path)
   at Orleans.Runtime.Configuration.ClusterConfiguration.LoadFromFile(String fileName)
   at Orleans.TestingHost.TestingSiloHost.StartOrleansSilo(SiloType type, TestingSiloOptions options, Int32 instanceCount, AppDomain shared)
   at Orleans.TestingHost.TestingSiloHost.<InitializeAsync>d__16.MoveNext()

Exception doesn't have a stacktrace

OneTimeSetUp: System.Exception : Exception during test initialization: 
Exc level 0: System.Runtime.Serialization.SerializationException: Type is not resolved for member 'Orleans.Runtime.Silo+SiloType,OrleansRuntime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
   at System.AppDomain.CreateInstanceFromAndUnwrap(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at Orleans.TestingHost.TestingSiloHost.LoadSiloInNewAppDomain(String siloName, SiloType type, ClusterConfiguration config, AppDomain& appDomain)
   at Orleans.TestingHost.TestingSiloHost.StartOrleansSilo(SiloType type, TestingSiloOptions options, Int32 instanceCount, AppDomain shared)
   at Orleans.TestingHost.TestingSiloHost.<InitializeAsync>d__16.MoveNext()

Exception doesn't have a stacktrace

schizo,

如果您使用的是MSTest框架,則只需為它抱怨的每個項目添加[DeploymentItem("missing_file_or_dll_name")] 如果使用xunit,則應將引用的DLL復制到輸出目錄,並將所有其他文件(如配置文件)設置為“ Copy To Output ”。

需要幫助請叫我。

有點老了,但是值得在這里...

這是NUnit和/或其VS適配器的怪癖。

Orleans會掃描當前目錄中的文件,但是NUnit會在其他位置設置此文件,而這些文件都不在其中。

因此,您必須在Orleans啟動之前自行設置當前目錄。

在測試的名稱空間中放入以下內容:

[SetUpFixture]
public class PreFixture
{
    [OneTimeSetUp]
    public void SetUp() {
        Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory);
    }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM