Example #1
0
        public void Should_properly_handle_the_response()
        {
            var     response = new FutureChannel <Purchased>();
            decimal price    = 0.0m;

            AnonymousActor.New(inbox =>
            {
                Auction.Request(new Ask(Id), inbox)
                .Within(30.Seconds())
                .Receive <Response <Status> >(m => status =>
                {
                    price = status.Body.CurrentBid;
                    Auction.Request(new Buy(status.Body.Token, 1), inbox)
                    .Within(30.Seconds())
                    .Receive <Response <Purchased> >(pm => pmsg => response.Complete(pmsg.Body))
                    .Otherwise(() => {});
                })
                .Receive <Response <Ended> >(m => ended => {});
            });

            response.WaitUntilCompleted(4.Seconds()).ShouldBeTrue("Timeout waiting for response");

            response.Value.AuctionId.ShouldEqual(Id);
            response.Value.Quantity.ShouldEqual(1);
            response.Value.Price.ShouldEqual(price);
        }
Example #2
0
        public void Should_properly_handle_the_response()
        {
            var response = new FutureChannel<Purchased>();
            decimal price = 0.0m;

            AnonymousActor.New(inbox =>
                {
                    Auction.Request(new Ask(Id), inbox)
                        .Within(30.Seconds())
                        .Receive<Response<Status>>(m => status =>
                            {
                                price = status.Body.CurrentBid;
                                Auction.Request(new Buy(status.Body.Token, 1), inbox)
                                    .Within(30.Seconds())
                                    .Receive<Response<Purchased>>(pm => pmsg => response.Complete(pmsg.Body))
                                    .Otherwise(() => { });
                            })
                        .Receive<Response<Ended>>(m => ended => { });
                });

            response.WaitUntilCompleted(4.Seconds()).ShouldBeTrue("Timeout waiting for response");

            response.Value.AuctionId.ShouldEqual(Id);
            response.Value.Quantity.ShouldEqual(1);
            response.Value.Price.ShouldEqual(price);
        }
Example #3
0
        public void Should_not_receive_a_response_to_a_stupid_message()
        {
            var response = new FutureChannel <bool>();

            AnonymousActor.New(inbox =>
            {
                Auction.Request(new Ask(new Guid()), inbox)
                .Within(1.Seconds())
                .Receive <Response <Status> >(m => status => {})
                .Otherwise(() => response.Complete(true));
            });

            response.WaitUntilCompleted(4.Seconds()).ShouldBeTrue("Timeout waiting for otherwise to be called");
        }
Example #4
0
        public void Should_receive_the_expected_value()
        {
            var response = new FutureChannel <Status>();

            AnonymousActor.New(inbox =>
            {
                Auction.Request(new Ask(Id), inbox)
                .Within(30.Seconds())
                .Receive <Response <Status> >(m => status => response.Complete(status.Body))
                .Receive <Response <Ended> >(m => ended => {});
            });

            response.WaitUntilCompleted(4.Seconds()).ShouldBeTrue("Timeout waiting for response");

            response.Value.AuctionId.ShouldEqual(Id);
        }
Example #5
0
        public void Should_receive_the_expected_value()
        {
            var response = new FutureChannel<Status>();

            AnonymousActor.New(inbox =>
                {
                    Auction.Request(new Ask(Id), inbox)
                        .Within(30.Seconds())
                        .Receive<Response<Status>>(m => status => response.Complete(status.Body))
                        .Receive<Response<Ended>>(m => ended => { });
                });

            response.WaitUntilCompleted(4.Seconds()).ShouldBeTrue("Timeout waiting for response");

            response.Value.AuctionId.ShouldEqual(Id);
        }
Example #6
0
        public void Should_receive_the_alternate_ending_if_it_is_such()
        {
            Auction.Send(new End());

            var response = new FutureChannel <Ended>();

            AnonymousActor.New(inbox =>
            {
                Auction.Request(new Ask(Id), inbox)
                .Within(30.Seconds())
                .Receive <Response <Status> >(m => status => {})
                .Receive <Response <Ended> >(m => ended => response.Complete(ended.Body));
            });

            response.WaitUntilCompleted(4.Seconds()).ShouldBeTrue("Timeout waiting for response");

            response.Value.AuctionId.ShouldEqual(Id);
        }
Example #7
0
		public void Should_receive_the_alternate_ending_if_it_is_such()
		{
			Auction.Send(new End());

			var response = new FutureChannel<Ended>();

			AnonymousActor.New(inbox =>
			{
				Auction.Request(new Ask(Id), inbox)
					.Within(30.Seconds())
					.Receive<Response<Status>>(m => status => {})
					.Receive<Response<Ended>>(m => ended => response.Complete(ended.Body));
			});

			response.WaitUntilCompleted(4.Seconds()).ShouldBeTrue("Timeout waiting for response");

			response.Value.AuctionId.ShouldEqual(Id);
		}
Example #8
0
        public void Should_not_call_the_other_receive_handlers()
        {
            var statusResponse = new FutureChannel <Status>();
            var endedResponse  = new FutureChannel <Ended>();

            AnonymousActor.New(inbox =>
            {
                Auction.Request(new Ask(Id), inbox)
                .Within(10.Seconds())
                .Receive <Response <Status> >(m => status =>
                {
                    statusResponse.Complete(status.Body);
                    Auction.Send(new End());
                    Auction.Request(new Ask(Id), inbox);
                })
                .Receive <Response <Ended> >(m => ended => endedResponse.Complete(ended.Body));
            });

            statusResponse.WaitUntilCompleted(4.Seconds()).ShouldBeTrue("Timeout waiting for response");
            endedResponse.WaitUntilCompleted(2.Seconds()).ShouldBeFalse("The receiver for Ended should not have been called.");
        }
Example #9
0
        public void Should_not_receive_a_response_to_a_stupid_message()
        {
            var response = new FutureChannel<bool>();

            AnonymousActor.New(inbox =>
                {
                    Auction.Request(new Ask(new Guid()), inbox)
                        .Within(1.Seconds())
                        .Receive<Response<Status>>(m => status => { })
                        .Otherwise(() => response.Complete(true));
                });

            response.WaitUntilCompleted(4.Seconds()).ShouldBeTrue("Timeout waiting for otherwise to be called");
        }
Example #10
0
        public void Should_not_call_the_other_receive_handlers()
        {
            var statusResponse = new FutureChannel<Status>();
            var endedResponse = new FutureChannel<Ended>();

            AnonymousActor.New(inbox =>
                {
                    Auction.Request(new Ask(Id), inbox)
                        .Within(10.Seconds())
                        .Receive<Response<Status>>(m => status =>
                            {
                                statusResponse.Complete(status.Body);
                                Auction.Send(new End());
                                Auction.Request(new Ask(Id), inbox);
                            })
                        .Receive<Response<Ended>>(m => ended => endedResponse.Complete(ended.Body));
                });

            statusResponse.WaitUntilCompleted(4.Seconds()).ShouldBeTrue("Timeout waiting for response");
            endedResponse.WaitUntilCompleted(2.Seconds()).ShouldBeFalse("The receiver for Ended should not have been called.");
        }