Example #1
0
        public void CreateMultipleChannelsForTheSameType_Expected_MultipleFactoryCreated()
        {
            var channelFactory1 = new AsyncChannelFactory <ITestService>();

            var channel1 = channelFactory1.CreateChannel();
            var channel2 = channelFactory1.CreateChannel();
        }
Example #2
0
        public void Task_InvokingComplexOperation_Expected_OperationInvoked()
        {
            var             channelFactory = new AsyncChannelFactory <ITestServiceOut>();
            var             channel        = channelFactory.CreateChannel();
            ComplexDataType data           = new ComplexDataType
            {
                Description = "in",
                Name        = "in name",
                Id          = 0,
            };

            var result =
                channel.ExecuteTask(ws => ws.ComplexMethod(ref data))
                .ContinueWith(
                    t =>
            {
                var res = t.Result;
                Assert.AreEqual("ref", data.Description);
                Assert.AreEqual("ref name", data.Name);
                Assert.AreEqual(1, data.Id);

                Assert.AreEqual("out", res.Description);
                Assert.AreEqual("out name", res.Name);
                Assert.AreEqual(2, res.Id);
                TestComplete();
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
Example #3
0
        public void InvokingComplexOperation_Expected_OperationInvoked()
        {
            var             channelFactory = new AsyncChannelFactory <ITestServiceOut>();
            var             channel        = channelFactory.CreateChannel();
            ComplexDataType data           = new ComplexDataType
            {
                Description = "in",
                Name        = "in name",
                Id          = 0,
            };

            var result =
                channel.ExecuteAsync(
                    ws => ws.ComplexMethod(ref data),
                    res =>
            {
                Assert.AreEqual("ref", data.Description);
                Assert.AreEqual("ref name", data.Name);
                Assert.AreEqual(1, data.Id);

                Assert.AreEqual("out", res.Description);
                Assert.AreEqual("out name", res.Name);
                Assert.AreEqual(2, res.Id);
                TestComplete();
            });
        }
Example #4
0
 public void Task_InvokingVoidOperation_Expected_OperationInvoked()
 {
     var channelFactory = new AsyncChannelFactory <ITestService>();
     var channel        = channelFactory.CreateChannel();
     var res            =
         channel.ExecuteTask(ws => ws.VoidOperation(0))
         .ContinueWith(x => TestComplete(), TaskScheduler.FromCurrentSynchronizationContext());
 }
Example #5
0
        public void Task_CreateProxy_Expected_ProxyCommunicate()
        {
            var channelFactory = new AsyncChannelFactory <ITestService>();
            var channel        = channelFactory.CreateChannel();

            var t = channel.ExecuteTask(ws => ws.Operation(1 + 4))
                    .ContinueWith(x => TestComplete(), TaskScheduler.FromCurrentSynchronizationContext());
        }
Example #6
0
 public void Task_InvokingOperationPassingAState_Expected_StateReceived()
 {
     var channelFactory = new AsyncChannelFactory <ITestService>();
     var channel        = channelFactory.CreateChannel();
     var res            = channel.ExecuteTask(ws => ws.Operation(0), "Status Message")
                          .ContinueWith(t =>
     {
         Assert.AreEqual("Status Message", t.AsyncState);
         TestComplete();
     }, TaskScheduler.FromCurrentSynchronizationContext());
 }
Example #7
0
        public void OpenService_Expected_ServiceOpen()
        {
            var channelFactory = new AsyncChannelFactory <ITestService>();
            var channel        = channelFactory.CreateChannel();

            Assert.AreEqual(CommunicationState.Created, channel.State);
            channel.Open(() =>
            {
                Assert.AreEqual(CommunicationState.Opened, channel.State);
                TestComplete();
            });
        }
Example #8
0
 public void InvokingVoidOperation_Expected_OperationInvoked()
 {
     var channelFactory = new AsyncChannelFactory <ITestService>();
     var channel        = channelFactory.CreateChannel();
     var res            =
         channel.ExecuteAsync(
             ws => ws.VoidOperation(0),
             () =>
     {
         TestComplete();
     });
 }
Example #9
0
 public void Task_InvokingOutOperation_Expected_OperationInvoked()
 {
     var channelFactory = new AsyncChannelFactory <ITestServiceOut>();
     var channel        = channelFactory.CreateChannel();
     int a   = 1;
     var res =
         channel.ExecuteTask(ws => ws.Method(ref a))
         .ContinueWith(x =>
     {
         Assert.AreEqual(9, a);
         TestComplete();
     }, TaskScheduler.FromCurrentSynchronizationContext());
 }
Example #10
0
        public void InvokeAnOperationDefinedInAnInheritedServiceInterface_Expected_OperationPerformed()
        {
            var channelFactory = new AsyncChannelFactory <IDerivedTestService>();
            var channel        = channelFactory.CreateChannel();

            channel.ExecuteAsync(
                ws => ws.VoidOperation(1),
                () =>
            {
                TestComplete();
            },
                exception => { Assert.Fail(); });
        }
Example #11
0
 public void InvokingOperationPassingAState_Expected_StateReceived()
 {
     var channelFactory = new AsyncChannelFactory <ITestService>();
     var channel        = channelFactory.CreateChannel();
     var res            =
         channel.ExecuteAsync(
             ws => ws.Operation(0),
             "status message",
             (result, status) =>
     {
         Assert.AreEqual("status message", status);
         TestComplete();
     });
 }
Example #12
0
 public void InvokingOutOperation2_Expected_OperationInvoked()
 {
     var channelFactory = new AsyncChannelFactory <duplicate.ITestServiceOut>();
     var channel        = channelFactory.CreateChannel();
     int a   = 1;
     var res =
         channel.ExecuteAsync(
             ws => ws.Method(ref a),
             () =>
     {
         Assert.AreEqual(29, a);
         TestComplete();
     });
 }
Example #13
0
 public void CreateProxy_Expected_ProxyCommunicate()
 {
     var channelFactory = new AsyncChannelFactory <ITestService>();
     var channel        = channelFactory.CreateChannel();
     int number         = 0;
     var res            =
         channel.ExecuteAsync(
             ws => ws.Operation(1 + 4),
             result =>
     {
         number = result + 1;
         Assert.AreEqual(number, 7);
         TestComplete();
     });
 }
Example #14
0
        public void OpenServiceWithSatus_Expected_StatusPassed()
        {
            var channelFactory = new AsyncChannelFactory <ITestService>();
            var channel        = channelFactory.CreateChannel();

            Assert.AreEqual(CommunicationState.Created, channel.State);

            channel.Open(
                "test status object",
                (status) =>
            {
                Assert.AreEqual("test status object", status);
                TestComplete();
            });
        }
Example #15
0
        public void InvokingCorrectlyWorkingOperation_Expected_OperationStatusChangeToOpened()
        {
            var channelFactory = new AsyncChannelFactory <ITestService>();
            var channel        = channelFactory.CreateChannel();

            Assert.AreEqual(CommunicationState.Created, channel.State);
            var res =
                channel.ExecuteAsync(
                    ws => ws.Operation(0),
                    () =>
            {
                Assert.AreEqual(CommunicationState.Opened, channel.State);
                TestComplete();
            });
        }
Example #16
0
        public void Task_InvokingCorrectlyWorkingOperation_Expected_OperationStatusChangeToOpened()
        {
            var channelFactory = new AsyncChannelFactory <ITestService>();
            var channel        = channelFactory.CreateChannel();

            Assert.AreEqual(CommunicationState.Created, channel.State);
            var res =
                channel.ExecuteTask(ws => ws.Operation(0))
                .ContinueWith(
                    (t) =>
            {
                Assert.AreEqual(CommunicationState.Opened, channel.State);
                TestComplete();
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
Example #17
0
        public void Task_InvokeAnOperationDefinedInAnInheritedServiceInterface_Expected_OperationPerformed()
        {
            var channelFactory = new AsyncChannelFactory <IDerivedTestService>();
            var channel        = channelFactory.CreateChannel();

            channel.ExecuteTask(ws => ws.VoidOperation(1))
            .ContinueWith(
                (t) =>
            {
                if (t.IsFaulted)
                {
                    Assert.Fail();
                }
                TestComplete();
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
Example #18
0
 public void InvokingFaultingOperation_Expected_ExceptionCatched()
 {
     var channelFactory = new AsyncChannelFactory <ITestService>();
     var channel        = channelFactory.CreateChannel();
     var res            =
         channel.ExecuteAsync(
             ws => ws.FaultingOperation(0),
             result =>
     {
         Assert.Fail();
     },
             exception =>
     {
         TestComplete();
     });
 }
Example #19
0
        public void Task_UseWithOperationContextScope_Expected_OperationPerformed()
        {
            var channelFactory = new AsyncChannelFactory <IDerivedTestService>();
            var channel        = channelFactory.CreateChannel();

            var userContextHeaderName      = "UserContext";
            var userContextHeaderNamespace = "http://my.context.namespace/";
            var userContextHeaderValue     = "My user context";

            var testPart = new MultipartComplete(2, TestComplete);

            using (var scope = new OperationContextScope(channel.ToContextChannel()))
            {
                OperationContext.Current.OutgoingMessageHeaders.Add(
                    MessageHeader.CreateHeader(
                        userContextHeaderName,
                        userContextHeaderNamespace,
                        userContextHeaderValue));

                channel.ExecuteTask(ws => ws.ReadHeaderOperation())
                .ContinueWith(t =>
                {
                    if (t.IsFaulted)
                    {
                        Assert.Fail();
                    }
                    var result = t.Result;
                    Assert.AreEqual(userContextHeaderValue, result);
                    testPart.Completed();
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }

            channel.ExecuteTask(ws => ws.ReadHeaderOperation())
            .ContinueWith(
                t =>
            {
                if (t.IsFaulted)
                {
                    Assert.Fail();
                }
                var result = t.Result;
                Assert.IsNull(result);
                testPart.Completed();
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
Example #20
0
        public void Task_InvokingFaultingOperation_Expected_ExceptionCatched()
        {
            var channelFactory = new AsyncChannelFactory <ITestService>();
            var channel        = channelFactory.CreateChannel();

            var res = channel.ExecuteTask(ws => ws.FaultingOperation(0))
                      .ContinueWith(x =>
            {
                if (x.IsFaulted)
                {
                    TestComplete();
                }
                else
                {
                    Assert.Fail();
                }
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
Example #21
0
        public void UseWithOperationContextScope_Expected_OperationPerformed()
        {
            var channelFactory = new AsyncChannelFactory <IDerivedTestService>();
            var channel        = channelFactory.CreateChannel();

            var userContextHeaderName      = "UserContext";
            var userContextHeaderNamespace = "http://my.context.namespace/";
            var userContextHeaderValue     = "My user context";

            var testPart = new MultipartComplete(2, TestComplete);

            using (var scope = new OperationContextScope(channel.ToContextChannel()))
            {
                OperationContext.Current.OutgoingMessageHeaders.Add(
                    MessageHeader.CreateHeader(
                        userContextHeaderName,
                        userContextHeaderNamespace,
                        userContextHeaderValue));

                channel.ExecuteAsync(
                    ws => ws.ReadHeaderOperation(),
                    result =>
                {
                    Assert.AreEqual(userContextHeaderValue, result);
                    testPart.Completed();
                },
                    exception => { Assert.Fail(); });
            }

            channel.ExecuteAsync(
                ws => ws.ReadHeaderOperation(),
                result =>
            {
                Assert.IsNull(result);
                testPart.Completed();
            },
                exception => { Assert.Fail(); });
        }