1

I have a method like below.

public async Task<bool> AddAsync<T>(IList<Tuple<string, T>> items) where T : class
        {
                RedisKey[] redisKeys = new RedisKey[items.Count];
                RedisValue[] redisValues = new RedisValue[items.Count];
                var sb = await this.redisCachingHelperPriv.CreateLuaScriptForMset(redisKeys, redisValues, items, this.customKey);
                var redisResult = await this.connectionMultiplexerPriv.GetDatabase().ScriptEvaluateAsync(sb, redisKeys, redisValues);
                return redisResult.ToString() == "OK";           
        }  

I am trying to write test method for above method using stubs like below.

 public void AddAsync_List_Functionality_TestMethod()
        {
            bool returnTask = false;
            using (ShimsContext.Create())
            {               
                IDatabase idata = new StubIDatabase
                {ScriptEvaluateAsyncStringRedisKeyArrayRedisValueArrayCommandFlags = (A, B, C, D) =>
                    {
                    //Need to return RedisResult object. But not able to create it.
                    }
                };
                ShimConnectionMultiplexer.AllInstances.GetDatabaseInt32Object = (A, B, C) => { return idata; };
                List<Tuple<string, string>> cacheItems = new List<Tuple<string, string>>();
                cacheItems.Add(Tuple.Create("test", "test"));
                this.redisCachingObj = new RedisCaching(this.redisCachingConfigObj, this.redisCachingHelperObj);
                this.redisCachingObj.InitializeAsync();
                Task task = this.redisCachingObj.AddAsync(cacheItems);
                task.Wait();              
                Assert.IsTrue(task.IsCompleted);
            }
        }

Inside stub for ScriptEvaluateAsync I need to return a task containing RedisResult object. But I am not able to create RedisResult object as it is an abstract class.

Could anyone please help me out in this?

4

0 回答 0