Ejemplo n.º 1
0
        public async Task NPubilsher_Static_Should_SubscribeTypeOfMessage()
        {
            var ts           = new TaskCompletionSource <TestMessage>();
            var ok           = false;
            var subscription = NPublisher.SubscribeIt <TestMessage>(x =>
            {
                ok = true;
                ts.SetResult(x);
            });

            NPublisher.PublishIt <TestMessage>();

            await ts.Task;

            ok.Should().BeTrue();
        }
Ejemplo n.º 2
0
        private void InitializeSubscriptions()
        {
            _loggedSubscription = NPublisher.SubscribeIt <LoggedMessage>(message =>
            {
                InitializeTimer();
            });

            _unloggedSubscription = NPublisher.SubscribeIt <LogoutMessage>(async message =>
            {
                SynchronizationTimerTokenSource.Cancel(true);
                SynchronizationTimer.Stop();

                var dbCleaner = Container.Resolve <ICleanService>();
                dbCleaner.Clean();

                MainThread.BeginInvokeOnMainThread(InitializeStartPage);
            });
        }
Ejemplo n.º 3
0
        public async Task NPubilsher_Static_Should_Unsubscribe()
        {
            var ts           = new TaskCompletionSource <TestMessageForUnsubscribe>();
            var ok           = false;
            var subscription = NPublisher.SubscribeIt <TestMessageForUnsubscribe>(x =>
            {
                ok = !ok;
                ts.SetResult(x);
            });

            NPublisher.PublishIt <TestMessageForUnsubscribe>();

            var result = await ts.Task;

            NPublisher.UnsubscribeIt(subscription);
            NPublisher.PublishIt <TestMessageForUnsubscribe>();

            ok.Should().Be(true);
        }
Ejemplo n.º 4
0
        public async Task NPubilsher_Static_Should_SubscribeTypeOfMessageWithContent()
        {
            var ts           = new TaskCompletionSource <TestMessageWithContent>();
            var ok           = false;
            var message      = new TestMessageWithContent("sample_data");
            var subscription = NPublisher.SubscribeIt <TestMessageWithContent>(x =>
            {
                ok = true;
                ts.SetResult(x);
                x.Should().Be(message);
            });

            NPublisher.PublishIt(message);

            var result = await ts.Task;

            result.Content.Should().Be(message.Content);
            result.Should().Be(message);
        }
Ejemplo n.º 5
0
        protected NoteViewModel(IViewModelFacade viewModelFacade) : base(viewModelFacade)
        {
            SelectNoteCommand = new Command <Note>(async(x) => await GoToNoteAsync(x));

            _newNotesSubscription = NPublisher.SubscribeIt <NewNotesMessage>(async message =>
            {
                var query = new GetActiveNotesQuery();
                var notes = await DispatchQueryAsync <GetActiveNotesQuery, ICollection <Note> >(query);

                MainThread.BeginInvokeOnMainThread(() =>
                {
                    Notes.Clear();

                    foreach (var note in notes)
                    {
                        Notes.Add(note);
                    }

                    OnPropertyChanged(nameof(Notes));
                    OnPropertyChanged(nameof(Note.CreatedAt));
                    OnPropertyChanged(nameof(Note.Name));
                });
            });
        }
Ejemplo n.º 6
0
 public void NPubilsher_Static_Should_ThrowExceptionOnNullAction()
 {
     Assert.Throws <NPublisherException>(() => NPublisher.SubscribeIt <TestMessageWithContent>(null));
 }