Ejemplo n.º 1
0
        public void ServerReturnsBigData_EnsureReceivedOnClient()
        {
            ITestContractAsync channel = CreateChannel();

            Server()
            .Setup(v => v.FunctionReturningHugeData())
            .Returns(() => Enumerable.Repeat(0, 1000).Select(_ => CompositeType.CreateRandom()).ToList());

            List <CompositeType> result = channel.FunctionReturningHugeData();

            Assert.Equal(1000, result.Count);
        }
Ejemplo n.º 2
0
        public void Client_ManyComplexParameters_EnsureSameOnServer()
        {
            var client = CreateChannel();
            Mock <ITestContract> server = Server();

            CompositeType arg1 = CompositeType.CreateRandom();
            CompositeType arg2 = CompositeType.CreateRandom();
            DateTime      arg3 = DateTime.UtcNow;

            server.Setup(v => v.MethodWithManyArguments(arg1, arg2, arg3));
            client.MethodWithManyArguments(arg1, arg2, arg3);
        }
Ejemplo n.º 3
0
        public void Client_CallsComplexFunction_EnsureValidDataReturned()
        {
            var client = CreateChannel();
            Mock <ITestContract> server = Server();

            CompositeType serverData = CompositeType.CreateRandom();

            server.Setup(v => v.ComplexFunction()).Returns(serverData);
            CompositeType clientData = client.ComplexFunction();

            Assert.Equal(serverData, clientData);
        }
Ejemplo n.º 4
0
        public void ClientSendsBigData_EnsureReceivedOnServer()
        {
            ITestContractAsync channel = CreateChannel();
            var data = Enumerable.Repeat(0, 1000).Select(_ => CompositeType.CreateRandom()).ToList();

            Mock <ITestContract> server = Server();

            server.Setup(v => v.MethodTakingHugeData(It.IsAny <List <CompositeType> >()))
            .Callback <List <CompositeType> >(v => Assert.Equal(1000, v.Count));

            channel.MethodTakingHugeData(data);

            server.Verify(v => v.MethodTakingHugeData(It.IsAny <List <CompositeType> >()));
        }
Ejemplo n.º 5
0
        public void Client_ComplexParameters_EnsureSameOnServer()
        {
            ITestContract        client = CreateChannel();
            Mock <ITestContract> server = Server();
            CompositeType        arg1   = CompositeType.CreateRandom();

            server.Setup(v => v.SimpleMethodWithComplexParameter(arg1)).Callback <CompositeType>(serverArg =>
            {
                Assert.NotSame(serverArg, arg1);
                Assert.Equal(serverArg, arg1);
            });

            client.SimpleMethodWithComplexParameter(arg1);
        }
Ejemplo n.º 6
0
        public void LongOperation_TimeoutSet_EnsureCallTimeouted()
        {
            IClientPipeline pipeline = CreatePipeline();

            pipeline.Find <CommunicationMiddleware>().ResponseTimeout = TimeSpan.FromSeconds(0.1);

            ITestContractAsync client = CreateChannel(pipeline);

            CompositeType arg = CompositeType.CreateRandom();

            Mock <ITestContract> server = Server();

            server.Setup(v => v.SimpleMethodWithComplexParameter(arg)).Callback(() => Thread.Sleep(TimeSpan.FromSeconds(10)));
            Assert.Throws <TimeoutException>(() => client.SimpleMethodWithComplexParameter(arg));
        }
Ejemplo n.º 7
0
        public void WriteParametersOnClient_ReadOnServer_OK()
        {
            var arg1 = CompositeType.CreateRandom();
            var arg2 = CompositeType.CreateRandom();
            var arg3 = DateTime.UtcNow;

            Server().Setup(v => v.MethodWithManyArguments(arg1, arg2, arg3)).Callback <CompositeType, CompositeType, DateTime>(
                (a1, a2, a3)
                =>
            {
                Assert.Equal(arg1, a1);
                Assert.Equal(arg2, a2);
                Assert.Equal(arg3, a3);
            });

            CreateChannel().MethodWithManyArguments(arg1, arg2, arg3);
        }
Ejemplo n.º 8
0
        public void WriteResponseOnServer_ReadOnClient_OK()
        {
            var data = new List <CompositeType>()
            {
                CompositeType.CreateRandom(),
                CompositeType.CreateRandom(),
                CompositeType.CreateRandom(),
                CompositeType.CreateRandom()
            };

            Server().Setup(v => v.FunctionReturningHugeData()).Returns(data);

            var returned = CreateChannel().FunctionReturningHugeData();

            Assert.Equal(data.Count, returned.Count);
            for (int i = 0; i < data.Count; i++)
            {
                Assert.Equal(returned[i], data[i]);
            }
        }