简体   繁体   English

单元测试项目orleans文件未找到异常

[英]Unit testing project orleans file not found exception

I am trying to get a handle on unit testing a fairly simple application I have made but I am getting a very odd error whilst running the test. 我正在尝试对我制作的一个相当简单的应用程序进行单元测试,但是在运行测试时遇到一个非常奇怪的错误。

All I did was: 我所做的就是:

  • Created a new class library 创建一个新的类库
  • Added references to Microsoft.Orleans.TestingHost and Microsoft.Orleans.OrleansProviders both version 1.1.2 添加了对Microsoft.Orleans.TestingHostMicrosoft.Orleans.OrleansProviders版本1.1.2引用
  • Run the test and get a file not found exception 运行测试并获得file not found exception

The test file looks like this: 测试文件如下所示:

[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"));
    }
}

^^ From the above I even tried to hard code the config file's location. ^^从以上我什至尝试对配置文件的位置进行硬编码。

Stack Trace (interestingly its looking for the config file in my appdata folder : 堆栈跟踪(有趣的是,它在我的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, schizo,

If you are using MSTest framework, just add [DeploymentItem("missing_file_or_dll_name")] for each item it is complaining. 如果您使用的是MSTest框架,则只需为它抱怨的每个项目添加[DeploymentItem("missing_file_or_dll_name")] If you are using xunit, the referenced DLLs should be copied to output directory and all extra files(like the config ones), should be set to " Copy To Output ". 如果使用xunit,则应将引用的DLL复制到输出目录,并将所有其他文件(如配置文件)设置为“ Copy To Output ”。

Let me know if you need anything else. 需要帮助请叫我。

A bit old, but worth being here... 有点老了,但是值得在这里...

This is a quirk of NUnit and/or its VS adaptor. 这是NUnit和/或其VS适配器的怪癖。

Orleans scans for files in the current directory, but NUnit sets this elsewhere, where none of the intended files live. Orleans会扫描当前目录中的文件,但是NUnit会在其他位置设置此文件,而这些文件都不在其中。

You therefore have to set the current directory yourself before Orleans starts up. 因此,您必须在Orleans启动之前自行设置当前目录。

Put something like this in the namespace of your tests: 在测试的名称空间中放入以下内容:

[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