Beispiel #1
0
        public void LayerStackProvider_StatelessLayerStackDoesNotReallocate()
        {
            var         provider = new LayerStackProvider <Dummy>(LoggerTests.BlackHole, new TestLayer_AlwaysThrows(), new TestLayer_AlwaysThrows());
            ILayerStack stack;
            Error       error = provider.GetLayerStack(null, out stack);

            Assert.IsNull(error);
            ILayerStack stack2;

            error = provider.GetLayerStack(null, out stack2);
            Assert.IsNull(error);
            Assert.AreSame(stack, stack2);
        }
        public void LayerStack_OnSend_InvokesForwardOrder()
        {
            var         testList      = new List <string>();
            var         testLayer1    = new TestLayer_Append("foo", testList);
            var         testLayer2    = new TestLayer_Append("bar", testList);
            var         stackProvider = new LayerStackProvider <Dummy>(testLayer1, testLayer2);
            Logger      logger        = LoggerTests.BlackHole;
            ILayerStack stack;
            Error       error = stackProvider.GetLayerStack(null, out stack, logger);

            Assert.IsNull(error);

            IBonded layerData;

            error = stack.OnSend(MessageType.REQUEST, sendContext, out layerData, logger);

            Assert.IsNull(error);
            Assert.IsNotNull(layerData);

            Dummy realLayerData = layerData.Deserialize <Dummy>();

            Assert.AreEqual(2, testList.Count);
            Assert.AreEqual(testLayer1.value, testList[0]);
            Assert.AreEqual(testLayer1.value + testLayer2.value, testList[1]);
            Assert.IsNotNull(realLayerData);
            Assert.AreEqual(testLayer1.value + testLayer2.value, realLayerData.string_value);
        }
        public void LayerStackProvider_StatefulLayerStackDoesReallocate()
        {
            var provider = new LayerStackProvider <Dummy>(new TestLayer_AlwaysThrows(),
                                                          new TestLayerProvider_StatefulAppend("foo"),
                                                          new TestLayer_AlwaysThrows());
            Logger      logger = LoggerTests.BlackHole;
            ILayerStack stack;
            Error       error = provider.GetLayerStack(null, out stack, logger);

            Assert.IsNull(error);
            ILayerStack stack2;

            error = provider.GetLayerStack(null, out stack2, logger);
            Assert.IsNull(error);
            Assert.AreNotSame(stack, stack2);
        }
Beispiel #4
0
        public void LayerStack_OnReceive_InvokesReverseOrder()
        {
            var         testList      = new List <string>();
            var         testLayer1    = new TestLayer_Append("foo", testList);
            var         testLayer2    = new TestLayer_Append("bar", testList);
            var         stackProvider = new LayerStackProvider <Dummy>(LoggerTests.BlackHole, testLayer1, testLayer2);
            ILayerStack stack;
            Error       error = stackProvider.GetLayerStack(null, out stack);

            Assert.IsNull(error);

            error = stack.OnReceive(MessageType.Request, receiveContext, CreateBondedTestData(initialReceiveValue));

            Assert.IsNull(error);
            Assert.AreEqual(2, testList.Count);
            Assert.AreEqual(initialReceiveValue + testLayer2.value, testList[0]);
            Assert.AreEqual(initialReceiveValue + testLayer2.value + testLayer1.value, testList[1]);
        }