0

作成したかなり単純なアプリケーションの単体テストを処理しようとしていますが、テストの実行中に非常に奇妙なエラーが発生します。

私がしたことはすべて:

  • 新しいクラス ライブラリを作成しました
  • Microsoft.Orleans.TestingHostおよびMicrosoft.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
4

2 に答える 2

2

シゾ、

MSTest フレームワークを使用している場合は、問題[DeploymentItem("missing_file_or_dll_name")]のある項目ごとに追加するだけです。xunit を使用している場合は、参照されている DLL を出力ディレクトリにコピーし、すべての追加ファイル (構成ファイルなど) を " " に設定する必要がありますCopy To Output

他に何か必要な場合はお知らせください。

于 2016-03-07T15:11:20.767 に答える
1

少し古いですが、ここにいる価値はあります...

これは、NUnit および/またはその VS アダプターの癖です。

Orleans は現在のディレクトリ内のファイルをスキャンしますが、NUnit はこれを別の場所に設定します。目的のファイルは存在しません。

したがって、Orleans を起動する前に、現在のディレクトリを自分で設定する必要があります。

テストの名前空間に次のようなものを配置します。

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

}
于 2016-09-12T11:28:58.880 に答える