示例#1
0
        public async Task GiveWrongType_ShouldRaiseNotTypeExceptionAsync()
        {
            var sut = new CreateNotificationCommandHandler(_context, _mapper);

            var command = new CreateNotificationCommand()
            {
                Type = "WRONG TYPE"
            };

            await Should.ThrowAsync <NotTypeException>(() =>
                                                       sut.Handle(command, CancellationToken.None));
        }
        public CreateNotificationCommandHandlerTests()
        {
            repository      = new Mock <INotificationRepository>();
            providerFactory = new Mock <IStatusProviderFactory>();
            discordTokenApi = new Mock <IDiscordTokenApi>();
            cltToken        = CancellationToken.None;
            var settings = new AppSettings()
            {
                Discord = new DiscordSettings()
            };

            handler = new CreateNotificationCommandHandler(repository.Object, providerFactory.Object, discordTokenApi.Object, settings);
        }
示例#3
0
        public async Task GiveValidRequest_ShouldCreateNotification1()
        {
            var sut = new CreateNotificationCommandHandler(_context, _mapper);
            List <UserModel> toUserList = new List <UserModel>();

            toUserList.AddRange(new[]
            {
                new UserModel
                {
                    DisplayName = "User1",
                    UserId      = userId1
                },
                new UserModel
                {
                    DisplayName = "User2",
                    UserId      = userId2
                }
            });

            var command = new CreateNotificationCommand()
            {
                Type             = "Mention",
                ConversationId   = conversationId.ToString(),
                isRead           = false,
                MessageContent   = "@User -> test",
                MessageId        = "",
                TeamId           = teamId1.ToString(),
                RegUserId        = "",
                ToUser           = toUserList,
                ConversationName = "",
                URL = ""
            };

            await sut.Handle(command, CancellationToken.None);

            var result = _context.Notifications.Where(q => q.MessageContent == "@User -> test").ToList();

            result.ShouldNotBeNull();
            result.Count.ShouldBe(toUserList.Count());
            foreach (Notification nfc in result)
            {
                nfc.Type.ShouldBe("Mention");
                nfc.TeamId.ShouldBe(teamId1.ToString());
                nfc.isRead.ShouldBeFalse();
                nfc.Title.ShouldContain("mentioned you in a channel");
            }
        }