Microsoft Fake를 사용하여 일반 매개 변수가있는 스텁을 나타내는 방법은 어떻게됩니까?

StackOverflow https://stackoverflow.com//questions/12680378

문제

나는 일하고있는 일부 단위 테스트에서 Microsoft Fake를 사용하고 있습니다.내 인터페이스는 다음과 같습니다 :

interface ISecuredItem<TChildType> where TChildType : class, ISecuredItem<TChildType>
{
    SecurityDescriptor Descriptor { get; }
    IEnumerable<TChildType> Children { get; }
}
.

이 전형적인 구현은 다음과 같습니다 :

class RegistryKey : ISecuredItem<RegistryKey>
{
    public SecurityDescriptor Descriptor { get; private set; }
    public IEnumerable<RegistryKey> Children { get; }
}
.

Microsoft Fakes와 함께이 인터페이스를 사용하고 있으며 저에게 스텁을 생성하고 싶습니다.문제는 양식 가짜가 사용하는 것이 StubInterfaceNameHere<>이므로 위의 예에서는 StubISecuredItem<StubISecuredItem<StubISecuredItem<StubISecuredItem.... 와 같은 일을하려고 노력하는 것입니다.

이하입니까?그렇다면이 방법으로 가짜를 어떻게 사용합니까?

도움이 되었습니까?

해결책

일부 실험 이후 가장 우아하지는 않지만 작업 해결책을 찾았습니다.

이것은 일반 코드입니다.

public interface ISecuredItem<TChildType>
    where TChildType : ISecuredItem<TChildType>
{
    SecurityDescriptor Descriptor { get; }
    IEnumerable<TChildType> Children { get; }
}
.

테스트 프로젝트에서 StubimpleMtation 인터페이스를 만드는

public interface StubImplemtation : ISecuredItem<StubImplemtation> { }
.

그런 다음 장치 테스트에서 다음을 수행 할 수 있습니다.

var securedItemStub = new StubISecuredItem<StubImplemtation>
                          {
                              ChildrenGet = () => new List<StubImplemtation>(),
                              DescriptorGet = () => new SecurityDescriptor()
                          };

var children = securedItemStub.ChildrenGet();
var descriptor = securedItemStub.DescriptorGet();
.

전체 StubImplementation 전체를 건너 뛰고 문제가없는 경우 RegistryKey를 사용할 수 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top