Beispiel #1
0
        void AddFund(object sender, EventArgs e)
        {
            FundOrder fundOrder = new FundOrder();
            fundOrder.CustomerId = View.Customer;
            fundOrder.TickerSymbol = View.Fund;

            if (!string.IsNullOrEmpty(fundOrder.CustomerId) && !string.IsNullOrEmpty(fundOrder.TickerSymbol))
                eventAggregator.GetEvent<FundAddedEvent>().Publish(fundOrder);
        }
        public void PresenterAddsFundOnEvent()
        {
            var view = new MockActivityView();
            var mockEventAggregator = new MockEventAggregator();

            MockFundAddedEvent mockEvent = new MockFundAddedEvent();
            mockEventAggregator.AddMapping<FundAddedEvent>(mockEvent);

            ActivityPresenter presenter = new ActivityPresenter(mockEventAggregator);
            presenter.View = view;
            string customerId = "ALFKI";
            presenter.CustomerId = customerId;
            FundOrder payload = new FundOrder() { CustomerId = customerId, TickerSymbol = "MSFT" };
            mockEvent.SubscribeArgumentAction(payload);
            StringAssert.Contains(view.AddContentArgumentContent, "MSFT");
        }
        public void PresenterUnsubcribesFromFundAddedEventIfCustomerIDIsSetTwice()
        {
            var mockEventAggregator = new MockEventAggregator();

            MockFundAddedEvent mockEvent = new MockFundAddedEvent();
            string customerId = "ALFKI";
            FundOrder payload = new FundOrder() { CustomerId = customerId, TickerSymbol = "MSFT" };
            mockEvent.Subscribe(delegate { new FundOrder() { CustomerId = customerId, TickerSymbol = "MSFT" }; }, ThreadOption.UIThread, true, delegate { return true; });
            mockEventAggregator.AddMapping<FundAddedEvent>(mockEvent);
            ActivityPresenter presenter = new ActivityPresenter(mockEventAggregator);
            presenter.View = new MockActivityView();


            presenter.CustomerId = "ALFKI";
            presenter.CustomerId = "ALFKI";

            Assert.AreEqual(1, mockEvent.SubscribeCount);
        }
        public void PresenterSubscribesToFundAddedForCorrectCustomer()
        {
            var mockEventAggregator = new MockEventAggregator();

            MockFundAddedEvent mockEvent = new MockFundAddedEvent();
            mockEventAggregator.AddMapping<FundAddedEvent>(mockEvent);
            ActivityPresenter presenter = new ActivityPresenter(mockEventAggregator);
            presenter.View = new MockActivityView();

            string customerId = "ALFKI";
            presenter.CustomerId = customerId;

            FundOrder payload = new FundOrder() { CustomerId = customerId };
            mockEvent.Subscribe(delegate { new FundOrder() { CustomerId = customerId }; }, ThreadOption.UIThread, true, delegate{
                if (customerId == "ALFKI"){
                    return true;
                }
                else{
                    return false;
                }
                                                                                                                        });
            mockEvent.Publish(payload);

            Assert.IsTrue(mockEvent.SubscribeArgumentFilter(new FundOrder { CustomerId = "ALFKI" }));
            Assert.AreEqual(ThreadOption.UIThread, mockEvent.ThreadOption);
            customerId = "FilteredOutCustomer";
            mockEvent.Subscribe(delegate { new FundOrder() { CustomerId = customerId }; }, ThreadOption.UIThread, true, delegate {
                if (customerId == "ALFKI")
                {
                    return true;
                }
                else {
                    return false;
                }
            });
            Assert.IsFalse(mockEvent.SubscribeArgumentFilter(new FundOrder { CustomerId = "FilteredOutCustomer" }));
        }
 public override void Publish(FundOrder payload)
 {
     PublishCalled = true;
     PublishArgumentPayload = payload;
 }
 public bool FundOrderFilter(FundOrder fundOrder)
 {
     return fundOrder.CustomerId == _customerId;
 }
 public void FundAddedEventHandler(FundOrder fundOrder)
 {
     Debug.Assert(View != null);
     View.AddContent(fundOrder.TickerSymbol);
 }