첫째, 난 강력하게/C 번호를 .NET 4.5, "페이크 및 스텁"이라고 두더지의 릴리스 버전, 5/비주얼 스튜디오 2012
System.Configurations 네임 스페이스를 이동하는 것이 좋습니다 것은 두더지와 호환되지 않습니다/위조 유형이며 스터브해야합니다. Moles Framework를 사용하여 스텁을 만들려면 System.Configuration.AppSettingsReader 유형의 인터페이스를 만듭니다. Moles 컴파일러는 인터페이스를 스텁 유형으로 자동 변환합니다. 도 그루터기 클래스 다음
using System;
namespace YOUR_NAMESPACE_HERE
{
/// <summary>
/// IOC object for stubbing System.Configuration.AppSettingsReader.
/// Provides a method for reading values of a particular type from
/// the configuration.
/// </summary>
interface IAppSettingsReader
{
/// <summary>
/// Gets the value for a specified key from the
/// System.Configuration.ConfigurationSettings.AppSettings property
/// and returns an object of the specified type containing the
/// value from the configuration.
/// </summary>
/// <param name="key">The key for which to get the value.</param>
/// <param name="type">The type of the object to return.</param>
/// <returns>The value of the specified key</returns>
/// <exception cref="System.ArgumentNullException">key is null.
/// - or -
/// type is null.</exception>
/// <exception cref="System.InvalidOperationException">key does
/// not exist in the <appSettings> configuration section.
/// - or -
/// The value in the <appSettings> configuration section
/// for key is not of type type.</exception>
public object GetValue(string key, Type type);
}
}
것 : 여기
이 프로젝트에 추가 할 수있는 인터페이스입니다 들어
using System;
using System.Configuration;
namespace YOUR_NAMESPACE_HERE
{
/// <summary>
/// Production stub for System.Configuration.AppSettingsReader.
/// Provides a method for reading values of a particular type from
/// the configuration.
/// </summary>
public class AppSettingsReaderStub : IAppSettingsReader
{
/// <summary>
/// Gets the value for a specified key from the
/// System.Configuration.ConfigurationSettings.AppSettings property
/// and returns an object of the specified type containing the value
/// from the configuration.
/// </summary>
/// <param name="key">The key for which to get the value.</param>
/// <param name="type">The type of the object to return.</param>
/// <returns>The value of the specified key</returns>
/// <exception cref="System.ArgumentNullException">key is null.
/// - or -
/// type is null.</exception>
/// <exception cref="System.InvalidOperationException">key does not
/// exist in the <appSettings> configuration section.
/// - or -
/// The value in the <appSettings> configuration section for
/// key is not of type type.</exception>
public object GetValue(string key, Type type)
{
var reader = new AppSettingsReader();
object result = reader.GetValue(key, type);
return result;
}
}
}
무엇을 그 내가 전화를 포장 결국 가치 : 공용 클래스 appSettings는을 { 공용 개체 GetValue (문자열 키, 형식 유형) { return 새 AppSettingsReader(). GetValue (key, type); } } 테스트 할 코드를 수정하지 않기를 바란다면 여전히 해결책을 찾고 싶습니다. – EricR