在代码中,我需要检测,结果发现这样的外部依赖:如何通过Microsoft Fakes使用ConcurrentDictionary(C#)来长时间地依赖外部依赖?
var something = GConfig.SConfig[Type.ServiceType1].Names;
这部分的代码是这样的:
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
namespace Class
{
public sealed class GConfig
{
public ConcurrentDictionary<Type, GConfigIt> SConfig { get; set; }
public GConfig()
{
SConfig = new ConcurrentDictionary<Type, GConfigIt>();
throw new InvalidOperationException("Error");
}
}
public enum Type
{
ServiceType1,
ServiceType2
}
public class GConfigIt
{
public List<string> Names { get; set; }
public GConfigIt()
{
Names = new List<string>();
}
}
}
我需要垫片,它依赖,但对我自己的我无法找到完整的解决方案,只是部分:
对于GConfigIt(和匀场名称):Fakes.ShimGConfigIt.AllInstances.NamesGet
适用于垫片SConfig:Fakes.ShimGConfig.AllInstances.SConfigGet
但是我找不到连接,如何充分垫片。
P.S.我只是一个测试人员,不能改变现有的代码。为了做出改变,我需要说服开发人员这样做(即为GConfig提供额外的接口),但他们必须确保它不仅仅是用于“简单测试”或“测试测试”的改变,而且他们确实需要这样做。