public void SimpleExpectationSetUp_BindingInputWithMultipleParametersToReturnValue_InvocationValuesAreAccessibleWhenStubbingMessage()
        {
            MsmqHelpers.Purge("shippingservice");
            var service = Configure.Stub().NServiceBusSerializers().WcfEndPoints().Create(@".\Private$\orderservice");

            var proxy = service.WcfEndPoint <ISomeService>("http://localhost:9101/something");

            proxy.Setup(s => s.IHaveMultipleInputParameters(Parameter.Any <string>(), Parameter.Equals <string>(str => str == "snappy"), Parameter.Any <bool>())).Returns <string, string, bool>((param1, param2, param3) => param1)
            .Send <IOrderWasPlaced, string>((msg, product) => { msg.OrderedProduct = product; }, "shippingservice");

            service.Start();

            string firstRequestReturnValue;

            using (var factory = new ChannelFactory <ISomeService>(new BasicHttpBinding(), "http://localhost:9101/something"))
            {
                ISomeService channel = factory.CreateChannel();

                firstRequestReturnValue = channel.IHaveMultipleInputParameters("hello", "snappy", false);
            }

            service.Dispose();

            Assert.That(MsmqHelpers.PickMessageBody("shippingservice"), Is.StringContaining("hello"));
            Assert.That(firstRequestReturnValue, Is.EqualTo("hello"));
        }
Пример #2
0
        public void Get_InvokingEndpointAndExpectationMet_MessageIsSentToQueue()
        {
            MsmqHelpers.Purge("shippingservice");

            ServiceStub service = Configure.Stub().NServiceBusSerializers().Restful().Create(@".\Private$\orderservice");

            const string BaseUrl      = "http://localhost:9101/";
            RestApi      restEndpoint = service.RestEndpoint(BaseUrl);

            IRouteTemplate <bool> get = restEndpoint.AddGet <bool>("/list");

            restEndpoint.Configure(get).With(Parameter.Any()).Returns(true)
            .Send <IOrderWasPlaced>(msg => msg.OrderedProduct = "stockings", "shippingservice");

            service.Start();

            var client = new HttpClient {
                BaseAddress = new Uri(BaseUrl)
            };

            Task <string> getAsync = client.GetStringAsync("list");

            string result = WaitVerifyNoExceptionsAndGetResult(getAsync);

            do
            {
                Thread.Sleep(100);
            } while (MsmqHelpers.GetMessageCount("shippingservice") == 0);

            client.Dispose();
            service.Dispose();

            Assert.That(result, Is.EqualTo("true"));
            Assert.That(MsmqHelpers.GetMessageCount("shippingservice"), Is.EqualTo(1), "shipping service did not recieve send");
        }
Пример #3
0
 public override bool Print(PrintType type, Printer printer)
 {
     if (Static)
     {
         Object.Print(type, printer);
         printer.Write("_");
     }
     printer.Write(Name);
     printer.Write("(");
     if (Object != null)
     {
         if (!Static)
         {
             Object.Print(type, printer);
             if (Parameter.Any())
             {
                 printer.Write(", ");
             }
         }
     }
     foreach (var i in Parameter)
     {
         i.Print(type, printer);
         if (!i.Equals(Parameter.Last()))
         {
             printer.Write(", ");
         }
     }
     printer.Write(")");
     return(true);
 }
        public void SimpleExpectationSetUp_BindingInputWithMultipleParametersToReturnValue2_InvocationValuesArePassedToReturn()
        {
            var service = Configure.Stub().NServiceBusSerializers().WcfEndPoints().Create(@".\Private$\orderservice");

            var proxy = service.WcfEndPoint <ISomeService>("http://localhost:9101/something");

            proxy.Setup(s => s.IHave4InputParameters(Parameter.Any <string>(), Parameter.Equals <string>(str => str == "snappy"), Parameter.Any <bool>(), Parameter.Any <string>())).Returns <string, string, bool, string>((param1, param2, param3, param4) =>
                                                                                                                                                                                                                            new FourInputParamsReturnValue {
                ReturnOne = param1, ReturnTwo = param2, ReturnThree = param3, ReturnFour = param4
            });

            service.Start();

            FourInputParamsReturnValue retVal;

            using (var factory = new ChannelFactory <ISomeService>(new BasicHttpBinding(), "http://localhost:9101/something"))
            {
                ISomeService channel = factory.CreateChannel();

                retVal = channel.IHave4InputParameters("hello", "snappy", false, "poppy");
            }

            service.Dispose();

            Assert.That(retVal.ReturnOne, Is.EqualTo("hello"));
        }
        public void SimpleExpectationSetUp_BindingInputToReturnValueByName_InvocationValuesArePassedToReturn()
        {
            var service = Configure.Stub().NServiceBusSerializers().WcfEndPoints().Create(@".\Private$\orderservice");

            var proxy = service.WcfEndPoint <ISomeService>("http://localhost:9101/something");

            proxy.Setup(s => s.IHave4InputParameters(Parameter.Any <string>(), Parameter.Any <string>(), Parameter.Any <bool>(), Parameter.Any <string>())).Returns <string>(fallback => new FourInputParamsReturnValue {
                ReturnOne = fallback
            });

            service.Start();

            FourInputParamsReturnValue actual;

            using (var factory = new ChannelFactory <ISomeService>(new BasicHttpBinding(), "http://localhost:9101/something"))
            {
                ISomeService channel = factory.CreateChannel();

                actual = channel.IHave4InputParameters("john doe", "somewhere", false, "to this");
            }

            service.Dispose();

            Assert.That(actual.ReturnOne, Is.EqualTo("to this"));
        }
        public void SimpleExpectationSetUp_UsingServiceKnownType_HandledAndMessageIsSentToQueue()
        {
            MsmqHelpers.Purge("shippingservice");

            var service = Configure.Stub().NServiceBusSerializers().WcfEndPoints().Create(@".\Private$\orderservice");

            var proxy = service.WcfEndPoint <IOrderService>("http://localhost:9101/orderservice");

            proxy.Setup(s => s.ExecuteCommand(Parameter.Any <DeleteOrder>()))
            .Send <IOrderWasPlaced>(msg => msg.OrderedProduct = "stockings", "shippingservice");

            service.Start();

            using (var factory = new ChannelFactory <IOrderService>(new BasicHttpBinding(), "http://localhost:9101/orderservice"))
            {
                IOrderService channel = factory.CreateChannel();

                channel.ExecuteCommand(new DeleteOrder());
            }

            MsmqHelpers.WaitForMessages("shippingservice");

            service.Dispose();

            Assert.That(MsmqHelpers.GetMessageCount("shippingservice"), Is.EqualTo(1), "shipping service did not recieve send");
        }
Пример #7
0
        public void ExecuteFromVariableWithParam()
        {
            var statement = Sql.Execute(Sql.Name("temp_statement"), Parameter.Any("@a1"), Parameter.Any("@a2"));
            var command   = Provider.GetCommand(statement);

            Assert.IsNotNull(command);
            Assert.AreEqual("EXECUTE `temp_statement` USING @a1, @a2;", command.CommandText);
        }
Пример #8
0
        public void SelectParam1WithDefault2()
        {
            var statement = Sql.Select.Output(Parameter.Any("@param1", "Foo"));

            var command = Utilities.GetCommand(statement);

            Assert.NotNull(command);
            Assert.Equal("SELECT @param1;", command.CommandText);

            //var result = command.ExecuteScalar();
            //Assert.Equal(result, "Foo");
        }
Пример #9
0
        public IStatement SelectParam1WithDefault2()
        {
            var statement = Sql.Select.Output(Parameter.Any("@param1", "Foo"));

            var text = Provider.GenerateStatement(statement);

            Assert.NotNull(text);
            Assert.Equal("SELECT @param1;", text);
            return(statement);

            //var result = command.ExecuteScalar();
            //Assert.Equal(result, "Foo");
        }
Пример #10
0
        public void BeginRollbackParameterTransactions()
        {
            var statement = Sql.Statements(
                Sql.BeginTransaction(Parameter.Any("@t")),
                Sql.SaveTransaction(Parameter.Any("@s")),
                Sql.RollbackTransaction(Parameter.Any("@s")),
                Sql.CommitTransaction(Parameter.Any("@t")));

            var command = Provider.GetCommand(statement);

            Assert.NotNull(command);
            Assert.Equal("BEGIN TRANSACTION @t;\r\nSAVEPOINT @s;\r\nROLLBACK TRANSACTION TO SAVEPOINT @s;\r\nCOMMIT TRANSACTION @t;", command.CommandText);
        }
Пример #11
0
        public void SelectParam1As()
        {
            var statement = Sql.Select.Output(Parameter.Any("@param1").As("p1"));

            var command = Utilities.GetCommand(statement);

            Assert.NotNull(command);
            Assert.Equal("SELECT @param1 AS [p1];", command.CommandText);

            //command.Parameters.SetValue("@param1", "Foo");

            //var result = command.ExecuteScalar();
            //Assert.Equal(result, "Foo");
        }
Пример #12
0
        public IStatement SelectParam1As()
        {
            var statement = Sql.Select.Output(Parameter.Any("@param1").As("p1"));

            var text = Provider.GenerateStatement(statement);

            Assert.NotNull(text);
            Assert.Equal("SELECT @param1 AS \"p1\";", text);
            return(statement);

            //command.Parameters.SetValue("@param1", "Foo");

            //var result = command.ExecuteScalar();
            //Assert.Equal(result, "Foo");
        }
Пример #13
0
        /// <summary>
        /// Initializes a new instance of the GreaterThanConstraint class using the specified parameters.
        /// </summary>
        /// <param name="left"> The left parameter.</param>
        /// <param name="right">The right parameter.</param>
        public GreaterThanConstraint(Parameter left, Parameter right)
        {
            if (left.Any((v) => !(v is IComparable)))
            {
                throw new ArgumentException("All parameter values must implement IComparable.", "left");
            }

            if (right.Any((v) => !(v is IComparable)))
            {
                throw new ArgumentException("All parameter values must implement IComparable.", "right");
            }

            Value          = null;
            LeftParameter  = left;
            RightParameter = right;
        }
Пример #14
0
        /// <summary>
        /// Initializes a new instance of the GreaterThanConstraint class using the specified parameter and value.
        /// </summary>
        /// <param name="parameter">The parameter.</param>
        /// <param name="value">The value.</param>
        public GreaterThanConstraint(Parameter parameter, object value)
        {
            if (!(value is IComparable))
            {
                throw new ArgumentException("Value must implement IComparable.", "value");
            }

            if (parameter.Any((v) => !(v is IComparable)))
            {
                throw new ArgumentException("All parameter values must implement IComparable.", "parameter");
            }

            Value          = (IComparable)value;
            LeftParameter  = parameter;
            RightParameter = null;
        }
Пример #15
0
        private void PrintFunctionHeader(PrintType type, Printer printer)
        {
            ReturnType.Print(type, printer);
            printer.Write(" ");
            if (Static)
            {
                ExtensionBase.Print(PrintType.WithoutModifiers, printer);
                printer.Write("_");
            }
            printer.Write($"{Name}(");

            if (!Static && ExtensionBase != null)
            {
                var thisVariable = new Variable
                {
                    Line   = Line,
                    Column = Column,
                    Name   = "__this",
                    Type   = ExtensionBase
                };

                thisVariable.Print(type, printer);

                if (Parameter.Any())
                {
                    printer.Write(", ");
                }
            }

            foreach (var i in Parameter)
            {
                i.Print(type, printer);
                if (i != Parameter.Last())
                {
                    printer.Write(", ");
                }
            }

            printer.Write(")");
        }
        public void SimpleExpectationSetUp_BindingInputWithMultipleParametersToReturnValue_InvocationValuesArePassedToReturn()
        {
            var service = Configure.Stub().NServiceBusSerializers().WcfEndPoints().Create(@".\Private$\orderservice");

            var proxy = service.WcfEndPoint <ISomeService>("http://localhost:9101/something");

            proxy.Setup(s => s.IHaveMultipleInputParameters(Parameter.Any <string>(), Parameter.Equals <string>(str => str == "snappy"), Parameter.Any <bool>())).Returns <string, string, bool>((param1, param2, param3) => param1);

            service.Start();

            string firstRequestReturnValue;

            using (var factory = new ChannelFactory <ISomeService>(new BasicHttpBinding(), "http://localhost:9101/something"))
            {
                ISomeService channel = factory.CreateChannel();

                firstRequestReturnValue = channel.IHaveMultipleInputParameters("hello", "snappy", false);
            }

            service.Dispose();

            Assert.That(firstRequestReturnValue, Is.EqualTo("hello"));
        }
        public void ExecuteServiceMethod_WhichReturnsComplexType_ReturnsType()
        {
            var service = Configure.Stub().NServiceBusSerializers().WcfEndPoints().Create(@"whatever");

            var proxy = service.WcfEndPoint <IOrderService>("http://localhost:9101/orderservice");

            proxy.Setup(s => s.PlaceOrder(Parameter.Any <string>())).Returns(() => true);
            proxy.Setup(s => s.WhenWasOrderLastPlaced()).Returns(() => new Date(2000, 1, 1));

            service.Start();

            Date returnValue;

            using (var factory = new ChannelFactory <IOrderService>(new BasicHttpBinding(), "http://localhost:9101/orderservice"))
            {
                IOrderService channel = factory.CreateChannel();

                returnValue = channel.WhenWasOrderLastPlaced();
            }

            service.Dispose();

            Assert.That(returnValue, Is.EqualTo(new Date(2000, 1, 1)));
        }