私はこれを箱から出してもらえませんでした。私は少しそれを微調整しなければならなかった。だから、GrensesnittObjectLocator.GetHandler
方法の代わりに、内側:私は、次のexmapleを書いた場所にこの変更によって
public static Func<object> GetHandler(Type T)
{
return() =>
{
Func<object> handler;
if (handleAll != null) return handleAll(T);
if (map.TryGetValue(T, out handler))
{
return handler();
}
return TryReflections(T);
};
}
:
public interface IFoo
{
int Add(int a, int b);
}
public class Foo : IFoo
{
private readonly string _foo;
public Foo(string foo)
{
_foo = foo;
}
public int Add(int a, int b)
{
return a + b;
}
}
あなたはどのように見ることができます
public static Func<object> GetHandler(Type T)
{
Func<object> handler;
if (handleAll != null) return() => { return handleAll(T); };
if (map.TryGetValue(T, out handler))
{
return (Func<object>)handler;
}
return() => { return TryReflections(T); };
}
私はそれを修正しましたFoo
クラスにはデフォルトコンストラクタがありません。だから今、私たちはこのテストを持つことができます。
[InterfaceSpecification]
public class IFooTests : AppliesToAll<IFoo>
{
[Test]
public void can_add_two_numbers()
{
Assert.AreEqual(5, subject.Add(2, 3));
}
}
そして、単にあなたのテストアセンブリ(以前のユニットテストが含まれている同じアセンブリ)に次のクラスを追加Foo
をインスタンス化する方法grensesnitt
に示すために:
を
[SetUpFixture]
public class Config
{
[SetUp]
public void SetUp()
{
// indicate to Grensesnitt that the Foo class
// doesn't have a default constructor and that
// it is up to you to provide an instance
GrensesnittObjectLocator.Register<Foo>(() =>
{
return new Foo("abc");
});
}
}
はい、うまくいきました。ありがとうございます。 grensesnittのgit(https://github.com/gregoryyoung/grensesnitt)用のパッチを作成する必要があります。 – zzandy
@zzandy、これはパッチを提供するためのバグであるかどうかはわかりません。たぶん私はこのライブラリを正しく使う方法を知りません。 –