コード例 #1
0
        public void Test_Lambda_RemoveOnCommand_CustomCreator_NonGeneric()
        {
            var testHandler = new TestHandler();

            byte[] serializedData    = new byte[] { 1, 2, 3 };
            byte[] serializedMessage = new byte[] { 1, 2, 3, 4 };
            string unserializedData  = "some data";
            var    mockSerializer    = new Mock <ISerializer>();

            mockSerializer.Setup(m => m.Deserialize <NetworkMessage>(serializedMessage)).Returns(new NetworkMessage {
                Data = serializedData, Name = "System.String"
            });
            mockSerializer.Setup(m => m.Deserialize <string>(serializedData)).Returns(unserializedData);

            var mockConnection = new Mock <IConnection>();

            var objectConnection = new DefaultObjectConnection(mockConnection.Object)
            {
                Serializer = mockSerializer.Object
            };
            bool OnCommandHasBeenCalled            = false;
            Action <IObjectConnection, string> del = (c, s) => OnCommandHasBeenCalled = true;
            string creator = "CreatorObject :)";

            objectConnection.OnCommand <string>(del, creator: creator);
            objectConnection.RemoveOnCommand(creator);

            //Act
            mockConnection.Raise(m => m.OnDataReceived += null, serializedMessage);

            Assert.IsFalse(OnCommandHasBeenCalled);
        }
コード例 #2
0
        public void Test_Lambda_OnCommand()
        {
            var testHandler = new TestHandler();

            byte[] serializedData    = new byte[] { 1, 2, 3 };
            byte[] serializedMessage = new byte[] { 1, 2, 3, 4 };
            string unserializedData  = "some data";
            var    mockSerializer    = new Mock <ISerializer>();

            mockSerializer.Setup(m => m.Deserialize <NetworkMessage>(serializedMessage)).Returns(new NetworkMessage {
                Data = serializedData, Name = "System.String"
            });
            mockSerializer.Setup(m => m.Deserialize <string>(serializedData)).Returns(unserializedData);

            var mockConnection = new Mock <IConnection>();

            var objectConnection = new DefaultObjectConnection(mockConnection.Object)
            {
                Serializer = mockSerializer.Object
            };
            bool OnCommandHasBeenCalled = false;

            objectConnection.OnCommand <string>((c, s) => OnCommandHasBeenCalled = true);

            //Act
            mockConnection.Raise(m => m.OnDataReceived += null, serializedMessage);

            Assert.IsTrue(OnCommandHasBeenCalled);
        }