public void Ignores_duplicate_request_type()
        {
            var cache = new MethodMatchEvaluationCache();

            var evaluation = new MethodMatchEvaluation(typeof(SomeRequest), null, Array.Empty <MethodInfo>());

            _ = cache.TryAdd(evaluation);

            bool added = cache.TryAdd(evaluation);

            Assert.False(added);
        }
        public void Finds_request_type()
        {
            var cache = new MethodMatchEvaluationCache();

            var evaluation = new MethodMatchEvaluation(typeof(SomeRequest), null, Array.Empty <MethodInfo>());

            _ = cache.TryAdd(evaluation);

            bool found = cache.TryFindEvaluation(typeof(SomeRequest), out var cached);

            Assert.True(found);
            Assert.Same(evaluation, cached);
        }
Esempio n. 3
0
        public void Can_be_deconstructed()
        {
            var expectedRequestType  = typeof(int);
            var expectedResponseType = typeof(int);
            var expectedMethods      = Array.Empty <MethodInfo>();

            var evaluation = new MethodMatchEvaluation(expectedRequestType, expectedResponseType, expectedMethods);

            var(requestType, responseType, methods) = evaluation;

            Assert.Same(expectedRequestType, requestType);
            Assert.Same(expectedResponseType, responseType);
            Assert.Same(expectedMethods, methods);
        }
Esempio n. 4
0
        public bool TryAdd(MethodMatchEvaluation evaluation)
        {
            if (evaluation is null)
            {
                throw new ArgumentNullException(nameof(evaluation));
            }
            if (evaluation.RequestType is null)
            {
                throw new ArgumentNullException(nameof(evaluation.RequestType));
            }
            if (evaluation.Methods is null)
            {
                throw new ArgumentNullException(nameof(evaluation.Methods));
            }

            var hash = evaluation.ResponseType is null
                ? HashCode.Combine(evaluation.RequestType)
                : HashCode.Combine(evaluation.RequestType, evaluation.ResponseType);

            return(_cache.TryAdd(hash, evaluation));
        }
Esempio n. 5
0
 public void Can_be_constructed()
 {
     _ = new MethodMatchEvaluation(typeof(object), typeof(object), Array.Empty <MethodInfo>());
 }