我是集成测试,我想在没有Mocking的情况下进行测试,因为我想要结束wcf服务,数据库等。我的代码在下面,我有一个评论说Mocking我需要知道该怎么做而不是嘲笑?此代码运行但出现错误“{”无效的URI:无法解析主机名。“}”。我该如何解决这个错误?顺便说一下,我看到过类似的问题,但没有接受答案(我也不会接受这个问题的答案)。
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);
}
}
}