Exemplo n.º 1
0
        public void TestSimpleEndpointClientThrowException()
        {
            CalculationEndpoint calculation = new CalculationEndpoint(false);

            Assert.AreEqual("Calculation", calculation.EndpointName);
            Assert.AreEqual(false, calculation.EnableAsynchronization);

            PrimitiveEndpointClientProvider provider            = new PrimitiveEndpointClientProvider(calculation);
            ICalculationEndpoint            calculationEndpoint = StrongTypedNodeEndpointClientBuilder.Create <ICalculationEndpoint>(provider);

            calculationEndpoint.ThrowException();
        }
Exemplo n.º 2
0
        public void TestSimpleEndpointClient()
        {
            CalculationEndpoint calculation = new CalculationEndpoint(false);

            Assert.AreEqual("Calculation", calculation.EndpointName);
            Assert.AreEqual(false, calculation.EnableAsynchronization);

            PrimitiveEndpointClientProvider provider            = new PrimitiveEndpointClientProvider(calculation);
            ICalculationEndpoint            calculationEndpoint = StrongTypedNodeEndpointClientBuilder.Create <ICalculationEndpoint>(provider);

            Assert.AreEqual(3, calculationEndpoint.Add(2, 1));
            Assert.AreEqual(1, calculationEndpoint.Sub(2, 1));
            Assert.AreEqual(2, calculationEndpoint.Mul(2, 1));
            Assert.AreEqual(2, calculationEndpoint.Div(2, 1));

            calculationEndpoint.SendMessage("Vczh is a genius!");
            Assert.AreEqual("Vczh is a genius!", calculationEndpoint.ReceiveMessage());
            Assert.AreEqual("Vczh is a genius!", calculation.Message);
        }
Exemplo n.º 3
0
        public static void TestProtocol(INodeEndpointProtocolFactory serverFactory, INodeEndpointProtocolFactory clientFactory, string serverAddress, string clientAddress)
        {
            INodeEndpointProtocolServer server = null;

            Thread serverThread = new Thread(() =>
            {
                INodeEndpointProtocolServerListener serverListener = serverFactory.CreateServerListener();
                server = serverListener.WaitForServer(serverAddress, new CalculationEndpoint(true));
            });

            serverThread.Start();

            ICalculationEndpoint client = clientFactory.WaitForClient <ICalculationEndpoint>(clientAddress, "Calculation");

            Assert.IsNotNull(client);

            Assert.AreEqual(3, client.Add(2, 1));
            Assert.AreEqual(1, client.Sub(2, 1));
            Assert.AreEqual(2, client.Mul(2, 1));
            Assert.AreEqual(2, client.Div(2, 1));

            Point point = client.Swap(new Point {
                X = 1, Y = 2
            });

            Assert.AreEqual(2, point.X);
            Assert.AreEqual(1, point.Y);

            Cat cat = (Cat)client.CopyAnimal(new Cat {
                name = "cat", catName = "bigcat"
            });

            Assert.AreEqual("cat", cat.name);
            Assert.AreEqual("bigcat", cat.catName);

            Dog dog = (Dog)client.CopyAnimal(new Dog {
                name = "dog", dogName = "bigdog"
            });

            Assert.AreEqual("dog", dog.name);
            Assert.AreEqual("bigdog", dog.dogName);

            client.SendMessage("Vczh is a genius!");
            Assert.AreEqual("Vczh is a genius!", client.ReceiveMessage());

            AssertCollection(client.CopyArray(Enumerable.Range(0, 10).ToArray()));
            AssertCollection(client.CopyList(new List <int>(Enumerable.Range(0, 10))));
            AssertCollection(client.CopyHashSet(new HashSet <int>(Enumerable.Range(0, 10))));
            AssertCollection(client.CopyLinkedList(new LinkedList <int>(Enumerable.Range(0, 10))));
            AssertCollection(client.CopyQueue(new Queue <int>(Enumerable.Range(0, 10))));
            AssertCollection(client.CopySortedSet(new SortedSet <int>(Enumerable.Range(0, 10))));
            AssertCollection(client.CopyStack(new Stack <int>(Enumerable.Range(0, 10).Reverse())));

            Dictionary <int, int> dictionary = Enumerable.Range(0, 10).ToDictionary(i => i);

            AssertCollection(client.CopyDictionary(dictionary));
            AssertCollection(client.CopySortedDictionary(new SortedDictionary <int, int>(dictionary)));
            AssertCollection(client.CopySortedList(new SortedList <int, int>(dictionary)));

            byte[] bytes = new byte[] { 1, 2, 3, 4, 5 };
            using (Stream stream = client.CopyStream(bytes))
            {
                byte[] copied = stream.ReadAllBytes();
                Assert.AreEqual("[1][2][3][4][5]", bytes.Select(b => "[" + b.ToString() + "]").Aggregate("", (a, b) => a + b));
            }
        }