示例#1
0
        public async Task PrimitiveValues_SetAsyncThenGetAsync(object input)
        {
            var          inputType         = input.GetType();
            const string key               = "test";
            var          cancellationToken = CancellationToken.None;

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            var getAsyncMethod = ReflectionUtils.GetMethodInfo(() =>
                                                               BinaryConvertDistributedCacheExtensions.GetAsync <object>(distributedCache, key, cancellationToken)
                                                               );
            getAsyncMethod = getAsyncMethod.GetGenericMethodDefinition().MakeGenericMethod(inputType);

            var setAsyncMethod = ReflectionUtils.GetMethodInfo(() =>
                                                               BinaryConvertDistributedCacheExtensions.SetAsync <object>(distributedCache, key, input, cancellationToken)
                                                               );
            setAsyncMethod = setAsyncMethod.GetGenericMethodDefinition().MakeGenericMethod(inputType);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

            await(Task) setAsyncMethod.Invoke(null, new object[] { distributedCache, key, input, cancellationToken });
            var   getTask = (Task)getAsyncMethod.Invoke(null, new object[] { distributedCache, key, cancellationToken });
            await getTask;

            var getTaskResultProperty = typeof(Task <>).MakeGenericType(inputType).GetProperty(nameof(Task <object> .Result));
            var actual = getTaskResultProperty.GetValue(getTask);
            Assert.Equal(input, actual);
        }
示例#2
0
        public void PrimitiveValues_SetThenGet(object input)
        {
            var          inputType = input.GetType();
            const string key       = "test";

            var getMethod = ReflectionUtils.GetMethodInfo(() =>
                                                          BinaryConvertDistributedCacheExtensions.Get <object>(distributedCache, key)
                                                          );

            getMethod = getMethod.GetGenericMethodDefinition().MakeGenericMethod(inputType);

            var setMethod = ReflectionUtils.GetMethodInfo(() =>
                                                          BinaryConvertDistributedCacheExtensions.Set <object>(distributedCache, key, input)
                                                          );

            setMethod = setMethod.GetGenericMethodDefinition().MakeGenericMethod(inputType);

            setMethod.Invoke(null, new object[] { distributedCache, key, input });
            var actual = getMethod.Invoke(null, new object[] { distributedCache, key });

            Assert.Equal(input, actual);
        }