Exemplo n.º 1
0
        private void ButtonOpenMain_Click(object sender, RoutedEventArgs e)
        {
            var ofd = new OpenFileDialog();

            if (ofd.ShowDialog() != null)
            {
                if (string.IsNullOrEmpty(ofd.FileName))
                {
                    return;
                }

                var img = System.Drawing.Image.FromFile(ofd.FileName);
                var bit = ResizeImage(img, 320, 240);

                string path = $"{Environment.CurrentDirectory}\\temp";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                bit.Save($"{path}\\temp.tmp");

                EventbusManager.GetEventbus().OpenView <MainView>(new MainMessage($"{path}\\temp.tmp"));
            }
        }
        public void CleanUpEventbus()
        {
            var eventbus = EventbusManager.GetEventbus();

            eventbus.Deregister <MockView>();
            eventbus.Deregister <Mock2View>();

            Assert.AreEqual(0, eventbus.RegisteredCount);
        }
        public MainView()
        {
            this.InitializeComponent();

            this._viewModel = (MainViewModel)this.DataContext;

            EventbusManager.GetEventbus().Register <MainView, MainMessage>(this.EventBusReceivedMessage);

            this.FinishConvertEvent += this.MainView_FinishConvertEvent;
        }
        public void EventbusManagerSimpleTest()
        {
            // arrange
            var eventbus = EventbusManager.GetEventbus();

            // act
            eventbus.Register <MockView, MockMessage>((message) => true);

            // asssert

            Assert.AreEqual(1, eventbus.RegisteredCount);
        }
        public void EventbusManagerSendOneMessageErrorNotReceiverTest()
        {
            // arrange
            var eventbus = EventbusManager.GetEventbus();
            Func <IMessageContainer, bool> message1 = (message) => true;

            eventbus.Register <MockView, MockMessage>(message1);

            // act
            var result = Assert.ThrowsException <EventbusException>(() => eventbus.Send <MockView, MockMessage2>(new MockMessage2("my message")));

            // asssert
            Assert.AreEqual("Not found or registered. View: MockView, MockMessage2", result.Message);
        }
        public void EventbusManagerRegisterTwoEventsForTwoViewsGetCountFromTargetViewTest()
        {
            // arrange
            var eventbus = EventbusManager.GetEventbus();
            Func <IMessageContainer, bool> message1 = (message) => true;
            Func <IMessageContainer, bool> message2 = (message) => true;

            // act
            eventbus.Register <MockView, MockMessage>(message1);
            eventbus.Register <Mock2View, MockMessage>(message2);

            // asssert
            Assert.AreEqual(2, eventbus.RegisteredCount);
        }
        public void EventbusManagerRegisterTwoEventsInOneViewErrorTest()
        {
            // arrange
            var eventbus = EventbusManager.GetEventbus();
            Func <IMessageContainer, bool> message1 = (message) => true;
            Func <IMessageContainer, bool> message2 = (message) => true;

            eventbus.Register <MockView, MockMessage>(message1);

            // act
            var result = Assert.ThrowsException <EventbusException>(() => eventbus.Register <MockView, MockMessage>(message2));

            // asssert
            Assert.AreEqual("can not register one moretime to the viewType MockView about message type: MockMessage", result.Message);
        }
        public void EventbusManagerSendOneMessageTest()
        {
            // arrange
            var    eventbus = EventbusManager.GetEventbus();
            string result   = string.Empty;
            Func <IMessageContainer, bool> message1 = (message) => { result = message.Content.ToString(); return(true); };
            Func <IMessageContainer, bool> message2 = (message) => true;

            eventbus.Register <MockView, MockMessage>(message1);
            eventbus.Register <MockView, MockMessage2>(message2);

            // act
            eventbus.Send <MockView, MockMessage>(new MockMessage("my message"));

            // asssert
            Assert.AreEqual("my message", result);
        }
 public void Dispose()
 {
     EventbusManager.GetEventbus().Deregister <MainView>();
     this.FinishConvertEvent -= this.MainView_FinishConvertEvent;
 }