Пример #1
0
        public void GetServices()
        {
            var services = KRPC.Service.KRPC.GetServices();

            Assert.IsNotNull(services);
            Assert.AreEqual(4, services.ServicesList.Count);

            var service = services.ServicesList.First(x => x.Name == "KRPC");

            Assert.AreEqual(6, service.Procedures.Count);
            Assert.AreEqual(0, service.Classes.Count);
            Assert.AreEqual(1, service.Enumerations.Count);

            int foundProcedures = 0;

            foreach (var method in service.Procedures)
            {
                if (method.Name == "GetStatus")
                {
                    MessageAssert.HasReturnType(method, "KRPC.Status");
                    MessageAssert.HasNoParameters(method);
                    MessageAssert.HasNoAttributes(method);
                    MessageAssert.HasDocumentation(method);
                }
                else if (method.Name == "GetServices")
                {
                    MessageAssert.HasReturnType(method, "KRPC.Services");
                    MessageAssert.HasNoParameters(method);
                    MessageAssert.HasNoAttributes(method);
                    MessageAssert.HasDocumentation(method);
                }
                else if (method.Name == "AddStream")
                {
                    MessageAssert.HasReturnType(method, "uint32");
                    MessageAssert.HasParameters(method, 1);
                    MessageAssert.HasParameter(method, 0, "KRPC.Request", "request");
                    MessageAssert.HasNoAttributes(method);
                    MessageAssert.HasDocumentation(method);
                }
                else if (method.Name == "RemoveStream")
                {
                    MessageAssert.HasNoReturnType(method);
                    MessageAssert.HasParameters(method, 1);
                    MessageAssert.HasParameter(method, 0, "uint32", "id");
                    MessageAssert.HasNoAttributes(method);
                    MessageAssert.HasDocumentation(method);
                }
                else if (method.Name == "get_Clients")
                {
                    MessageAssert.HasReturnType(method, "KRPC.List");
                    MessageAssert.HasNoParameters(method);
                    MessageAssert.HasAttributes(method, 2);
                    MessageAssert.HasAttribute(method, 0, "Property.Get(Clients)");
                    MessageAssert.HasAttribute(method, 1, "ReturnType.List(Tuple(bytes,string,string))");
                    MessageAssert.HasDocumentation(method);
                }
                else if (method.Name == "get_CurrentGameScene")
                {
                    MessageAssert.HasReturnType(method, "int32");
                    MessageAssert.HasNoParameters(method);
                    MessageAssert.HasAttributes(method, 2);
                    MessageAssert.HasAttribute(method, 0, "Property.Get(CurrentGameScene)");
                    MessageAssert.HasAttribute(method, 1, "ReturnType.Enum(KRPC.GameScene)");
                    MessageAssert.HasDocumentation(method);
                }
                else
                {
                    Assert.Fail();
                }
                foundProcedures++;
            }
            Assert.AreEqual(6, foundProcedures);

            bool foundEnumeration = false;

            foreach (var enumeration in service.Enumerations)
            {
                if (enumeration.Name == "GameScene")
                {
                    foundEnumeration = true;
                    MessageAssert.HasDocumentation(enumeration,
                                                   "<doc>\n<summary>\nThe game scene. See <see cref=\"M:KRPC.CurrentGameScene\" />.\n</summary>\n</doc>");
                    MessageAssert.HasValues(enumeration, 5);
                    MessageAssert.HasValue(enumeration, 0, "SpaceCenter", 0,
                                           "<doc>\n<summary>\nThe game scene showing the Kerbal Space Center buildings.\n</summary>\n</doc>");
                    MessageAssert.HasValue(enumeration, 1, "Flight", 1,
                                           "<doc>\n<summary>\nThe game scene showing a vessel in flight (or on the launchpad/runway).\n</summary>\n</doc>");
                    MessageAssert.HasValue(enumeration, 2, "TrackingStation", 2,
                                           "<doc>\n<summary>\nThe tracking station.\n</summary>\n</doc>");
                    MessageAssert.HasValue(enumeration, 3, "EditorVAB", 3,
                                           "<doc>\n<summary>\nThe Vehicle Assembly Building.\n</summary>\n</doc>");
                    MessageAssert.HasValue(enumeration, 4, "EditorSPH", 4,
                                           "<doc>\n<summary>\nThe Space Plane Hangar.\n</summary>\n</doc>");
                }
            }
            Assert.IsTrue(foundEnumeration);
        }
Пример #2
0
        public void TestServiceProcedures()
        {
            var service         = services.ServicesList.First(x => x.Name == "TestService");
            int foundProcedures = 0;

            foreach (var proc in service.Procedures)
            {
                if (proc.Name == "ProcedureNoArgsNoReturn")
                {
                    MessageAssert.HasNoParameters(proc);
                    MessageAssert.HasNoReturnType(proc);
                    MessageAssert.HasNoAttributes(proc);
                    MessageAssert.HasDocumentation(proc, "<doc>\n  <summary>\nProcedure with no return arguments.\n</summary>\n</doc>");
                }
                else if (proc.Name == "ProcedureSingleArgNoReturn")
                {
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameter(proc, 0, "KRPC.Response", "data");
                    MessageAssert.HasNoReturnType(proc);
                    MessageAssert.HasNoAttributes(proc);
                    MessageAssert.HasDocumentation(proc, "<doc>\n  <summary>\nProcedure with a single return argument.\n</summary>\n</doc>");
                }
                else if (proc.Name == "ProcedureThreeArgsNoReturn")
                {
                    MessageAssert.HasParameters(proc, 3);
                    MessageAssert.HasParameter(proc, 0, "KRPC.Response", "x");
                    MessageAssert.HasParameter(proc, 1, "KRPC.Request", "y");
                    MessageAssert.HasParameter(proc, 2, "KRPC.Response", "z");
                    MessageAssert.HasNoReturnType(proc);
                    MessageAssert.HasNoAttributes(proc);
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "ProcedureNoArgsReturns")
                {
                    MessageAssert.HasNoParameters(proc);
                    MessageAssert.HasReturnType(proc, "KRPC.Response");
                    MessageAssert.HasNoAttributes(proc);
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "ProcedureSingleArgReturns")
                {
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameter(proc, 0, "KRPC.Response", "data");
                    MessageAssert.HasReturnType(proc, "KRPC.Response");
                    MessageAssert.HasNoAttributes(proc);
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "ProcedureWithValueTypes")
                {
                    MessageAssert.HasParameters(proc, 3);
                    MessageAssert.HasParameter(proc, 0, "float", "x");
                    MessageAssert.HasParameter(proc, 1, "string", "y");
                    MessageAssert.HasParameter(proc, 2, "bytes", "z");
                    MessageAssert.HasReturnType(proc, "int32");
                    MessageAssert.HasNoAttributes(proc);
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "get_PropertyWithGetAndSet")
                {
                    MessageAssert.HasNoParameters(proc);
                    MessageAssert.HasReturnType(proc, "string");
                    MessageAssert.HasAttributes(proc, 1);
                    MessageAssert.HasAttribute(proc, 0, "Property.Get(PropertyWithGetAndSet)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "set_PropertyWithGetAndSet")
                {
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameter(proc, 0, "string", "value");
                    MessageAssert.HasNoReturnType(proc);
                    MessageAssert.HasAttributes(proc, 1);
                    MessageAssert.HasAttribute(proc, 0, "Property.Set(PropertyWithGetAndSet)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "get_PropertyWithGet")
                {
                    MessageAssert.HasNoParameters(proc);
                    MessageAssert.HasReturnType(proc, "string");
                    MessageAssert.HasAttributes(proc, 1);
                    MessageAssert.HasAttribute(proc, 0, "Property.Get(PropertyWithGet)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "set_PropertyWithSet")
                {
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameter(proc, 0, "string", "value");
                    MessageAssert.HasNoReturnType(proc);
                    MessageAssert.HasAttributes(proc, 1);
                    MessageAssert.HasAttribute(proc, 0, "Property.Set(PropertyWithSet)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "CreateTestObject")
                {
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameter(proc, 0, "string", "value");
                    MessageAssert.HasReturnType(proc, "uint64");
                    MessageAssert.HasAttributes(proc, 1);
                    MessageAssert.HasAttribute(proc, 0, "ReturnType.Class(TestService.TestClass)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "DeleteTestObject")
                {
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameter(proc, 0, "uint64", "obj");
                    MessageAssert.HasNoReturnType(proc);
                    MessageAssert.HasAttributes(proc, 1);
                    MessageAssert.HasAttribute(proc, 0, "ParameterType(0).Class(TestService.TestClass)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "EchoTestObject")
                {
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameter(proc, 0, "uint64", "obj");
                    MessageAssert.HasReturnType(proc, "uint64");
                    MessageAssert.HasAttributes(proc, 2);
                    MessageAssert.HasAttribute(proc, 0, "ParameterType(0).Class(TestService.TestClass)");
                    MessageAssert.HasAttribute(proc, 1, "ReturnType.Class(TestService.TestClass)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "TestClass_FloatToString")
                {
                    MessageAssert.HasParameters(proc, 2);
                    MessageAssert.HasParameter(proc, 0, "uint64", "this");
                    MessageAssert.HasParameter(proc, 1, "float", "x");
                    MessageAssert.HasReturnType(proc, "string");
                    MessageAssert.HasAttributes(proc, 2);
                    MessageAssert.HasAttribute(proc, 0, "Class.Method(TestService.TestClass,FloatToString)");
                    MessageAssert.HasAttribute(proc, 1, "ParameterType(0).Class(TestService.TestClass)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "TestClass_ObjectToString")
                {
                    MessageAssert.HasParameters(proc, 2);
                    MessageAssert.HasParameter(proc, 0, "uint64", "this");
                    MessageAssert.HasParameter(proc, 1, "uint64", "other");
                    MessageAssert.HasReturnType(proc, "string");
                    MessageAssert.HasAttributes(proc, 3);
                    MessageAssert.HasAttribute(proc, 0, "Class.Method(TestService.TestClass,ObjectToString)");
                    MessageAssert.HasAttribute(proc, 1, "ParameterType(0).Class(TestService.TestClass)");
                    MessageAssert.HasAttribute(proc, 2, "ParameterType(1).Class(TestService.TestClass)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "TestClass_IntToString")
                {
                    MessageAssert.HasParameters(proc, 2);
                    MessageAssert.HasParameter(proc, 0, "uint64", "this");
                    MessageAssert.HasParameterWithDefaultValue(proc, 1, "int32", "x", 42);
                    MessageAssert.HasReturnType(proc, "string");
                    MessageAssert.HasAttributes(proc, 2);
                    MessageAssert.HasAttribute(proc, 0, "Class.Method(TestService.TestClass,IntToString)");
                    MessageAssert.HasAttribute(proc, 1, "ParameterType(0).Class(TestService.TestClass)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "TestClass_get_IntProperty")
                {
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameter(proc, 0, "uint64", "this");
                    MessageAssert.HasReturnType(proc, "int32");
                    MessageAssert.HasAttributes(proc, 2);
                    MessageAssert.HasAttribute(proc, 0, "Class.Property.Get(TestService.TestClass,IntProperty)");
                    MessageAssert.HasAttribute(proc, 1, "ParameterType(0).Class(TestService.TestClass)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "TestClass_set_IntProperty")
                {
                    MessageAssert.HasParameters(proc, 2);
                    MessageAssert.HasParameter(proc, 0, "uint64", "this");
                    MessageAssert.HasParameter(proc, 1, "int32", "value");
                    MessageAssert.HasNoReturnType(proc);
                    MessageAssert.HasAttributes(proc, 2);
                    MessageAssert.HasAttribute(proc, 0, "Class.Property.Set(TestService.TestClass,IntProperty)");
                    MessageAssert.HasAttribute(proc, 1, "ParameterType(0).Class(TestService.TestClass)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "TestClass_get_ObjectProperty")
                {
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameter(proc, 0, "uint64", "this");
                    MessageAssert.HasReturnType(proc, "uint64");
                    MessageAssert.HasAttributes(proc, 3);
                    MessageAssert.HasAttribute(proc, 0, "Class.Property.Get(TestService.TestClass,ObjectProperty)");
                    MessageAssert.HasAttribute(proc, 1, "ParameterType(0).Class(TestService.TestClass)");
                    MessageAssert.HasAttribute(proc, 2, "ReturnType.Class(TestService.TestClass)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "TestClass_set_ObjectProperty")
                {
                    MessageAssert.HasParameters(proc, 2);
                    MessageAssert.HasParameter(proc, 0, "uint64", "this");
                    MessageAssert.HasParameter(proc, 1, "uint64", "value");
                    MessageAssert.HasNoReturnType(proc);
                    MessageAssert.HasAttributes(proc, 3);
                    MessageAssert.HasAttribute(proc, 0, "Class.Property.Set(TestService.TestClass,ObjectProperty)");
                    MessageAssert.HasAttribute(proc, 1, "ParameterType(0).Class(TestService.TestClass)");
                    MessageAssert.HasAttribute(proc, 2, "ParameterType(1).Class(TestService.TestClass)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "TestClass_StaticMethod")
                {
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameterWithDefaultValue(proc, 0, "string", "a", String.Empty);
                    MessageAssert.HasReturnType(proc, "string");
                    MessageAssert.HasAttributes(proc, 1);
                    MessageAssert.HasAttribute(proc, 0, "Class.StaticMethod(TestService.TestClass,StaticMethod)");
                }
                else if (proc.Name == "TestTopLevelClass_AMethod")
                {
                    MessageAssert.HasParameters(proc, 2);
                    MessageAssert.HasParameter(proc, 0, "uint64", "this");
                    MessageAssert.HasParameter(proc, 1, "int32", "x");
                    MessageAssert.HasReturnType(proc, "string");
                    MessageAssert.HasAttributes(proc, 2);
                    MessageAssert.HasAttribute(proc, 0, "Class.Method(TestService.TestTopLevelClass,AMethod)");
                    MessageAssert.HasAttribute(proc, 1, "ParameterType(0).Class(TestService.TestTopLevelClass)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "TestTopLevelClass_get_AProperty")
                {
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameter(proc, 0, "uint64", "this");
                    MessageAssert.HasReturnType(proc, "string");
                    MessageAssert.HasAttributes(proc, 2);
                    MessageAssert.HasAttribute(proc, 0, "Class.Property.Get(TestService.TestTopLevelClass,AProperty)");
                    MessageAssert.HasAttribute(proc, 1, "ParameterType(0).Class(TestService.TestTopLevelClass)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "TestTopLevelClass_set_AProperty")
                {
                    MessageAssert.HasParameters(proc, 2);
                    MessageAssert.HasParameter(proc, 0, "uint64", "this");
                    MessageAssert.HasParameter(proc, 1, "string", "value");
                    MessageAssert.HasNoReturnType(proc);
                    MessageAssert.HasAttributes(proc, 2);
                    MessageAssert.HasAttribute(proc, 0, "Class.Property.Set(TestService.TestTopLevelClass,AProperty)");
                    MessageAssert.HasAttribute(proc, 1, "ParameterType(0).Class(TestService.TestTopLevelClass)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "ProcedureSingleOptionalArgNoReturn")
                {
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameterWithDefaultValue(proc, 0, "string", "x", "foo");
                    MessageAssert.HasNoReturnType(proc);
                    MessageAssert.HasNoAttributes(proc);
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "ProcedureThreeOptionalArgsNoReturn")
                {
                    MessageAssert.HasParameters(proc, 3);
                    MessageAssert.HasParameter(proc, 0, "float", "x");
                    MessageAssert.HasParameterWithDefaultValue(proc, 1, "string", "y", "jeb");
                    MessageAssert.HasParameterWithDefaultValue(proc, 2, "int32", "z", 42);
                    MessageAssert.HasNoReturnType(proc);
                    MessageAssert.HasNoAttributes(proc);
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "ProcedureOptionalNullArg")
                {
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameterWithDefaultValue(proc, 0, "uint64", "x", null);
                    MessageAssert.HasNoReturnType(proc);
                    MessageAssert.HasAttributes(proc, 1);
                    MessageAssert.HasAttribute(proc, 0, "ParameterType(0).Class(TestService.TestClass)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "ProcedureEnumArg")
                {
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameter(proc, 0, "int32", "x");
                    MessageAssert.HasNoReturnType(proc);
                    MessageAssert.HasAttributes(proc, 1);
                    MessageAssert.HasAttribute(proc, 0, "ParameterType(0).Enum(TestService.TestEnum)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "ProcedureEnumReturn")
                {
                    MessageAssert.HasNoParameters(proc);
                    MessageAssert.HasReturnType(proc, "int32");
                    MessageAssert.HasAttributes(proc, 1);
                    MessageAssert.HasAttribute(proc, 0, "ReturnType.Enum(TestService.TestEnum)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "BlockingProcedureNoReturn")
                {
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameter(proc, 0, "int32", "n");
                    MessageAssert.HasNoReturnType(proc);
                    MessageAssert.HasNoAttributes(proc);
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "BlockingProcedureReturns")
                {
                    MessageAssert.HasParameters(proc, 2);
                    MessageAssert.HasParameter(proc, 0, "int32", "n");
                    MessageAssert.HasParameterWithDefaultValue(proc, 1, "int32", "sum", 0);
                    MessageAssert.HasReturnType(proc, "int32");
                    MessageAssert.HasNoAttributes(proc);
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "EchoList")
                {
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameter(proc, 0, "KRPC.List", "l");
                    MessageAssert.HasReturnType(proc, "KRPC.List");
                    MessageAssert.HasAttributes(proc, 2);
                    MessageAssert.HasAttribute(proc, 0, "ParameterType(0).List(string)");
                    MessageAssert.HasAttribute(proc, 1, "ReturnType.List(string)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "EchoDictionary")
                {
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameter(proc, 0, "KRPC.Dictionary", "d");
                    MessageAssert.HasReturnType(proc, "KRPC.Dictionary");
                    MessageAssert.HasAttributes(proc, 2);
                    MessageAssert.HasAttribute(proc, 0, "ParameterType(0).Dictionary(int32,string)");
                    MessageAssert.HasAttribute(proc, 1, "ReturnType.Dictionary(int32,string)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "EchoSet")
                {
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameter(proc, 0, "KRPC.Set", "h");
                    MessageAssert.HasReturnType(proc, "KRPC.Set");
                    MessageAssert.HasAttributes(proc, 2);
                    MessageAssert.HasAttribute(proc, 0, "ParameterType(0).Set(int32)");
                    MessageAssert.HasAttribute(proc, 1, "ReturnType.Set(int32)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "EchoTuple")
                {
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameter(proc, 0, "KRPC.Tuple", "t");
                    MessageAssert.HasReturnType(proc, "KRPC.Tuple");
                    MessageAssert.HasAttributes(proc, 2);
                    MessageAssert.HasAttribute(proc, 0, "ParameterType(0).Tuple(int32,bool)");
                    MessageAssert.HasAttribute(proc, 1, "ReturnType.Tuple(int32,bool)");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "EchoNestedCollection")
                {
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameter(proc, 0, "KRPC.Dictionary", "c");
                    MessageAssert.HasReturnType(proc, "KRPC.Dictionary");
                    MessageAssert.HasAttributes(proc, 2);
                    MessageAssert.HasAttribute(proc, 0, "ParameterType(0).Dictionary(int32,List(string))");
                    MessageAssert.HasAttribute(proc, 1, "ReturnType.Dictionary(int32,List(string))");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else if (proc.Name == "EchoListOfObjects")
                {
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameter(proc, 0, "KRPC.List", "l");
                    MessageAssert.HasReturnType(proc, "KRPC.List");
                    MessageAssert.HasAttributes(proc, 2);
                    MessageAssert.HasAttribute(proc, 0, "ParameterType(0).List(Class(TestService.TestClass))");
                    MessageAssert.HasAttribute(proc, 1, "ReturnType.List(Class(TestService.TestClass))");
                    MessageAssert.HasNoDocumentation(proc);
                }
                else
                {
                    Assert.Fail();
                }
                foundProcedures++;
            }
            Assert.AreEqual(37, foundProcedures);
            Assert.AreEqual(37, service.Procedures.Count);
        }