我正在使用swisstopo的dll将坐标从LV03迁移到LV95格式。
我从here下载了dll。
我想做的第一件事是编写一个单元测试来确认迁移的正确性。 我引用了两个dll并编写了单元测试:
[TestFixture]
public class Lv03ToLv95ConverterTest
{
[Test]
[TestCase(600000, 200000, 2600000.0, 1200000.0)]
public void Convert_WhenGivenLv03In_ThenExpectedLv95Out(double givenLv03Easting, double givenLv03Northing, double expectedLv95Easting, double expectedLv95Northing)
{
var actualLv95 = Lv03ToLv95Converter.Convert(givenLv03Easting, givenLv03Northing);
actualLv95.Easting.ShouldBeEquivalentTo(expectedLv95Easting);
actualLv95.Northing.ShouldBeEquivalentTo(expectedLv95Northing);
}
}
public static class Lv03ToLv95Converter
{
public static Lv95 Convert(double easting, double northing)
{
var reframe = new Reframe();
var height = 0.0;
reframe.ComputeReframe(
ref easting,
ref northing,
ref height,
Reframe.PlanimetricFrame.LV03_Civil,
Reframe.PlanimetricFrame.LV95,
Reframe.AltimetricFrame.LN02,
Reframe.AltimetricFrame.LHN95);
return new Lv95(easting, northing);
}
}
public class Lv95
{
public Lv95(double easting, double northing)
{
this.Easting = easting;
this.Northing = northing;
}
public double Easting { get; private set; }
public double Northing { get; private set; }
}
不幸的是,当我想要运行测试时,它说:
System.IO.FileLoadException:无法加载指定的文件。
at swisstopo.geodesy.htrans.CHtrans.ReadData(Single [,]& data,String filename)
at swisstopo.geodesy.htrans.CHtrans.ComputeHtrans(Double& height,Double east,Double north,HeightTransformation transformation)
at swisstopo.geodesy.reframe.Reframe.TransformAltimetry(Double& height,Double east,Double north,AltimetricFrame altFrameIn,AltimetricFrame altFrameOut)
at swisstopo.geodesy.reframe.Reframe.ComputeReframe(Double& east,Double& north,Double& height,PlanimetricFrame plaFrameIn,PlanimetricFrame plaFrameOut,AltimetricFrame altFrameIn,AltimetricFrame altFrameOut)
at MyProject.Tests.Lv03ToLv95Converter.Convert(Double easting,Double northing)在C:\ Projects \ MyProject \ sources \ MyProject.Tests \ Lv03ToLv95ConverterTest.cs:第33行
at MyProject.Tests.Lv03ToLv95ConverterTest.Convert_WhenGivenLv03In_ThenExpectedLv95Out(Double givenLv03Easting,Double givenLv03Northing,Double expectedLv95Easting,Double expectedLv95Northing)在C:\ Projects \ MyProject \ sources \ MyProject.Tests \ Lv03ToLv95ConverterTest.cs:第21行
有谁知道这里的问题是什么? 我之前从未遇到过引用和使用dll的问题......
提前致谢
编辑: 我们认为问题可能是,Reframe正在调用Assembly.ExecutingAssembly并在路径中查找swisstopo.data等它没有'找到,因为正在执行的程序集是nunit runner ...
我们尝试在测试中手动加载程序集,但遗憾的是也没有。
[Test]
[TestCase(600000, 200000, 2600000.0, 1200000.0)]
public void Convert_WhenGivenLv03In_ThenExpectedLv95Out(double givenLv03Easting, double givenLv03Northing, double expectedLv95Easting, double expectedLv95Northing)
{
AppDomain.CurrentDomain.Load("swisstopo.data");
AppDomain.CurrentDomain.Load("swisstopo.reframelib");
var actualLv95 = Lv03ToLv95Converter.Convert(givenLv03Easting, givenLv03Northing);
actualLv95.Easting.ShouldBeEquivalentTo(expectedLv95Easting);
actualLv95.Northing.ShouldBeEquivalentTo(expectedLv95Northing);
}
答案 0 :(得分:3)
我在加载" swisstopo.data"时遇到了同样的问题。在NUnit中组装。 对我来说,使用MS Test而不是NUnit解决了这个问题。在MS Test中,执行程序集是测试程序集。
[TestMethod]
public void Convert_WhenGivenLv03In_ThenExpectedLv95Out()
{
double givenLv03Easting = 600100, givenLv03Northing = 200100, expectedLv95Easting = 2600100.08309925, expectedLv95Northing = 1200100.06755549;
var executingAssembly = Assembly.GetExecutingAssembly().FullName;
Console.WriteLine(executingAssembly);
var actualLv95 = Lv03ToLv95Converter.Convert(givenLv03Easting, givenLv03Northing);
actualLv95.Easting.Should().BeApproximately(expectedLv95Easting, 0.00001);
actualLv95.Northing.Should().BeApproximately(expectedLv95Northing, 0.00001);
}