주어진 인터페이스의 구현을 내보내는 어셈블리를 디렉토리에서 검색하는 플러그인 라이브러리를 작성했습니다. 이는 반사 전용 컨텍스트에서 모든 어셈블리를 임시 앱 도메인으로로드하고 내 보낸 유형을 검색하여 수행합니다. 그런 다음 임시 앱 도메인이 언로드되고 관심있는 어셈블리가 기본 앱 도메인에로드되며 발견 된 유형의 개체가 검색 인터페이스를 통해 사용되도록 인스턴스화됩니다.NUnit 테스트에서 앱 도메인을 만들 때 예외가 발생했습니다.
NUnit을 사용하여이 프로세스에 대한 일부 단위 테스트를 작성하려고하지만 ReflectionOnlyAssemblyResolve 이벤트를 연결할 때 단위 테스트에서만 FileNotFoundException이 발생합니다. 내가 알고있는 위치에 몇 가지 더미 어셈블리의 코드를 테스트하려고 시도했습니다
using System;
using System.Reflection;
using NUnit.Framework;
namespace NUnitAppDomains
{
[TestFixture]
public class TestClass
{
[Test]
public void NUnitTest()
{
var ad = AppDomain.CreateDomain("someName");
// this next line throws a FileNotFoundException, complaining about not being
// able to find the test assembly itself... o.O
ad.ReflectionOnlyAssemblyResolve += SomeHandler;
AppDomain.Unload(ad);
}
static Assembly SomeHandler(object sender, ResolveEventArgs args)
{
// some code would be here
throw new NotImplementedException();
}
}
}
/유효한 imlementation/S를 포함하지 않는 않는 일부 : 여기에 빈약 한 예입니다. 내 코드가 단위 테스트에 적합하지 않거나, 그렇다면 어떻게 이러한 예외를 피할 수 있습니까? 감사합니다
잘 구성된 질문, [SSCCE] (http://sscce.org/)에 감사드립니다. SO에 오신 것을 환영합니다! –