在使用c#和MVVM进行集成测试时,如何避免嘲笑IEventAggregator?
我正在进行集成测试,我希望在不进行模拟的情况下进行测试,因为我希望能够对wcf服务、数据库等进行端到端的测试。我的代码如下,其中我有一条评论说,模拟我需要知道如何做,而不是模拟?此代码运行时出现错误“{”无效URI:无法分析主机名。“}”。我怎样才能纠正这个错误?顺便说一句,我见过一个类似的问题,但没有被接受的答案(我也不会接受这个问题的答案)在使用c#和MVVM进行集成测试时,如何避免嘲笑IEventAggregator?,c#,wcf,testing,mvvm,integration,C#,Wcf,Testing,Mvvm,Integration,我正在进行集成测试,我希望在不进行模拟的情况下进行测试,因为我希望能够对wcf服务、数据库等进行端到端的测试。我的代码如下,其中我有一条评论说,模拟我需要知道如何做,而不是模拟?此代码运行时出现错误“{”无效URI:无法分析主机名。“}”。我怎样才能纠正这个错误?顺便说一句,我见过一个类似的问题,但没有被接受的答案(我也不会接受这个问题的答案) namespace Optimal.SynTQ.Client.Shell.Services.Proxies.Tests { /// ///MyProx
namespace Optimal.SynTQ.Client.Shell.Services.Proxies.Tests
{
///
///MyProxyTests的摘要说明
///
[测试类]
公共类集成TestMyClassProxy
{
#区域测试初始化
私有MyServiceModel\u服务模型;
私有MyFilterServiceModel(U filteredServiceModel);
//私人IMyProxy_MyProxy;
私有MyProxy_MyProxy;
私有ProxyInvoker\u ProxyInvoker;
私家柜台;;
私有IEnumerable\u列表;
私有模拟工厂\u模拟工厂;
私人IUnityContainer\U unityContainer;
私人单位联系人(unityCont);
私有端点管理器_EndpointManager;
私人事件聚合器;
私有事件聚合器_eventAgg;
//私人ILog_日志;
private ilogu log=LogManager.GetLogger(typeof(IntegrationTestMyProxy));
//private Logging.SynTQLogger.Log\u Log;
PagedListServiceModel\u MappedPolicys=null;
[测试初始化]
公共作废设置()
{
XmlConfigurator.Configure();
BasicConfigurator.Configure();
_endpointManager=新的endpointManager();
_eventAggregator=Substitute.For();//模拟
//注册unity容器,然后解析
_unityCont=新的UnityContainer();
_unityCont.RegisterType();
_impersonationFactory=新的impersonationFactory(\u unityCont);
_proxyInvoker=新的proxyInvoker(_impersonationFactory、_endpointManager、_unityCont、_eventAggregator、_log);
_RegisterType(新的ContainerControlledLifetimeManager(),新的注入构造函数(typeof(ITypeMapFactory),MapperRegistry.Mappers));
_unityCont.RegisterType();
_unityCont.RegisterType();
_RegisterType(新注入构造函数(typeof(IConfigurationProvider));
_unityCont.RegisterType();
StaticMapper.createAutoMappingsFromAttribute(Assembly.GetAssembly(typeof(MyViewModel));
}
#端区
[测试方法]
公共无效TestAuditGetFilteredMyDefaultDates()
{
//安排
ConfigurationManager.AppSettings.Set(“myServerPort”、“808”);
ConfigurationManager.AppSettings.Set(“myServerMachineName”、“localhost”);
ConfigurationManager.AppSettings.Set(“myServerMyAddress”、“net.tcp://{0}:{1}/Blah.BlahBlah.MyServer.MyServices/MyService.svc”);
var request=Substitute.For();
//表演
MyProxy _MyProxy=新的MyProxy(_proxyInvoker);
MyViewModel MyViewModel=新的MyViewModel(_MyProxy);
MyFilterServiceModelFilter=Mapper.Map(MyViewModel);
var results=\u MyProxy.GetFilteredMy(filter);
}
}
}
namespace Optimal.SynTQ.Client.Shell.Services.Proxies.Tests
{
/// <summary>
/// Summary description for MyProxyTests
/// </summary>
[TestClass]
public class IntegrationTestMyClassProxy
{
#region Test Initialisation
private MyServiceModel _serviceModel;
private MyFilterServiceModel _filteredServiceModel;
//private IMyProxy _MyProxy;
private MyProxy _MyProxy;
private ProxyInvoker _proxyInvoker;
private int _counter;
private IEnumerable<MyServiceModel> _list;
private ImpersonationFactory _impersonationFactory;
private IUnityContainer _unityContainer;
private UnityContainer _unityCont;
private EndpointManager _endpointManager;
private IEventAggregator _eventAggregator;
private EventAggregator _eventAgg;
//private ILog _log;
private ILog _log = LogManager.GetLogger(typeof(IntegrationTestMyProxy));
//private Logging.SynTQLogger.Log _log;
PagedListServiceModel<MyViewModel> _mappedPolicies = null;
[TestInitialize]
public void Setup()
{
XmlConfigurator.Configure();
BasicConfigurator.Configure();
_endpointManager = new EndpointManager();
_eventAggregator = Substitute.For<IEventAggregator>(); //Mocking
//register unity container then resolve
_unityCont = new UnityContainer();
_unityCont.RegisterType<MyProxy>();
_impersonationFactory = new ImpersonationFactory(_unityCont);
_proxyInvoker = new ProxyInvoker(_impersonationFactory, _endpointManager, _unityCont, _eventAggregator, _log);
_unityCont.RegisterType<ConfigurationStore, ConfigurationStore>(new ContainerControlledLifetimeManager(), new InjectionConstructor(typeof(ITypeMapFactory), MapperRegistry.Mappers));
_unityCont.RegisterType<IConfigurationProvider, ConfigurationStore>();
_unityCont.RegisterType<IConfiguration, ConfigurationStore>();
_unityCont.RegisterType<IMappingEngine, MappingEngine>(new InjectionConstructor(typeof(IConfigurationProvider)));
_unityCont.RegisterType<ITypeMapFactory, TypeMapFactory>();
StaticMapper.CreateAutoMapperMappingsFromAttribute(Assembly.GetAssembly(typeof(MyViewModel)));
}
#endregion
[TestMethod]
public void TestAuditGetFilteredMyDefaultDates()
{
//Arrange
ConfigurationManager.AppSettings.Set("myServerPort", "808");
ConfigurationManager.AppSettings.Set("myServerMachineName", "localhost");
ConfigurationManager.AppSettings.Set("myServerMyAddress", "net.tcp://{0}:{1}/Blah.BlahBlah.MyServer.MyServices/MyService.svc");
var request = Substitute.For<ConfigurationRequest>();
//Act
MyProxy _MyProxy = new MyProxy(_proxyInvoker);
MyViewModel MyViewModel = new MyViewModel(_MyProxy);
MyFilterServiceModel filter = Mapper.Map<MyFilterServiceModel>(MyViewModel);
var results = _MyProxy.GetFilteredMy(filter);
}
}
}