ASP.NET MVC Website Testing

I am working on an MVC site with the ability to upload images, and I want to write a test that will load an image.

I made an image called TestImage.jpg and set Copy to Output to "Copy if Newer". In my test, I am trying to load this with the following code:

System.Drawing.Image testImage = System.Drawing.Image.FromFile(@"TestImage.jpg"); 

Should I copy the output copy to the same directory as the test? If not, how can I find out where it was copied? Some kind of relative path to the root of the project is best so that I can freely move the solution without this violation.

+6
asp.net-mvc mstest
source share
2 answers

in the solution explorer. In the solution items, double-click LocalTestRun.testrunconfig, go to the deployment and add an image

http://img17.imageshack.us/img17/5219/sanstitrelca.jpg

+1
source share

In MSTest, the framework copies all the DLL files to the TestResults folder. Unfortunately, it only copies the .dlls, .pdbs and .configs files from the output folder to the TestResults folder, so your files are not copied.

To copy these files you will need

  • add the DeploymentItem attribute to the corresponding test
  • edit the .testrunconfig file by adding the appropriate files to the Deployment tab

The best alternative is to embed the test files in the test as an embedded resource, and then read them directly from the resource stream.

+16
source share

All Articles