Example #1
0
        public void Save_WhenUserKnown_ThenSavesReaction()
        {
            // Arrange
            var sut = new ReactionsService(_reactionsRepositoryMock.Object, _usersRepositoryMock.Object, _mapperMock.Object);

            var dummyReaction = new Reaction
            {
                Name = "Old name"
            };
            var dummyUser = new User
            {
                Name = "New name"
            };

            _usersRepositoryMock
            .Setup(r => r.GetByToken("KIT20IWP3LQ"))
            .Returns(dummyUser);

            _reactionsRepositoryMock
            .Setup(rep => rep.Save(It.Is <Reaction>(rct => rct.Name == "New name")));

            // Act & Assert
            sut.Save("KIT20IWP3LQ", dummyReaction);

            _mockRepository.VerifyAll();
        }
Example #2
0
        public void Delete_WhenUserKnown_ThenSavesReaction()
        {
            // Arrange
            var sut = new ReactionsService(_reactionsRepositoryMock.Object, _usersRepositoryMock.Object, _mapperMock.Object);

            var id        = Guid.Parse("58018B2E-15BD-42D4-8A16-80465956BEF8");
            var dummyUser = new User
            {
                Rights = new List <Right> {
                    Right.AllowRemoveReactions
                }
            };

            _usersRepositoryMock
            .Setup(r => r.GetByToken("KIT20IWP3LQ"))
            .Returns(dummyUser);

            _reactionsRepositoryMock
            .Setup(rep => rep.Delete(id));

            // Act & Assert
            sut.Delete("KIT20IWP3LQ", id);

            _mockRepository.VerifyAll();
        }
Example #3
0
        public async Task Gender()
        {
            if (Context.Channel is IPrivateChannel)
            {
                return;
            }

            await ReactionsService.Gender(Context.Message, (ISocketMessageChannel)Context.Channel);
        }
Example #4
0
        public async Task Cashmachine()
        {
            if (Context.Channel is IPrivateChannel)
            {
                return;
            }

            await ReactionsService.Bank(Context.Message, Context.User, (ISocketMessageChannel)Context.Channel);
        }
Example #5
0
        public async Task Shop()
        {
            if (Context.Channel is IPrivateChannel)
            {
                return;
            }

            await ReactionsService.Shop(Context.Guild, Context.Message, (ISocketMessageChannel)Context.Channel);
        }
Example #6
0
        public async Task Fun2()
        {
            if (Context.Channel is IPrivateChannel)
            {
                return;
            }

            await ReactionsService.Fun2(Context.Guild, (ISocketMessageChannel)Context.Channel, Context.User, Context.Message);
        }
Example #7
0
        public async Task Profile()
        {
            if (Context.Channel is IPrivateChannel)
            {
                return;
            }

            await ReactionsService.Profile((ISocketMessageChannel)Context.Channel, Context.User, Context.Message);
        }
Example #8
0
        public void List_WhenIsAdmin_ThenShowEmails()
        {
            // Arrange
            var sut = new ReactionsService(_reactionsRepositoryMock.Object, _usersRepositoryMock.Object, _mapperMock.Object);

            var dummyQueryResults = new List <Reaction>();

            _reactionsRepositoryMock
            .Setup(r => r.List(3, SortType.Score, OrderType.Asc))
            .Returns(dummyQueryResults);

            var dummyMappedResults = new List <ReactionView>
            {
                new ReactionView
                {
                    Email = "*****@*****.**"
                },
                new ReactionView
                {
                    Email = "*****@*****.**"
                },
                new ReactionView
                {
                    Email = "*****@*****.**"
                }
            };

            _mapperMock
            .Setup(m => m.Map <List <ReactionView> >(dummyQueryResults))
            .Returns(dummyMappedResults);

            var dummyUser = new User
            {
                Rights = new List <Right> {
                    Right.AllowRemoveReactions
                }
            };

            _usersRepositoryMock
            .Setup(r => r.GetByToken("KIT20IWP3LQ"))
            .Returns(dummyUser);

            // Act
            var actual = sut.List("KIT20IWP3LQ", 3, SortType.Score, OrderType.Asc);

            // Assert
            actual.Count().ShouldBe(3);
            actual.ShouldAllBe(r => r.Email != null);

            _mockRepository.VerifyAll();
        }
Example #9
0
        public void Save_WhenUserNotKnown_ThenThrowUnauthorizedException()
        {
            // Arrange
            var sut = new ReactionsService(_reactionsRepositoryMock.Object, _usersRepositoryMock.Object, _mapperMock.Object);

            _usersRepositoryMock
            .Setup(r => r.GetByToken("KIT20IWP3LQ"))
            .Returns((User)null);

            // Act & Assert
            Should.Throw <UnauthorizedException>(() => sut.Save("KIT20IWP3LQ", new Reaction()));

            _mockRepository.VerifyAll();
        }
Example #10
0
        public void Delete_WhenUserNotAdmin_ThenThrowUnauthorizedException()
        {
            // Arrange
            var sut = new ReactionsService(_reactionsRepositoryMock.Object, _usersRepositoryMock.Object, _mapperMock.Object);

            var dummyUser = new User();

            _usersRepositoryMock
            .Setup(r => r.GetByToken("KIT20IWP3LQ"))
            .Returns(dummyUser);

            // Act & Assert
            Should.Throw <UnauthorizedException>(() => sut.Delete("KIT20IWP3LQ", It.IsAny <Guid>()));

            _mockRepository.VerifyAll();
        }
 public static Task <int> AddEmojiReactionEAsync(this ReactionsService service, ulong gid, DiscordEmoji emoji, IEnumerable <string> triggers, bool regex)
 => service.AddEmojiReactionAsync(gid, emoji.GetDiscordName(), triggers, regex);
 public static Task <int> RemoveEmojiReactionsEAsync(this ReactionsService service, ulong gid, DiscordEmoji emoji)
 => service.RemoveEmojiReactionsAsync(gid, emoji.GetDiscordName());