Adding resource file for testing in Rider

混江龙づ霸主 提交于 2019-12-24 00:18:43

问题


I have started to use rider for developing in Linux with C#. I have created my tests like:

namespace RAWConverter
{

    using NUnit.Framework;

    [TestFixture]
    public class SerializationHelperTest
    {

        [Test]
        public void SerializeEntry()
        {
            msRun msRun = new msRun();
            SerializationHelper.SerializationEntry(System.IO.Path.GetTempFileName(), msRun);
        }

        [Test]
        public void DeserializationEntry()
        {
            msRun msRun = SerializationHelper.DeserializationEntry(getFileNameFromResource(RAWConverter.Properties.));
            Console.WriteLine(msRun.endTime);
        }

        private string getFileNameFromResource(String fileName)
        {
            String strAppPath = Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
            String strFilePath = Path.Combine(strAppPath, "resources");
            return Path.Combine(strFilePath, fileName);
        }

    }
}

and I have a folder in my project called resources that contains the file. However when I execute my tests it fail because this variable

System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName

is in /usr/bin

Any ideas?


回答1:


The bin folder is the default output directory where the project binaries are copied to and executed from when the project is built. If you were to manually copy the resources folder and its contents to the bin folder the test would work.

I am not familiar with the IDE in question but I suggest checking if there is a setting that will allow for resources to be automatically copied to the output directories when the project is built.

Found a comment in their community

Editing file properties - Copy to output directory

We are about to publish new EAP build in couple of days, and in that new build "Build Action" and "Copy to output directory" are drop-downs.

For now you may press F4 on project in SolutionExplorer and edit Include manually.



来源:https://stackoverflow.com/questions/44053289/adding-resource-file-for-testing-in-rider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!