Код: Выделить всё
public class TestingSample
{
public class FactoryClass : Class {}
public class Class : IInterface {}
public interface IInterface {}
public class AutoData : AutoDataAttribute
{
public AutoData() : base( Create() ) {}
static IFixture Create()
{
var fixture = new Fixture();
fixture.Customize( composer => composer.FromFactory( () => new FactoryClass() ) );
fixture.Customize( composer => composer.FromFactory( () => new FactoryClass() ) );
return fixture;
}
}
[Theory, TestingSample.AutoData]
public void OldSkool( [Frozen( As = typeof(IInterface) )]Class first, Class second, IInterface third )
{
Assert.IsType( first );
Assert.Same( first, second );
Assert.Same( first, third );
}
[Theory, TestingSample.AutoData]
public void DirectBaseType( [Frozen( Matching.ExactType )]Class first, Class second )
{
Assert.IsType( first );
Assert.Same( first, second );
}
[Theory, TestingSample.AutoData]
public void ImplementedInterfaces( [Frozen( Matching.ImplementedInterfaces )]Class first, IInterface second )
{
Assert.IsType( first );
Assert.Same( first, second ); // The Fails.
}
}
Однако оказывается, что Match.ImplementedInterfaces ведет себя иначе, чем Match.ExactType и FrozenAttribute.As.
Я так и сделал немного покопался и увидел, что Match.ExactType и FrozenAttribute.As используют SeedRequestSpecification, тогда как Match.ImplementedInterfaces соответствует только запросам Type.
Можно ли получить некоторый контекст этого поведения? Это задумано? И если да, то существует ли известная рекомендация по проектированию таким образом, чтобы восстановить старое поведение с помощью Match.ImplementedInterfaces?
Подробнее здесь: https://stackoverflow.com/questions/348 ... tching-exa
Мобильная версия