public TypeResolver( ITypeNameResolvingStrategy typeNameResolvingStrategy, ITypeResolvingStrategy typeResolvingStrategy) { _typeNameResolvingStrategy = typeNameResolvingStrategy; _typeResolvingStrategy = typeResolvingStrategy; }
public void sut_relays_correctly(Type type, string typeName) { ITypeResolvingStrategy strategy = Mock.Of <ITypeResolvingStrategy>(); Mock.Get(strategy).Setup(x => x.TryResolveType(typeName)).Returns(type); var sut = new CachingTypeResolvingStrategy(strategy); Type actual = sut.TryResolveType(typeName); actual.Should().Be(type); }
public void sut_caches_null_if_strategy_fails(string typeName) { ITypeResolvingStrategy strategy = Mock.Of <ITypeResolvingStrategy>(); Mock.Get(strategy).Setup(x => x.TryResolveType(typeName)).Throws <InvalidOperationException>(); var sut = new CachingTypeResolvingStrategy(strategy); sut.TryResolveType(typeName); Type actual = sut.TryResolveType(typeName); actual.Should().BeNull(); Mock.Get(strategy).Verify(x => x.TryResolveType(It.IsAny <string>()), Times.Once()); }
public void sut_caches_result(string typeName) { ITypeResolvingStrategy strategy = Mock.Of <ITypeResolvingStrategy>(); Type type = typeof(MessageData1); Mock.Get(strategy).Setup(x => x.TryResolveType(typeName)).Returns(type); var sut = new CachingTypeResolvingStrategy(strategy); sut.TryResolveType(typeName); Type actual = sut.TryResolveType(typeName); actual.Should().Be(type); Mock.Get(strategy).Verify(x => x.TryResolveType(It.IsAny <string>()), Times.Once()); }
public static DependencyResolverOptions SetTypeStrategy(this DependencyResolverOptions options, ITypeResolvingStrategy strategy) { options.TypeResolvingStrategy = strategy; return(options); }
public CachingTypeResolvingStrategy(ITypeResolvingStrategy strategy) { _strategy = strategy; _cache = new ConcurrentDictionary <string, Type?>(); }