public void HandleEchoList() { var list = new KRPC.Schema.KRPC.List(); list.Items.Add(ProtocolBuffers.WriteValue("jeb", typeof(string))); list.Items.Add(ProtocolBuffers.WriteValue("bob", typeof(string))); list.Items.Add(ProtocolBuffers.WriteValue("bill", typeof(string))); var mock = new Mock <ITestService> (MockBehavior.Strict); mock.Setup(x => x.EchoList(It.IsAny <IList <string> > ())) .Returns((IList <string> x) => x); TestService.Service = mock.Object; var response = Run(Req("TestService", "EchoList", Arg(0, ProtocolBuffers.WriteMessage(list)))); response.Time = 0; Assert.AreEqual("", response.Error); Assert.AreEqual(ProtocolBuffers.WriteMessage(list), response.ReturnValue); mock.Verify(x => x.EchoList(It.IsAny <IList <string> > ()), Times.Once()); }
public void HandleEchoNestedCollection() { var list0 = new KRPC.Schema.KRPC.List(); list0.Items.Add(ProtocolBuffers.WriteValue("jeb", typeof(string))); list0.Items.Add(ProtocolBuffers.WriteValue("bob", typeof(string))); var list1 = new KRPC.Schema.KRPC.List(); var list2 = new KRPC.Schema.KRPC.List(); list2.Items.Add(ProtocolBuffers.WriteValue("bill", typeof(string))); list2.Items.Add(ProtocolBuffers.WriteValue("edzor", typeof(string))); var collection = new Dictionary(); collection.Entries.Add(new DictionaryEntry { Key = ProtocolBuffers.WriteValue(0, typeof(int)), Value = ProtocolBuffers.WriteMessage(list0) }); collection.Entries.Add(new DictionaryEntry { Key = ProtocolBuffers.WriteValue(1, typeof(int)), Value = ProtocolBuffers.WriteMessage(list1) }); collection.Entries.Add(new DictionaryEntry { Key = ProtocolBuffers.WriteValue(2, typeof(int)), Value = ProtocolBuffers.WriteMessage(list2) }); var mock = new Mock <ITestService> (MockBehavior.Strict); mock.Setup(x => x.EchoNestedCollection(It.IsAny <IDictionary <int, IList <string> > > ())) .Returns((IDictionary <int, IList <string> > x) => x); TestService.Service = mock.Object; var response = Run(Req("TestService", "EchoNestedCollection", Arg(0, ProtocolBuffers.WriteMessage(collection)))); response.Time = 0; Assert.AreEqual("", response.Error); Assert.AreEqual(ProtocolBuffers.WriteMessage(collection), response.ReturnValue); mock.Verify(x => x.EchoNestedCollection(It.IsAny <IDictionary <int, IList <string> > > ()), Times.Once()); }
public void HandleEchoListOfObjects() { var instance0 = new TestService.TestClass("foo"); var instance1 = new TestService.TestClass("bar"); var guid0 = ObjectStore.Instance.AddInstance(instance0); var guid1 = ObjectStore.Instance.AddInstance(instance1); var list = new KRPC.Schema.KRPC.List(); list.Items.Add(ProtocolBuffers.WriteValue(guid0, typeof(ulong))); list.Items.Add(ProtocolBuffers.WriteValue(guid1, typeof(ulong))); var mock = new Mock <ITestService> (MockBehavior.Strict); mock.Setup(x => x.EchoListOfObjects(It.IsAny <IList <TestService.TestClass> > ())) .Returns((IList <TestService.TestClass> x) => x); TestService.Service = mock.Object; var response = Run(Req("TestService", "EchoListOfObjects", Arg(0, ProtocolBuffers.WriteMessage(list)))); response.Time = 0; Assert.AreEqual("", response.Error); Assert.AreEqual(ProtocolBuffers.WriteMessage(list), response.ReturnValue); mock.Verify(x => x.EchoListOfObjects(It.IsAny <IList <TestService.TestClass> > ()), Times.Once()); }