示例#1
0
        public void TestServiceEnumerations()
        {
            var service           = services.ServicesList.First(x => x.Name == "TestService");
            int foundEnumerations = 0;

            foreach (var enumeration in service.Enumerations)
            {
                if (enumeration.Name == "TestEnum")
                {
                    MessageAssert.HasDocumentation(enumeration, "<doc>\n<summary>\nDocumentation string for TestEnum.\n</summary>\n</doc>");
                    MessageAssert.HasValues(enumeration, 3);
                    MessageAssert.HasValue(enumeration, 0, "X", 0, "<doc>\n<summary>\nDocumented enum field\n</summary>\n</doc>");
                    MessageAssert.HasValue(enumeration, 1, "Y", 1);
                    MessageAssert.HasValue(enumeration, 2, "Z", 2);
                }
                else
                {
                    Assert.Fail();
                }
                foundEnumerations++;
            }
            Assert.AreEqual(1, foundEnumerations);
            Assert.AreEqual(1, service.Enumerations.Count);
        }
示例#2
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);
        }
示例#3
0
        public void GetServices()
        {
            var services = KRPC.Service.KRPC.KRPC.GetServices();

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

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

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

            int foundProcedures = 0;

            foreach (var proc in service.Procedures)
            {
                if (proc.Name == "GetClientID")
                {
                    MessageAssert.HasReturnType(proc, typeof(byte[]));
                    MessageAssert.HasNoParameters(proc);
                    MessageAssert.HasDocumentation(proc);
                }
                else if (proc.Name == "GetClientName")
                {
                    MessageAssert.HasReturnType(proc, typeof(string));
                    MessageAssert.HasNoParameters(proc);
                    MessageAssert.HasDocumentation(proc);
                }
                else if (proc.Name == "GetStatus")
                {
                    MessageAssert.HasReturnType(proc, typeof(KRPC.Service.Messages.Status));
                    MessageAssert.HasNoParameters(proc);
                    MessageAssert.HasDocumentation(proc);
                }
                else if (proc.Name == "GetServices")
                {
                    MessageAssert.HasReturnType(proc, typeof(KRPC.Service.Messages.Services));
                    MessageAssert.HasNoParameters(proc);
                    MessageAssert.HasDocumentation(proc);
                }
                else if (proc.Name == "AddStream")
                {
                    MessageAssert.HasReturnType(proc, typeof(KRPC.Service.Messages.Stream));
                    MessageAssert.HasParameters(proc, 2);
                    MessageAssert.HasParameter(proc, 0, typeof(KRPC.Service.Messages.ProcedureCall), "call");
                    MessageAssert.HasParameterWithDefaultValue(proc, 1, typeof(bool), "start", true);
                    MessageAssert.HasDocumentation(proc);
                }
                else if (proc.Name == "StartStream")
                {
                    MessageAssert.HasNoReturnType(proc);
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameter(proc, 0, typeof(ulong), "id");
                    MessageAssert.HasDocumentation(proc);
                }
                else if (proc.Name == "SetStreamRate")
                {
                    MessageAssert.HasNoReturnType(proc);
                    MessageAssert.HasParameters(proc, 2);
                    MessageAssert.HasParameter(proc, 0, typeof(ulong), "id");
                    MessageAssert.HasParameter(proc, 1, typeof(float), "rate");
                    MessageAssert.HasDocumentation(proc);
                }
                else if (proc.Name == "RemoveStream")
                {
                    MessageAssert.HasNoReturnType(proc);
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameter(proc, 0, typeof(ulong), "id");
                    MessageAssert.HasDocumentation(proc);
                }
                else if (proc.Name == "get_Clients")
                {
                    MessageAssert.HasReturnType(proc, typeof(IList <KRPC.Utils.Tuple <byte[], string, string> >));
                    MessageAssert.HasNoParameters(proc);
                    MessageAssert.HasDocumentation(proc);
                }
                else if (proc.Name == "get_CurrentGameScene")
                {
                    MessageAssert.HasReturnType(proc, typeof(KRPC.Service.KRPC.KRPC.GameScene));
                    MessageAssert.HasNoParameters(proc);
                    MessageAssert.HasDocumentation(proc);
                }
                else
                {
                    foundProcedures--;
                }
                foundProcedures++;
            }
            Assert.AreEqual(10, 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);

            int foundExceptions = 0;

            foreach (var exception in service.Exceptions)
            {
                if (exception.Name == "InvalidOperationException")
                {
                    MessageAssert.HasDocumentation(exception,
                                                   "<doc>\n<summary>\nA method call was made to a method that is invalid\ngiven the current state of the object.\n</summary>\n</doc>");
                }
                else if (exception.Name == "ArgumentException")
                {
                    MessageAssert.HasDocumentation(exception,
                                                   "<doc>\n<summary>\nA method was invoked where at least one of the passed arguments does not\nmeet the parameter specification of the method.\n</summary>\n</doc>");
                }
                else if (exception.Name == "ArgumentNullException")
                {
                    MessageAssert.HasDocumentation(exception,
                                                   "<doc>\n<summary>\nA null reference was passed to a method that does not accept it as a valid argument.\n</summary>\n</doc>");
                }
                else if (exception.Name == "ArgumentOutOfRangeException")
                {
                    MessageAssert.HasDocumentation(exception,
                                                   "<doc>\n<summary>\nThe value of an argument is outside the allowable range of values as defined by the invoked method.\n</summary>\n</doc>");
                }
                foundExceptions++;
            }
            Assert.AreEqual(4, foundExceptions);
        }