Exemple #1
0
        public async Task NotifyAllProfiles()
        {
            var users = new List <SlackUser> {
                new SlackUser {
                    Id = "User1"
                }, new SlackUser {
                    Id = "User2"
                }
            };
            var creationResult = await CreateProfileBot(true);

            var slackIntegration = creationResult.SlackIntegration;

            slackIntegration.Setup(s => s.GetAllUsers()).ReturnsAsync(users);
            creationResult.SlackProfileChecker.Setup(s => s.ValidateProfile(It.IsAny <SlackUser>()))
            .Returns <SlackUser>(s => new ProfileValidationResult(false, s.Id, $"Error {s.Id}"));

            slackIntegration.Raise(s => s.MessageReceived += null,
                                   MessageParserTests.CreateMessage(adminUser.Id, "Notify all users"));

            slackIntegration.Verify(s => s.SendDirectMessage("User1", "Error User1"));
            slackIntegration.Verify(
                s => s.SendDirectMessage(adminUser.Id, "Error User1"));
            slackIntegration.Verify(s => s.SendDirectMessage("User2", "Error User2"));
            slackIntegration.Verify(
                s => s.SendDirectMessage(adminUser.Id, "Error User2"));
            slackIntegration.Verify(s => s.SendDirectMessage(adminUser.Id,
                                                             "2 users have bad profiles:\r\n<@User1>, <@User2>"));
        }
Exemple #2
0
        public async Task Version_ShowsVersion()
        {
            var creationResult = await CreateProfileBot(true);

            creationResult.SlackIntegration.Raise(s => s.MessageReceived += null, MessageParserTests.CreateMessage(adminUser, "version"));

            creationResult.SlackIntegration.Verify(s => s.IndicateTyping(It.Is <SlackUser>(u => u.Id == adminUser.Id)));
            creationResult.SlackIntegration.Verify(s => s.SendDirectMessage(It.Is <SlackUser>(u => u.Id == adminUser.Id), It.IsRegex("\\d*[.]\\d*[.]\\d*[.]\\d*")));
        }
Exemple #3
0
        public async Task UnknownCommand_AdminSendsMessage_ListsAvailableCommands()
        {
            var creationResult = await CreateProfileBot(true);

            var slackIntegration = creationResult.SlackIntegration;

            slackIntegration.Raise(s => s.MessageReceived += null,
                                   MessageParserTests.CreateMessage(adminUser.Id, "Unknown command"));

            slackIntegration.Verify(s => s.SendDirectMessage(adminUser.Id, $"Available commands are:{Environment.NewLine}- validate all users{Environment.NewLine}- notify all users{Environment.NewLine}- validate @user{Environment.NewLine}- notify @user"));
        }
Exemple #4
0
        public async Task WhitelistProfile()
        {
            var creationResult = await CreateProfileBot(true);

            var slackIntegration = creationResult.SlackIntegration;

            slackIntegration.Raise(s => s.MessageReceived += null,
                                   MessageParserTests.CreateMessage(adminUser, "Whitelist <@U1TBU8336>"));

            slackIntegration.Verify(s => s.IndicateTyping(It.Is <SlackUser>(u => u.Id == adminUser.Id)));
            creationResult.FaceWhitelistFake.Verify(f => f.WhitelistUser(It.Is <SlackUser>(s => s.Id == adminUser.Id)));
            slackIntegration.Verify(s => s.SendDirectMessage(It.Is <SlackUser>(u => u.Id == adminUser.Id), "Whitelisted <@U1TBU8336>"));
        }
Exemple #5
0
        public async Task InvalidMessage_AdminReportAlsoFails_DoesNotCrash()
        {
            var creationResult = await CreateProfileBot(true);

            var slackIntegration = creationResult.SlackIntegration;

            slackIntegration.Setup(s => s.SendDirectMessage(It.Is <SlackUser>(u => u.Id == adminUser.Id), It.IsRegex("I crashed"))).Throws(new Exception());
            slackIntegration.Setup(s => s.SendDirectMessage(It.Is <SlackUser>(u => u.Id == adminUser.Id), It.IsRegex("Available commands"))).Throws(new Exception());

            slackIntegration.Raise(s => s.MessageReceived += null, MessageParserTests.CreateMessage(adminUser, "Message"));

            slackIntegration.Verify(s => s.SendDirectMessage(It.Is <SlackUser>(u => u.Id == adminUser.Id), It.IsRegex("I crashed")));
        }
Exemple #6
0
        public async Task CommandFails()
        {
            var creationResult = await CreateProfileBot(true);

            var slackIntegration = creationResult.SlackIntegration;

            slackIntegration.Setup(s => s.GetUser(adminUser.Id)).Throws <Exception>();

            slackIntegration.Raise(s => s.MessageReceived += null,
                                   MessageParserTests.CreateMessage(adminUser.Id, "Notify <@U1TBU8336>"));

            slackIntegration.Verify(s => s.SendDirectMessage(adminUser.Id, "Notifying <@U1TBU8336>"));
            slackIntegration.Verify(s => s.SendDirectMessage(adminUser.Id, It.IsRegex("I crashed")));
        }
Exemple #7
0
        public async Task MessageInGroupChat_DoesNothing()
        {
            var creationResult = await CreateProfileBot(true);

            var slackIntegration = creationResult.SlackIntegration;
            var message          = MessageParserTests.CreateMessage(adminUser, "Unknown command");

            message.ChatHub = new SlackChatHub {
                Type = SlackChatHubType.Group
            };

            slackIntegration.Raise(s => s.MessageReceived += null, message);

            slackIntegration.Verify(s => s.SendDirectMessage(It.IsAny <SlackUser>(), It.IsAny <string>()), Times.Never());
        }
Exemple #8
0
        public async Task VerifyAllProfiles_NoProfileErrors()
        {
            var users = new List <SlackUser> {
                new SlackUser(), new SlackUser()
            };
            var creationResult = await CreateProfileBot(true);

            creationResult.SlackIntegration.Setup(s => s.GetAllUsers()).ReturnsAsync(users);
            creationResult.SlackProfileChecker.Setup(s => s.ValidateProfile(It.IsAny <SlackUser>()))
            .Returns(ProfileValidationResult.CreateValid());

            creationResult.SlackIntegration.Raise(s => s.MessageReceived += null,
                                                  MessageParserTests.CreateMessage(adminUser.Id, "validate all users"));

            creationResult.SlackIntegration.Verify(s => s.SendDirectMessage(adminUser.Id, "No profiles contain errors :)"));
        }
Exemple #9
0
        public async Task AnswerRegularUser_IncompleteProfile()
        {
            var user = new SlackUser {
                Id = "U1TBU8337"
            };
            var creationResult = await CreateProfileBot(true);

            var slackIntegration = creationResult.SlackIntegration;

            slackIntegration.Setup(s => s.GetUser("U1TBU8337")).ReturnsAsync(user);
            creationResult.SlackProfileChecker.Setup(s => s.ValidateProfile(It.IsAny <SlackUser>())).Returns <SlackUser>(s => new ProfileValidationResult(false, s.Id, $"Error {s.Id}"));

            slackIntegration.Raise(s => s.MessageReceived += null,
                                   MessageParserTests.CreateMessage("U1TBU8337", "Any message"));

            slackIntegration.Verify(s => s.SendDirectMessage("U1TBU8337", "Checking your profile"));
            slackIntegration.Verify(s => s.SendDirectMessage("U1TBU8337", "Error U1TBU8337"));
        }
Exemple #10
0
        public async Task NotifySingleProfile_ValidProfile()
        {
            var user = new SlackUser {
                Id = adminUser.Id
            };
            var creationResult = await CreateProfileBot(true);

            var slackIntegration = creationResult.SlackIntegration;

            slackIntegration.Setup(s => s.GetUser(adminUser.Id)).ReturnsAsync(user);
            creationResult.SlackProfileChecker.Setup(s => s.ValidateProfile(It.IsAny <SlackUser>())).Returns(ProfileValidationResult.CreateValid());

            slackIntegration.Raise(s => s.MessageReceived += null,
                                   MessageParserTests.CreateMessage(adminUser.Id, "Notify <@U1TBU8336>"));

            slackIntegration.Verify(s => s.SendDirectMessage(adminUser.Id, "Notifying <@U1TBU8336>"));
            slackIntegration.Verify(s => s.SendDirectMessage(adminUser.Id, "<@U1TBU8336> has a complete profile"));
        }
Exemple #11
0
        public async Task VerifySingleProfile_IncompleteProfile()
        {
            var user = new SlackUser {
                Id = adminUser.Id
            };
            var creationResult = await CreateProfileBot(true);

            var slackIntegration = creationResult.SlackIntegration;

            slackIntegration.Setup(s => s.GetUser(adminUser.Id)).ReturnsAsync(user);
            creationResult.SlackProfileChecker.Setup(s => s.ValidateProfile(It.IsAny <SlackUser>())).Returns <SlackUser>(s => new ProfileValidationResult(false, s.Id, $"Error {s.Id}"));

            slackIntegration.Raise(s => s.MessageReceived += null,
                                   MessageParserTests.CreateMessage(adminUser.Id, "Validate <@U1TBU8336>"));

            slackIntegration.Verify(s => s.SendDirectMessage(adminUser.Id, "Validating <@U1TBU8336>"));
            slackIntegration.Verify(s => s.SendDirectMessage(adminUser.Id, "Error U1TBU8336"));
        }
Exemple #12
0
        public async Task AnswerRegularUser_ValidProfile()
        {
            var user = new SlackUser {
                Id = "U1TBU8337"
            };
            var creationResult = await CreateProfileBot(true);

            var slackIntegration = creationResult.SlackIntegration;

            slackIntegration.Setup(s => s.GetUser("U1TBU8337")).ReturnsAsync(user);
            creationResult.SlackProfileChecker.Setup(s => s.ValidateProfile(It.IsAny <SlackUser>())).ReturnsAsync(ValidResult());

            slackIntegration.Raise(s => s.MessageReceived += null,
                                   MessageParserTests.CreateMessage(user, "Any message"));

            slackIntegration.Verify(s => s.SendDirectMessage(user, "Checking your profile"));
            slackIntegration.Verify(s => s.SendDirectMessage(user, "Well done <@U1TBU8337>, your profile is complete"));
        }
Exemple #13
0
        public async Task Whitelist_ShowWhitelistedUsers()
        {
            var creationResult = await CreateProfileBot(true);

            var slackIntegration = creationResult.SlackIntegration;

            creationResult.FaceWhitelistFake.Setup(w => w.GetWhitelistedUsers()).ReturnsAsync(new[] { new SlackUser {
                                                                                                          Id = "U1TBU8336"
                                                                                                      }, new SlackUser {
                                                                                                          Id = "U1TBU8346"
                                                                                                      } });

            slackIntegration.Raise(s => s.MessageReceived += null, MessageParserTests.CreateMessage(adminUser, "Whitelist"));

            slackIntegration.Verify(s => s.IndicateTyping(It.Is <SlackUser>(u => u.Id == adminUser.Id)));
            creationResult.FaceWhitelistFake.Verify(f => f.GetWhitelistedUsers());
            slackIntegration.Verify(s => s.SendDirectMessage(It.Is <SlackUser>(u => u.Id == adminUser.Id), "Whitelist: <@U1TBU8336>, <@U1TBU8346>"));
        }
Exemple #14
0
        public async Task VerifyAllProfiles()
        {
            var users = new List <SlackUser> {
                new SlackUser {
                    Id = "User1"
                }, new SlackUser {
                    Id = "User2"
                }
            };
            var creationResult = await CreateProfileBot(true);

            creationResult.SlackIntegration.Setup(s => s.GetAllUsers()).ReturnsAsync(users);
            creationResult.SlackProfileChecker.Setup(s => s.ValidateProfile(It.IsAny <SlackUser>()))
            .Returns <SlackUser>(s => Task.FromResult(FailedResult(s.Id)));

            creationResult.SlackIntegration.Raise(s => s.MessageReceived += null,
                                                  MessageParserTests.CreateMessage(adminUser, "validate all users"));

            creationResult.SlackIntegration.Verify(s => s.SendDirectMessage(It.Is <SlackUser>(u => u.Id == adminUser.Id), "2 users have bad profiles:\r\n<@User1>, <@User2>"));
        }