コード例 #1
0
 public TypeResolver(
     ITypeNameResolvingStrategy typeNameResolvingStrategy,
     ITypeResolvingStrategy typeResolvingStrategy)
 {
     _typeNameResolvingStrategy = typeNameResolvingStrategy;
     _typeResolvingStrategy     = typeResolvingStrategy;
 }
コード例 #2
0
        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);
        }
コード例 #3
0
        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());
        }
コード例 #4
0
        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());
        }
コード例 #5
0
 public static DependencyResolverOptions SetTypeStrategy(this DependencyResolverOptions options, ITypeResolvingStrategy strategy)
 {
     options.TypeResolvingStrategy = strategy;
     return(options);
 }
コード例 #6
0
 public CachingTypeResolvingStrategy(ITypeResolvingStrategy strategy)
 {
     _strategy = strategy;
     _cache    = new ConcurrentDictionary <string, Type?>();
 }