Exemplo n.º 1
0
        public void WebServiceProxyFactorySetsCredential()
        {
            Request request = new Request();

            request.Endpoint        = "endpoint";
            request.OnlineProxyType = typeof(MockClient);

            NetworkCredential creds = new NetworkCredential("user", "pwd");

            MockEndpointCatalog catalog  = new MockEndpointCatalog();
            MockEndpoint        endpoint = new MockEndpoint("endpoint");

            endpoint.Default            = new MockEndpointConfig(defaultURL);
            endpoint.Default.Credential = creds;
            catalog.Endpoints.Add("endpoint", endpoint);

            WCFProxyFactory <IMockService> factory = new WCFProxyFactory <IMockService>((IEndpointCatalog)catalog);

            MockClient proxy = (MockClient)factory.GetOnlineProxy(request, "Network");

            Assert.IsNotNull(proxy);

            Assert.AreEqual("user", proxy.ClientCredentials.UserName.UserName);
            Assert.AreEqual("pwd", proxy.ClientCredentials.UserName.Password);
        }
Exemplo n.º 2
0
        public void FactoryCallTheSpecifiedMethod()
        {
            Request request = new Request();

            request.Endpoint        = "endpoint";
            request.MethodName      = "CalledMethod";
            request.OnlineProxyType = typeof(MockClient);

            NetworkCredential creds = new NetworkCredential("user", "pwd");

            MockEndpointCatalog catalog  = new MockEndpointCatalog();
            MockEndpoint        endpoint = new MockEndpoint("endpoint");

            endpoint.Default            = new MockEndpointConfig(defaultURL);
            endpoint.Default.Credential = creds;
            catalog.Endpoints.Add("endpoint", endpoint);

            WCFProxyFactory <IMockService> factory = new WCFProxyFactory <IMockService>((IEndpointCatalog)catalog);

            MockClient proxy = (MockClient)factory.GetOnlineProxy(request, "Network");

            Exception exception = null;

            factory.CallOnlineProxyMethod(proxy, request, ref exception);

            Assert.IsTrue(proxy.MethodCalled);
        }
Exemplo n.º 3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();

            services.AddAuthentication(IISDefaults.AuthenticationScheme);
            services.AddControllersWithViews();
            services.AddSingleton <IADUser>(p => (IADUser)WCFProxyFactory.GetWCFProxy(typeof(IADUser), Configuration));
            services.AddSingleton <IRegion>(p => (IRegion)WCFProxyFactory.GetWCFProxy(typeof(IRegion), Configuration));
            services.AddTransient <IPDFSaver>(p => (IPDFSaver)WCFProxyFactory.GetWCFProxy(typeof(IPDFSaver), Configuration));

            //services.AddTransient<IService1CWCF>(p => (IService1CWCF)WCFProxyFactory.GetWCFProxy(typeof(IService1CWCF), Configuration));
            //services.AddTransient<IService1СSoapWCF>(p => (IService1СSoapWCF)WCFProxyFactory.GetWCFProxy(typeof(IService1СSoapWCF), Configuration));
            services.AddTransient <IService1C, EFService1C>();
            services.AddTransient <IService1СSoap, Service1СSoap>();

            //services.AddTransient<IServiceNBCHWCF>(p => (IServiceNBCHWCF)WCFProxyFactory.GetWCFProxy(typeof(IServiceNBCHWCF), Configuration));
            services.AddTransient <IServiceNBCH, EFServiceNBCH>();
            services.AddTransient <IServiceNBCHsoap, ServiceNBCHsoap>();

            //services.AddTransient<IServiceRegistrarWCF>(p => (IServiceRegistrarWCF)WCFProxyFactory.GetWCFProxy(typeof(IServiceRegistrarWCF), Configuration));
            services.AddTransient <IServiceRegistrar, EFServiceRegistrar>();

            //services.AddTransient<IServicePDNWCF>(p => (IServicePDNWCF)WCFProxyFactory.GetWCFProxy(typeof(IServicePDNWCF), Configuration));
            services.AddTransient <IServicePDN, EFServicePDN>();

            services.AddTransient <ISecret1C>(p => Secret1C.GetSecret(Configuration));
            services.AddTransient <ISecretNBCH[]>(p => SecretNBCH.GetSecretNBCHs(Configuration));

            //services.AddTransient<IServicePostsWCF>(p => (IServicePostsWCF)WCFProxyFactory.GetWCFProxy(typeof(IServicePostsWCF), Configuration));
            services.AddTransient <IServicePosts, EFServicePosts>();

            services.AddTransient <IServiceInspecting, EFServiceInspecting>();
        }
Exemplo n.º 4
0
        public void CloseOpenedWCFClientBaseOnReleaseOnlineProxy()
        {
            using (ServiceHost serviceHost = new ServiceHost(typeof(MockForReleaseService)))
            {
                serviceHost.Open();
                WCFProxyFactory <IMockForReleaseService> factory = new WCFProxyFactory <IMockForReleaseService>();
                MockClientForRelease client = new MockClientForRelease();
                client.Foo();
                factory.ReleaseOnlineProxy(client);

                Assert.AreEqual(CommunicationState.Closed, client.State);
            }
        }
Exemplo n.º 5
0
        public void GetOnlineProxyUsesProxyAddressIfNoEndPointConfigured()
        {
            Request request = new Request();

            request.Endpoint        = "MissingEndpoint";
            request.MethodName      = "CalledMethod";
            request.OnlineProxyType = typeof(MockClient);
            MockEndpointCatalog            catalog = new MockEndpointCatalog();
            WCFProxyFactory <IMockService> factory = new WCFProxyFactory <IMockService>((IEndpointCatalog)catalog);

            MockClient proxy = (MockClient)factory.GetOnlineProxy(request, "Network");

            Assert.IsNotNull(proxy);
            Assert.IsNotNull(proxy.Endpoint);
            Assert.AreEqual(new EndpointAddress("http://myurl.com"), proxy.Endpoint.Address);
        }
Exemplo n.º 6
0
        public void WhenServiceHostIsDownProxyFactoryShouldLeaveTheClientInClosedState()
        {
            WCFProxyFactory <IMockForReleaseService> factory = new WCFProxyFactory <IMockForReleaseService>();
            MockClientForRelease client = new MockClientForRelease();

            try
            {
                client.Foo();
                Assert.Fail("Should have thrown exception");
            }
            catch (CommunicationException)
            {
                Assert.AreEqual(CommunicationState.Faulted, client.State);
                factory.ReleaseOnlineProxy(client);
                Assert.AreEqual(CommunicationState.Closed, client.State);
            }
        }
Exemplo n.º 7
0
        public void WhenServiceThrowsProxyFactoryShouldLeaveTheClientInClosedState()
        {
            using (ServiceHost serviceHost = new ServiceHost(typeof(MockForReleaseService)))
            {
                serviceHost.Open();

                WCFProxyFactory <IMockForReleaseService> factory = new WCFProxyFactory <IMockForReleaseService>();
                MockClientForRelease client = new MockClientForRelease();
                try
                {
                    client.FooThrow();
                    Assert.Fail("Should have thrown exception");
                }
                catch (Exception)
                {
                    Assert.AreEqual(CommunicationState.Faulted, client.State);
                    factory.ReleaseOnlineProxy(client);
                    Assert.AreEqual(CommunicationState.Closed, client.State);
                }
            }
        }
Exemplo n.º 8
0
        public void WebServiceProxyFactoryCreatesAnObjectOfTheOnlineProxyType()
        {
            Request request = new Request();

            request.Endpoint        = "endpoint";
            request.OnlineProxyType = typeof(MockClient);

            NetworkCredential creds = new NetworkCredential("user", "pwd");

            MockEndpointCatalog catalog  = new MockEndpointCatalog();
            MockEndpoint        endpoint = new MockEndpoint("endpoint");

            endpoint.Default            = new MockEndpointConfig(defaultURL);
            endpoint.Default.Credential = creds;
            catalog.Endpoints.Add("endpoint", endpoint);

            WCFProxyFactory <IMockService> factory = new WCFProxyFactory <IMockService>((IEndpointCatalog)catalog);


            object proxy = factory.GetOnlineProxy(request, "Network");

            Assert.IsNotNull(proxy);
            Assert.AreEqual(typeof(MockClient), proxy.GetType());
        }
Exemplo n.º 9
0
        public void CanCreateWithEndpointCatalog()
        {
            WCFProxyFactory <IMockService> factory = new WCFProxyFactory <IMockService>(new MockEndpointCatalog());

            Assert.IsNotNull(factory);
        }
Exemplo n.º 10
0
        public void FactoryIsIProxyFactory()
        {
            WCFProxyFactory <IMockService> factory = new WCFProxyFactory <IMockService>();

            Assert.IsTrue(factory is IProxyFactory);
        }