public void InvokeFailsIfTheNameCannotBeFound()
 {
     var server = new Server("Test");
     var invoker = new ActionInvoker(server);
     var result = invoker.Invoke("urn:ccnet:test:ghost", new InvokeArguments());
     Assert.IsNotNull(result);
     Assert.AreEqual(RemoteResultCode.UnknownUrn, result.ResultCode);
 }
 public void GetInstanceGeneratesNewInstanceWithServer()
 {
     var invoker = new ActionInvoker();
     var provider = new WcfChannelInstanceProvider(invoker);
     var instance = provider.GetInstance(null, null);
     Assert.IsInstanceOf<WcfChannel>(instance);
     var channel = instance as WcfChannel;
     Assert.AreSame(invoker, channel.Invoker);
 }
 public void InvokeFailsIfInputIsMissing()
 {
     var testItem = new TestItem("Baby");
     var server = new Server("Test", testItem);
     var invoker = new ActionInvoker(server);
     var arguments = new InvokeArguments
                         {
                             Action = "TestAction",
                             Data = string.Empty
                         };
     var result = invoker.Invoke("urn:ccnet:test:baby", arguments);
     Assert.IsNotNull(result);
     Assert.AreEqual(RemoteResultCode.InvalidInput, result.ResultCode);
 }
 public void InvokeFailsIfInputIsIncorrectType()
 {
     var testItem = new TestItem("Baby");
     var server = new Server("Test", testItem);
     var invoker = new ActionInvoker(server);
     var arguments = new InvokeArguments
                         {
                             Action = "TestAction",
                             Data = "<Blank xmlns=\"urn:cruisecontrol:common\" />"
                         };
     var result = invoker.Invoke("urn:ccnet:test:baby", arguments);
     Assert.IsNotNull(result);
     Assert.AreEqual(RemoteResultCode.InvalidInput, result.ResultCode);
 }
 public void InvokeHandlesMethodsWithTheSameName()
 {
     var called = false;
     var item = new TroublesomeItem
                    {
                        Name = "ghost",
                        DoSomethingAction = () => called = true
                    };
     var server = new Server("Test", item);
     var invoker = new ActionInvoker(server);
     var arguments = new InvokeArguments
                         {
                             Action = "DoSomething",
                             Data = "<Blank xmlns=\"urn:cruisecontrol:common\" />"
                         };
     var result = invoker.Invoke("urn:ccnet:test:ghost", arguments);
     Assert.AreEqual(RemoteResultCode.Success, result.ResultCode);
     Assert.IsTrue(called);
 }
 public void InvokeInvokesMethod()
 {
     var testItem = new TestItem("Baby");
     var server = new Server("Test", testItem);
     var invoker = new ActionInvoker(server);
     var arguments = new InvokeArguments
                         {
                             Action = "DoSomething",
                             Data = "<Blank xmlns=\"urn:cruisecontrol:common\" />"
                         };
     var result = invoker.Invoke("urn:ccnet:test:baby", arguments);
     Assert.AreEqual(RemoteResultCode.Success, result.ResultCode);
     Assert.IsNotNull(result);
     Assert.IsNotNull(result.Data);
     var message = MessageSerialiser.Deserialise(result.Data);
     Assert.IsInstanceOf<Messages.Blank>(message);
     Assert.IsTrue(testItem.WasInvoked);
 }
 public void RetrieveServerNameRetrievesUrnFromServer()
 {
     var server = new Server("testserver");
     var invoker = new ActionInvoker(server);
     var expected = server.UniversalName;
     var actual = invoker.RetrieveServerName();
     Assert.AreEqual(expected, actual);
 }
 public void QueryRetrievesOutputDefinitions()
 {
     var testItem = new TestItem("Baby");
     var server = new Server("Test", testItem);
     var invoker = new ActionInvoker(server);
     var result = invoker.Query(
         "urn:ccnet:test:baby",
         new QueryArguments { DataToInclude = DataDefinitions.OutputOnly });
     Assert.IsNotNull(result);
     Assert.AreEqual(RemoteResultCode.Success, result.ResultCode);
     var expected = new[]
                        {
                            new RemoteActionDefinition
                                {
                                    Name = "DoSomething",
                                    Description = "This will do something",
                                    OutputData = "<definition name=\"Blank\" namespace=\"urn:cruisecontrol:common\" />"
                                },
                            new RemoteActionDefinition
                                {
                                    Name = "TestAction",
                                    Description = "This is a test action",
                                    OutputData = "<definition name=\"Blank\" namespace=\"urn:cruisecontrol:common\" />"
                                }
                        };
     CollectionAssert.AreEqual(expected, result.Actions.OrderBy(rad => rad.Name), new DefinitionComparer());
 }
 public void QueryFiltersActions()
 {
     var testItem = new TestItem("Baby");
     var server = new Server("Test", testItem);
     var invoker = new ActionInvoker(server);
     var args = new QueryArguments { FilterPattern = "DoSomething", DataToInclude = DataDefinitions.None };
     var result = invoker.Query("urn:ccnet:test:baby", args);
     Assert.IsNotNull(result);
     Assert.AreEqual(RemoteResultCode.Success, result.ResultCode);
     var expected = new[]
                        {
                            new RemoteActionDefinition
                                {
                                    Name = "DoSomething",
                                    Description = "This will do something"
                                }
                        };
     CollectionAssert.AreEqual(expected, result.Actions, new DefinitionComparer());
 }
 public void PingReturnsTrue()
 {
     var channel = new ActionInvoker(null);
     Assert.IsTrue(channel.Ping());
 }
 public void QueryReturnsActions()
 {
     var testItem = new TestItem("Baby");
     var server = new Server("Test", testItem);
     var invoker = new ActionInvoker(server);
     var result = invoker.Query("urn:ccnet:test:baby", null);
     Assert.IsNotNull(result);
     Assert.AreEqual(RemoteResultCode.Success, result.ResultCode);
     var expected = new[]
                        {
                            new RemoteActionDefinition
                                {
                                    Name = "DoSomething",
                                    Description = "This will do something",
                                    InputData = "<definition name=\"Blank\" namespace=\"urn:cruisecontrol:common\" />",
                                    OutputData = "<definition name=\"Blank\" namespace=\"urn:cruisecontrol:common\" />"
                                },
                            new RemoteActionDefinition
                                {
                                    Name = "TestAction",
                                    Description = "This is a test action",
                                    InputData = "<definition name=\"SingleValue\" namespace=\"urn:cruisecontrol:common\">" +
                                             "<value name=\"Value\" type=\"string\" />" +
                                         "</definition>",
                                    OutputData = "<definition name=\"Blank\" namespace=\"urn:cruisecontrol:common\" />"
                                }
                        };
     CollectionAssert.AreEqual(expected, result.Actions.OrderBy(rad => rad.Name), new DefinitionComparer());
 }
 public void InvokeFailsIfTheArgumentsAreMissing()
 {
     var testItem = new TestItem("Baby");
     var server = new Server("Test", testItem);
     var invoker = new ActionInvoker(server);
     var result = invoker.Invoke("urn:ccnet:test:baby", null);
     Assert.IsNotNull(result);
     Assert.AreEqual(RemoteResultCode.MissingArguments, result.ResultCode);
 }
 public void InvokeFailsIfTheActionCannotBeFound()
 {
     var testItem = new TestItem("Baby");
     var server = new Server("Test", testItem);
     var invoker = new ActionInvoker(server);
     var result = invoker.Invoke("urn:ccnet:test:baby", new InvokeArguments { Action = "DoesNotExist" });
     Assert.IsNotNull(result);
     Assert.AreEqual(RemoteResultCode.UnknownAction, result.ResultCode);
 }