Exemple #1
0
        /// <summary>
        /// GetObject a ServiceProxy that is configured to call the service under test. Both the port and the hostname of
        /// the provided ServiceProxy is changed to match those of the service which was started by the ServiceTester.
        /// </summary>
        /// <param name="timeout">Optional. The timeout for ServiceProxy calls.</param>
        /// <typeparam name="TServiceInterface"></typeparam>
        /// <returns>An ServiceProxy instance of <see cref="TServiceInterface"/>.</returns>
        public virtual TServiceInterface GetServiceProxy <TServiceInterface>(TimeSpan?timeout = null)
        {
            var factory = ResolutionRoot.Get <Func <string, Func <string, ReachabilityChecker, IServiceDiscovery>, IServiceProxyProvider> >();

            var provider = new ServiceProxyProvider <TServiceInterface>(serviceName => factory(serviceName, (serName, checker) => new LocalhostServiceDiscovery()));

            provider.DefaultPort = BasePort;
            if (timeout != null)
            {
                provider.InnerProvider.SetHttpTimeout(timeout.Value);
            }

            return(provider.Client);
        }
Exemple #2
0
        /// <summary>
        /// GetObject a ServiceProxy that is configured to call the service under test. Both the port and the hostname of
        /// the provided ServiceProxy is changed to match those of the service which was started by the ServiceTester.
        /// </summary>
        /// <param name="serviceName">Name of service </param>
        /// <param name="timeout">Optional. The timeout for ServiceProxy calls.</param>
        /// <returns>An ServiceProxy instance of <see cref="TServiceInterface"/>.</returns>
        public virtual ServiceProxyProvider GetServiceProxyProvider(string serviceName, TimeSpan?timeout = null)
        {
            var factory = ResolutionRoot.Get <Func <string, Func <string, ReachabilityChecker, IServiceDiscovery>, ServiceProxyProvider> >();

            var provider = factory(serviceName, (srName, r) => new LocalhostServiceDiscovery());

            provider.DefaultPort = BasePort;
            if (timeout != null)
            {
                provider.SetHttpTimeout(timeout.Value);
            }

            return(provider);
        }
Exemple #3
0
        /// <summary>
        /// GetObject a ServiceProxy with caching  that is configured to call the service under test. Both the port and the hostname of
        /// the provided ServiceProxy is changed to match those of the service which was started by the ServiceTester.
        /// </summary>
        /// <param name="timeout">Optional. The timeout for ServiceProxy calls.</param>
        /// <typeparam name="TServiceInterface"></typeparam>
        /// <returns>An ServiceProxy with caching <see cref="TServiceInterface"/>.</returns>
        public virtual TServiceInterface GetServiceProxyWithCaching <TServiceInterface>(TimeSpan?timeout = null)
        {
            var factory = ResolutionRoot
                          .Get <Func <string, Func <string, ReachabilityChecker, IServiceDiscovery>, IServiceProxyProvider> >();
            var provider = new ServiceProxyProvider <TServiceInterface>(serviceName => factory(serviceName, (serName, checker) => new LocalhostServiceDiscovery()));

            provider.DefaultPort = BasePort;
            if (timeout != null)
            {
                provider.InnerProvider.SetHttpTimeout(timeout.Value);
            }
            if (ResolutionRoot.Get <IMetadataProvider>().HasCachedMethods(typeof(TServiceInterface)))
            {
                var cachingProxy = ResolutionRoot.Get <CachingProxyProvider <TServiceInterface> >(
                    new ConstructorArgument("dataSource", provider.Client),
                    new ConstructorArgument("serviceName", (string)null));

                return(cachingProxy.Proxy);
            }
            return(provider.Client);
        }