Including resources file for Unit test in C# project -


I have some tasks that read & amp; Modify files To make the unit independent of any file system issues, I want to include files inside the project.

However, my function should get the file path, and all I can get from the assembly is a FileStream. Any idea how can I get the file path of a resource file in the project?

System. Refining Assembly = a.Reflection.Assembly.Load (assemblyName); File stream stream = a.GetFile (assembly name + "." + FileName);

Thanks!

My usual solution to this problem is to open the file in my calling method Again, I pass a stream instead of passing the file name and opening the file.

This allows me to pass a memorystream to test so that I can test my unit without using the file system. Sometimes it is easier to check whether the data is written correctly and it is definitely fast, especially for higher tests

  Public TestSaveAndLoad ():  

After typing as an example, you must remember to flush memorystream. {Create data to save ...] (memorystream targetstream = new memorystream ()) {target.Save (targetstream); TargetStream.Flush (); Targetstream.Seek (0, ...); Target.Load (targetStream); } [... claim that weighted data is equal to saved data ...]}


Comments