Example #1
0
        public void TestMethodDefinition(String methodDefinitionString, SosMethodDefinition expectedMethodDefinition)
        {
            Console.WriteLine("Testing '{0}'", methodDefinitionString);
            SosMethodDefinition methodDefinition = SosTypes.ParseMethodDefinition(methodDefinitionString, 0);
            String diff = expectedMethodDefinition.Diff(methodDefinition);

            if (diff != null)
            {
                Assert.Fail("Expected diff to be null but was '{0}'", diff);
            }
            if (!expectedMethodDefinition.Equals(methodDefinition))
            {
                Assert.Fail(String.Format("Diff was null but Equals failed Expected '{0}' Actual '{1}'",
                                          expectedMethodDefinition.Definition(), methodDefinition.Definition()));
            }
        }
Example #2
0
        /*
         * public void VerifyObjectsAndInterfaceMethods(Boolean forceInterfaceUpdateFromServer, ICollection<RemoteNpcObject> expectedObjects, ICollection<RemoteNpcInterface> expectedInterfaces)
         * {
         *  GetServerInterface(forceInterfaceUpdateFromServer);
         *  String interfaceDiff = ServerInterfaceMethodsDiff(cachedServerInterfaces.Values, expectedInterfaces);
         *  if (interfaceDiff != null) throw new InvalidOperationException(interfaceDiff);
         *
         *  foreach (RemoteNpcObject expectedObject in expectedObjects)
         *  {
         *      Boolean foundObject = false;
         *      for (int serverObjectIndex = 0; serverObjectIndex < cachedServerObjects.Count; serverObjectIndex++)
         *      {
         *          RemoteNpcObject serverObject = cachedServerObjects[serverObjectIndex];
         *
         *          if (expectedObject.name.Equals(serverObject.name))
         *          {
         *              foundObject = true;
         *
         *              // Check that the interfaces are the same
         *              for (int expectedInterfaceIndex = 0; expectedInterfaceIndex < expectedObject.interfaces.Length; expectedInterfaceIndex++)
         *              {
         *                  RemoteNpcInterface expectedInterface = expectedObject.interfaces[expectedInterfaceIndex];
         *                  Boolean foundInterface = false;
         *
         *                  for(int serverInterfaceIndex = 0; serverInterfaceIndex < serverObject.interfaces.Length; serverInterfaceIndex++)
         *                  {
         *                      RemoteNpcInterface serverInterface = serverObject.interfaces[serverInterfaceIndex];
         *
         *                      if(expectedInterface.name.Equals(serverInterface.name))
         *                      {
         *                          foundInterface = true;
         *                          // Note: the interface definition does not need to be checked because it was already checked
         *                          break;
         *                      }
         *
         *                  }
         *
         *                  if(!foundInterface) throw new InvalidOperationException(String.Format("Server object '{0}' is missing the '{1}' interface", serverObject.name, expectedInterface.name));
         *              }
         *
         *              break;
         *          }
         *      }
         *      if(!foundObject) throw new InvalidOperationException(String.Format("Server missing '{0}' object", expectedObject.name));
         *  }
         * }
         */
        /*
         * public void VerifyInterfaceMethods(Boolean forceInterfaceUpdateFromServer, ICollection<RemoteNpcInterface> expectedInterfaces)
         * {
         *  GetServerInterface(forceInterfaceUpdateFromServer);
         *  String interfaceDiff = ServerInterfaceMethodsDiff(cachedServerInterfaces.Values, expectedInterfaces);
         *  if (interfaceDiff != null) throw new InvalidOperationException(interfaceDiff);
         * }
         */

        // Returns null if the client interfaces are contained in the server interfaces, otherwise,
        // returns a message indicating what client interface is missing or out of sync.
        public static String ServerInterfaceMethodsDiff(IDictionary <String, RemoteNpcInterface> serverInterfaces, ICollection <RemoteNpcInterface> expectedInterfaces)
        {
            if (expectedInterfaces.Count > serverInterfaces.Count)
            {
                return(String.Format("Expected server to have at least {0} interfaces but server only has {1}", expectedInterfaces.Count, serverInterfaces.Count));
            }

            foreach (RemoteNpcInterface expectedInterface in expectedInterfaces)
            {
                RemoteNpcInterface serverInterface;
                if (!serverInterfaces.TryGetValue(expectedInterface.name, out serverInterface))
                {
                    return(String.Format("Server does not have the '{0}' interface", expectedInterface.name));
                }

                if (serverInterface.methods.Length != expectedInterface.methods.Length)
                {
                    return(String.Format("Expected server interface '{0}' to have {1} methods but it has {2}",
                                         serverInterface.name, expectedInterface.methods.Length, serverInterface.methods.Length));
                }

                //
                // Check that the interfaces are the same
                //
                for (int clientMethodIndex = 0; clientMethodIndex < expectedInterface.methods.Length; clientMethodIndex++)
                {
                    SosMethodDefinition clientMethodDefinition = expectedInterface.methods[clientMethodIndex];
                    Boolean             foundMethod            = false;
                    for (int serverMethodIndex = 0; serverMethodIndex < serverInterface.methods.Length; serverMethodIndex++)
                    {
                        SosMethodDefinition serverMethodDefinition = serverInterface.methods[serverMethodIndex];
                        if (clientMethodDefinition.Equals(serverMethodDefinition))
                        {
                            foundMethod = true;
                            break;
                        }
                    }
                    if (!foundMethod)
                    {
                        return(String.Format("Server Interface '{0}' does not have method '{1}'",
                                             serverInterface.name, clientMethodDefinition.Definition()));
                    }
                }
            }

            return(null); // The server has all the expected interfaces
        }