public void SimpleUsage() { var instance = new TestService.TestClass ("foo"); var object_id = ObjectStore.Instance.AddInstance (instance); var handler = new ClassMethodHandler (typeof(TestService.TestClass).GetMethod ("FloatToString")); Assert.AreEqual ("foo3.14159", handler.Invoke (new object[] { object_id, 3.14159f })); }
public void EncodeClass () { var obj = new TestService.TestClass ("foo"); var data = Encoder.Encode (obj); var expected = new [] { (byte)ObjectStore.Instance.AddInstance (obj) }.ToHexString (); Assert.AreEqual (expected, data.ToHexString ()); }
public void DefaultArguments() { var instance = new TestService.TestClass ("foo"); var object_id = ObjectStore.Instance.AddInstance (instance); var handler = new ClassMethodHandler (typeof(TestService.TestClass).GetMethod ("IntToString")); Assert.AreEqual ("foo42", handler.Invoke (new object[] { object_id, Type.Missing })); }
public void DefaultArguments() { var instance = new TestService.TestClass("foo"); var object_id = ObjectStore.Instance.AddInstance(instance); var handler = new ClassMethodHandler(typeof(TestService.TestClass).GetMethod("IntToString")); Assert.AreEqual("foo42", handler.Invoke(new object[] { object_id, Type.Missing })); }
public void SimpleUsage() { var instance = new TestService.TestClass("foo"); var object_id = ObjectStore.Instance.AddInstance(instance); var handler = new ClassMethodHandler(typeof(TestService.TestClass).GetMethod("FloatToString")); Assert.AreEqual("foo3.14159", handler.Invoke(new object[] { object_id, 3.14159f })); }
public void SimpleUsage() { var instance = new TestService.TestClass("foo"); var classType = typeof(TestService.TestClass); var handler = new ClassMethodHandler(classType, classType.GetMethod("FloatToString"), false); Assert.AreEqual("foo3.14159", handler.Invoke(new object[] { instance, 3.14159f })); }
public void DefaultArguments() { var instance = new TestService.TestClass("foo"); var classType = typeof(TestService.TestClass); var handler = new ClassMethodHandler(classType, classType.GetMethod("IntToString"), false); Assert.AreEqual("foo42", handler.Invoke(new object[] { instance, Type.Missing })); }
public void ExecuteCallForObjectMethod() { var instance = new TestService.TestClass("jeb"); const float arg = 3.14159f; var result = Run(Call("TestService", "TestClass_FloatToString", Arg(0, instance), Arg(1, arg))); CheckResultNotEmpty(result); Assert.AreEqual("jeb3.14159", (string)result.Value); }
public void ExecuteCallForObjectMethodWithObjectParameter() { var instance = new TestService.TestClass("bill"); var arg = new TestService.TestClass("bob"); var result = Run(Call("TestService", "TestClass_ObjectToString", Arg(0, instance), Arg(1, arg))); CheckResultNotEmpty(result); Assert.AreEqual("billbob", (string)result.Value); }
public void ExecuteCallForClassPropertyGetter() { var instance = new TestService.TestClass("jeb"); instance.IntProperty = 42; var result = Run(Call("TestService", "TestClass_get_IntProperty", Arg(0, instance))); CheckResultNotEmpty(result); Assert.AreEqual(42, (int)result.Value); }
public void ExecuteCallForClassPropertySetter() { var instance = new TestService.TestClass("jeb"); instance.IntProperty = 42; var result = Run(Call("TestService", "TestClass_set_IntProperty", Arg(0, instance), Arg(1, 1337))); CheckResultEmpty(result); Assert.AreEqual(1337, instance.IntProperty); }
public void ExecuteCallWithClassTypeParameterFromDifferentService() { var instance = new TestService.TestClass("jeb"); instance.IntProperty = 42; ObjectStore.Instance.AddInstance(instance); var result = Run(Call("TestService2", "ClassTypeFromOtherServiceAsParameter", Arg(0, instance))); CheckResultNotEmpty(result); Assert.AreEqual(42, (int)result.Value); }
public void HandleRequestForObjectMethodWithObjectParameter() { var instance = new TestService.TestClass("bill"); var arg = new TestService.TestClass("bob"); var guid = ObjectStore.Instance.AddInstance(instance); var request = Req("TestService", "TestClass_ObjectToString", Arg(0, guid), Arg(1, arg)); var response = Run(request); response.Time = 42; Assert.AreEqual("billbob", (string)(response.ReturnValue)); }
public void HandleRequestForObjectMethod() { var instance = new TestService.TestClass("jeb"); var guid = ObjectStore.Instance.AddInstance(instance); const float arg = 3.14159f; var request = Req("TestService", "TestClass_FloatToString", Arg(0, guid), Arg(1, arg)); var response = Run(request); response.Time = 42; Assert.AreEqual("jeb3.14159", (string)response.ReturnValue); }
public void HandleRequestForObjectMethod() { var instance = new TestService.TestClass("jeb"); var guid = ObjectStore.Instance.AddInstance(instance); ByteString guidBytes = ProtocolBuffers.WriteValue(guid, typeof(ulong)); ByteString argBytes = ProtocolBuffers.WriteValue(3.14159f, typeof(float)); var request = Req("TestService", "TestClass_FloatToString", Arg(0, guidBytes), Arg(1, argBytes)); var response = Run(request); response.Time = 42; Assert.AreEqual("jeb3.14159", ProtocolBuffers.ReadValue(response.ReturnValue, typeof(string))); }
public void ClassMethodGameModeSpecifiedInAttribute() { var instance = new TestService.TestClass("jeb"); CallContext.SetGameScene(GameScene.Flight); CheckError(String.Empty, "Procedure not available in game scene 'Flight'", Run(Call("TestService", "TestClass_MethodAvailableInSpecifiedGameScene", Arg(0, instance)))); CallContext.SetGameScene(GameScene.EditorVAB); var result = Run(Call("TestService", "TestClass_MethodAvailableInSpecifiedGameScene", Arg(0, instance))); CheckResultNotEmpty(result); Assert.AreEqual("foo", result.Value); }
public void HandleRequestWithObjectParameter() { var instance = new TestService.TestClass("foo"); ObjectStore.Instance.AddInstance(instance); var mock = new Mock <ITestService> (MockBehavior.Strict); mock.Setup(x => x.DeleteTestObject(It.IsAny <TestService.TestClass> ())) .Callback((TestService.TestClass x) => Assert.AreSame(instance, x)); TestService.Service = mock.Object; Run(Req("TestService", "DeleteTestObject", Arg(0, instance))); mock.Verify(x => x.DeleteTestObject(It.IsAny <TestService.TestClass> ()), Times.Once()); }
public void HandleRequestForClassPropertyGetter() { var instance = new TestService.TestClass("jeb"); instance.IntProperty = 42; var guid = ObjectStore.Instance.AddInstance(instance); var request = Req("TestService", "TestClass_get_IntProperty", Arg(0, guid)); var response = Run(request); response.Time = 0; Assert.AreEqual(string.Empty, response.Error); Assert.AreEqual(42, (int)response.ReturnValue); }
public void HandleRequestWithObjectParameter() { var instance = new TestService.TestClass("foo"); var arg = ObjectStore.Instance.AddInstance(instance); ByteString argBytes = ProtocolBuffers.WriteValue(arg, typeof(ulong)); var mock = new Mock <ITestService> (MockBehavior.Strict); mock.Setup(x => x.DeleteTestObject(It.IsAny <TestService.TestClass> ())) .Callback((TestService.TestClass x) => Assert.AreSame(instance, x)); TestService.Service = mock.Object; Run(Req("TestService", "DeleteTestObject", Arg(0, argBytes))); mock.Verify(x => x.DeleteTestObject(It.IsAny <TestService.TestClass> ()), Times.Once()); }
public void HandleRequestWithClassTypeParameterFromDifferentService() { var instance = new TestService.TestClass("jeb"); instance.IntProperty = 42; ObjectStore.Instance.AddInstance(instance); var request = Req("TestService2", "ClassTypeFromOtherServiceAsParameter", Arg(0, instance)); var response = Run(request); response.Time = 0; Assert.AreEqual(string.Empty, response.Error); Assert.AreEqual(42, (int)response.ReturnValue); }
public void ClassMethodGameModeInheritedFromService() { var instance = new TestService.TestClass("jeb"); CallContext.SetGameScene(GameScene.TrackingStation); CheckError(String.Empty, "Procedure not available in game scene 'TrackingStation'", Run(Call("TestService", "TestClass_MethodAvailableInInheritedGameScene", Arg(0, instance)))); CallContext.SetGameScene(GameScene.Flight); var result = Run(Call("TestService", "TestClass_MethodAvailableInInheritedGameScene", Arg(0, instance))); CheckResultNotEmpty(result); Assert.AreEqual("foo", result.Value); }
public void HandleRequestWithObjectReturn() { var instance = new TestService.TestClass("foo"); var mock = new Mock <ITestService> (MockBehavior.Strict); mock.Setup(x => x.CreateTestObject("foo")).Returns(instance); TestService.Service = mock.Object; Response response = Run(Req("TestService", "CreateTestObject", Arg(0, "foo"))); Assert.AreEqual(string.Empty, response.Error); response.Time = 42; Assert.IsNotNull(response.ReturnValue); Assert.AreEqual(instance, (TestService.TestClass)response.ReturnValue); }
public void HandleRequestForObjectMethodWithObjectParameter() { var instance = new TestService.TestClass("bill"); var argInstance = new TestService.TestClass("bob"); var guid = ObjectStore.Instance.AddInstance(instance); var argGuid = ObjectStore.Instance.AddInstance(argInstance); ByteString guidBytes = ProtocolBuffers.WriteValue(guid, typeof(ulong)); ByteString argBytes = ProtocolBuffers.WriteValue(argGuid, typeof(ulong)); var request = Req("TestService", "TestClass_ObjectToString", Arg(0, guidBytes), Arg(1, argBytes)); var response = Run(request); response.Time = 42; Assert.AreEqual("billbob", ProtocolBuffers.ReadValue(response.ReturnValue, typeof(string))); }
public void ExecuteCallWithObjectReturn() { var instance = new TestService.TestClass("foo"); var mock = new Mock <ITestService> (MockBehavior.Strict); mock.Setup(x => x.CreateTestObject("foo")).Returns(instance); TestService.Service = mock.Object; var result = Run(Call("TestService", "CreateTestObject", Arg(0, "foo"))); mock.Verify(x => x.CreateTestObject(It.IsAny <string> ()), Times.Once()); CheckResultNotEmpty(result); Assert.IsNotNull(result.Value); Assert.AreEqual(instance, (TestService.TestClass)result.Value); }
public void HandleRequestForClassPropertyGetter() { var instance = new TestService.TestClass("jeb"); instance.IntProperty = 42; var guid = ObjectStore.Instance.AddInstance(instance); ByteString guidBytes = ProtocolBuffers.WriteValue(guid, typeof(ulong)); var request = Req("TestService", "TestClass_get_IntProperty", Arg(0, guidBytes)); var response = Run(request); response.Time = 0; Assert.AreEqual("", response.Error); Assert.AreEqual(42, ProtocolBuffers.ReadValue(response.ReturnValue, typeof(int))); }
public void HandleRequestWithClassTypeParameterFromDifferentService() { var instance = new TestService.TestClass("jeb"); instance.IntProperty = 42; var guid = ObjectStore.Instance.AddInstance(instance); ByteString guidBytes = ProtocolBuffers.WriteValue(guid, typeof(ulong)); var request = Req("TestService2", "ClassTypeFromOtherServiceAsParameter", Arg(0, guidBytes)); var response = Run(request); response.Time = 0; Assert.AreEqual("", response.Error); Assert.AreEqual(42, ProtocolBuffers.ReadValue(response.ReturnValue, typeof(long))); }
public void HandleRequestForClassPropertySetter() { var instance = new TestService.TestClass("jeb"); instance.IntProperty = 42; var guid = ObjectStore.Instance.AddInstance(instance); var request = Req("TestService", "TestClass_set_IntProperty", Arg(0, guid), Arg(1, 1337)); var response = Run(request); response.Time = 0; Assert.AreEqual(String.Empty, response.Error); Assert.AreEqual(1337, instance.IntProperty); }
public void HandleRequestWithObjectReturn() { var instance = new TestService.TestClass("foo"); var guid = ObjectStore.Instance.AddInstance(instance); var argBytes = ProtocolBuffers.WriteValue("foo", typeof(string)); var mock = new Mock <ITestService> (MockBehavior.Strict); mock.Setup(x => x.CreateTestObject("foo")).Returns(instance); TestService.Service = mock.Object; Response response = Run(Req("TestService", "CreateTestObject", Arg(0, argBytes))); Assert.AreEqual("", response.Error); response.Time = 42; Assert.IsNotNull(response.ReturnValue); Assert.AreEqual(guid, ProtocolBuffers.ReadValue(response.ReturnValue, typeof(ulong))); }
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()); }
public void HandleRequestForObjectMethodWithObjectParameter () { var instance = new TestService.TestClass ("bill"); var arg = new TestService.TestClass ("bob"); var guid = ObjectStore.Instance.AddInstance (instance); var request = Req ("TestService", "TestClass_ObjectToString", Arg (0, guid), Arg (1, arg)); var response = Run (request); response.Time = 42; Assert.AreEqual ("billbob", (string)(response.ReturnValue)); }
public static int ClassTypeFromOtherServiceAsParameter(TestService.TestClass obj) { return(obj.IntProperty); }
public void DecodeClass () { var obj = new TestService.TestClass ("foo"); var id = ObjectStore.Instance.AddInstance (obj); var value = Encoder.Decode (new [] { (byte)id }.ToHexString ().ToByteString (), typeof(TestService.TestClass)); Assert.AreEqual (obj, value); }
public void HandleRequestWithObjectReturn () { var instance = new TestService.TestClass ("foo"); var mock = new Mock<ITestService> (MockBehavior.Strict); mock.Setup (x => x.CreateTestObject ("foo")).Returns (instance); TestService.Service = mock.Object; Response response = Run (Req ("TestService", "CreateTestObject", Arg (0, "foo"))); Assert.AreEqual (String.Empty, response.Error); response.Time = 42; Assert.IsNotNull (response.ReturnValue); Assert.AreEqual (instance, (TestService.TestClass)response.ReturnValue); }
public void HandleRequestWithObjectParameter () { var instance = new TestService.TestClass ("foo"); ObjectStore.Instance.AddInstance (instance); var mock = new Mock<ITestService> (MockBehavior.Strict); mock.Setup (x => x.DeleteTestObject (It.IsAny<TestService.TestClass> ())) .Callback ((TestService.TestClass x) => Assert.AreSame (instance, x)); TestService.Service = mock.Object; Run (Req ("TestService", "DeleteTestObject", Arg (0, instance))); mock.Verify (x => x.DeleteTestObject (It.IsAny<TestService.TestClass> ()), Times.Once ()); }
public void HandleRequestForObjectMethod () { var instance = new TestService.TestClass ("jeb"); var guid = ObjectStore.Instance.AddInstance (instance); const float arg = 3.14159f; var request = Req ("TestService", "TestClass_FloatToString", Arg (0, guid), Arg (1, arg)); var response = Run (request); response.Time = 42; Assert.AreEqual ("jeb3.14159", (string)response.ReturnValue); }
public void HandleRequestForClassPropertySetter () { var instance = new TestService.TestClass ("jeb"); instance.IntProperty = 42; var guid = ObjectStore.Instance.AddInstance (instance); var request = Req ("TestService", "TestClass_set_IntProperty", Arg (0, guid), Arg (1, 1337)); var response = Run (request); response.Time = 0; Assert.AreEqual (String.Empty, response.Error); Assert.AreEqual (1337, instance.IntProperty); }
public void HandleRequestWithClassTypeParameterFromDifferentService () { var instance = new TestService.TestClass ("jeb"); instance.IntProperty = 42; ObjectStore.Instance.AddInstance (instance); var request = Req ("TestService2", "ClassTypeFromOtherServiceAsParameter", Arg (0, instance)); var response = Run (request); response.Time = 0; Assert.AreEqual (String.Empty, response.Error); Assert.AreEqual (42, (int)response.ReturnValue); }