目标是在这些Xml文件中给出一些数据来运行一些测试.
如何在单元测试方法中轻松地将给定的Xml文件加载到XmlDoc中?
目前的状态是:
XmlDocument doc = new XmlDocument();
string xmlFile = "4.xml";
string dir = System.IO.Directory.GetCurrentDirectory() + @"\Msgs\"
//dir is then the value of the current exe's path, which is
//d:\sourcecode\myproject\TestResults\myComputer 2009-10-08 16_07_45\Out
//we actually need:
//d:\sourcecode\myproject\Msgs\
doc.Load( dir + fileName); //should really use System.IO.Path.Combine()!
Run Code Online (Sandbox Code Playgroud)
只是将这条路径放在一个简单的问题上app.config?考虑到开发人员机器上存在不同路径的可能性,我希望避免这种情况.
问题:如何编写算法以将单个测试方法中的给定Xml文件加载到XmlDocument中?
简而言之,以下代码的目的是根据目标大小和乘数(1x,2x,3x)调整图像大小.这工作正常,除了某些原因我还没有确定一些图像正在旋转.
public void ResizeImage(TargetSize targetSize, ResizeMultiplier multiplier, Stream input, Stream output)
{
using (var image = Image.FromStream(input))
{
// Calculate the resize factor
var scaleFactor = targetSize.CalculateScaleFactor(image.Width, image.Height);
scaleFactor /= (int)multiplier; // Enum is effectively named constant with a value of 1, 2, or 3
var newWidth = (int)Math.Floor(image.Width / scaleFactor);
var newHeight = (int)Math.Floor(image.Height / scaleFactor);
using (var newBitmap = new Bitmap(newWidth, newHeight))
{
using (var imageScaler = Graphics.FromImage(newBitmap))
{
imageScaler.CompositingQuality = CompositingQuality.HighQuality;
imageScaler.SmoothingMode = SmoothingMode.HighQuality;
imageScaler.InterpolationMode = InterpolationMode.HighQualityBicubic; …Run Code Online (Sandbox Code Playgroud)