public void SendRequestTest() { string uri = "net.tcp://localhost:8889"; // Open frontend Uri listenUri = new Uri(uri); NetTcpBinding binding = new NetTcpBinding(SecurityMode.None); MockBrokerQueue queue = new MockBrokerQueue(); queue.DirectReply = true; DuplexFrontEnd target = new DuplexFrontEnd(listenUri, binding, null, queue, null, null); target.Open(); MockWCFClient client = new MockWCFClient(binding, new EndpointAddress(uri)); try { client.Calc(4); } catch (FaultException fe) { Assert.AreEqual(fe.Code.SubCode.Name, "DummyReply"); } target.Close(); }
/// <summary> /// Send message with security /// </summary> //[TestMethod] public void SendMessageWithSecurity() { string uri = String.Format("https://{0}:8080", Environment.MachineName); // Open frontend Uri listenUri = new Uri(uri); BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential); binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; MockBrokerAuthorization auth = new MockBrokerAuthorization(); MockBrokerQueue queue = new MockBrokerQueue(); queue.DirectReply = true; RequestReplyFrontEnd <IReplyChannel> target = new RequestReplyFrontEnd <IReplyChannel>(listenUri, binding, auth, queue); target.Open(); // Build channel to send request MockWCFClient client = new MockWCFClient(binding, new EndpointAddress(uri)); client.ClientCredentials.UserName.UserName = "******"; client.ClientCredentials.UserName.Password = "******"; auth.Allow = false; try { client.Calc(3); } catch (FaultException fe) { Assert.AreEqual(fe.Code.Name, "AuthenticationFailure"); } // Send request which is allowed auth.Allow = true; try { client.Calc(4); } catch (FaultException fe) { Assert.AreEqual(fe.Code.Name, "DummyReply"); } client.Close(); target.Close(); }
public void NewDispatcherTest() { int jobId = 1; int taskId = 1; int niceId = 1; string machineName = Environment.MachineName; EndpointAddress epr = this.GetEndpointAddress(jobId, taskId, machineName); MockBrokerQueue queue = new MockBrokerQueue(); ServiceHost host = StartMockServiceHost(epr); Global.SetBrokerQueue(new MockBrokerQueue()); DispatcherManager manager = new DispatcherManager(1, String.Empty); manager.NewDispatcher(jobId, taskId, niceId, machineName); Message request = Message.CreateMessage(MessageVersion.Default, "NewDispatcherTest", "Test"); request.Headers.MessageId = new UniqueId(); queue.TriggerGetRequestCallback(new BrokerQueueItem(new DummyRequestContext(MessageVersion.Default), request, null)); Thread.Sleep(500); int tryCount = 0; while (tryCount < 3) { if (queue.ReplyMessageQueue.Count > 0) { Message reply = queue.ReplyMessageQueue.Dequeue(); string replyMessage = reply.GetBody <string>(); Assert.AreEqual("TestReply", replyMessage); break; } Thread.Sleep(3000); tryCount++; } if (tryCount >= 3) { Assert.Fail("Timeout"); } host.Close(); }
public void SendRequestTestWithSecurity() { string uri = "net.tcp://localhost:8889"; // Open frontend Uri listenUri = new Uri(uri); NetTcpBinding binding = new NetTcpBinding(SecurityMode.Transport); MockBrokerQueue queue = new MockBrokerQueue(); MockBrokerAuthorization auth = new MockBrokerAuthorization(); queue.DirectReply = true; DuplexFrontEnd target = new DuplexFrontEnd(listenUri, binding, auth, queue); target.Open(); MockWCFClient client = new MockWCFClient(binding, new EndpointAddress(uri)); auth.Allow = true; try { client.Calc(4); } catch (FaultException fe) { Assert.AreEqual(fe.Code.SubCode.Name, "DummyReply"); } auth.Allow = false; try { client.Calc(4); } catch (FaultException fe) { Assert.AreEqual(fe.Code.SubCode.Name, "AuthenticationFailure"); } target.Close(); }
public void SendRequestWithoutSecurity() { string uri = "http://localhost:8888"; // Open frontend Uri listenUri = new Uri(uri); Binding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); MockBrokerQueue queue = new MockBrokerQueue(); queue.DirectReply = true; RequestReplyFrontEnd <IReplyChannel> target = new RequestReplyFrontEnd <IReplyChannel>(listenUri, binding, null, queue); target.Open(); // Build channel to send request IChannelFactory <IRequestChannel> factory = binding.BuildChannelFactory <IRequestChannel>(); factory.Open(); IRequestChannel channel = factory.CreateChannel(new EndpointAddress(uri)); channel.Open(); Message request = Message.CreateMessage(MessageVersion.Soap11, "UnitTest", "Test"); try { Message reply = channel.Request(request); } catch (FaultException fe) { Assert.AreEqual(fe.Code.Name, "DummyReply"); } channel.Close(); factory.Close(); target.Close(); }