Example #1
0
        public async Task Should_Count_Unread_Notifications()
        {
            int  result    = 0;
            User sender    = new User((Nickname)"sender", (FullName)"sender user", Password.Create("password").Value, (Email)"*****@*****.**", "my bio");
            User recipient = new User((Nickname)"recipient", (FullName)"recipient user", Password.Create("password").Value, (Email)"*****@*****.**", "my bio");
            var  not1      = new Notification(sender, recipient, "Notification 1");
            var  not2      = new Notification(sender, recipient, "Notification 2");
            var  not3      = new Notification(sender, recipient, "Notification 3");

            using (var session = _testFixture.OpenSession(_output))
            {
                not1.MarkAsRead();
                await session.SaveAsync(sender);

                await session.SaveAsync(recipient);

                await session.SaveAsync(not1);

                await session.SaveAsync(not2);

                await session.SaveAsync(not3);

                await session.FlushAsync();
            }

            var query = new UnreadNotificationsQuery(recipient.ID);

            using (var session = _testFixture.OpenSession(_output))
            {
                var sut = new UnreadNotificationsQueryHandler(session, Log.Logger);
                result = await sut.Handle(query, default);
            }

            result.Should().Be(2);
        }
        public async Task <IViewComponentResult> InvokeAsync(int userID)
        {
            var query = new UnreadNotificationsQuery(userID);
            var count = await _dispatcher.Send(query);

            return(View(count));
        }