Example #1
0
        public void SpamPunishmentStrategy_ShouldNotGiveAnyPunishment(int userWarnsCount, SpamProbability spamProbability)
        {
            // Arrange
            var punishmentsCachingService = new Mock <IPunishmentsCachingService>();

            punishmentsCachingService
            .Setup(x => x.GetUserWarnsCount(AntiSpamTestsService.DEFAULT_TEST_USER_ID, It.IsAny <DateTime>()))
            .Returns(userWarnsCount);
            var punishmentStrategy = new SpamPunishmentStrategy(punishmentsCachingService.Object);

            // Act
            var punishment = punishmentStrategy.GetPunishment(AntiSpamTestsService.DEFAULT_TEST_USER_ID, spamProbability);

            // Assert
            Assert.That(punishment.PunishmentOption, Is.EqualTo(PunishmentOption.Nothing));
        }
Example #2
0
        public void SpamPunishmentStrategy_ShouldGiveMuteForTime(int userMutesCount, int expectedMinutesOfMute)
        {
            // Arrange
            var punishmentsCachingService = new Mock <IPunishmentsCachingService>();

            punishmentsCachingService
            .Setup(x => x.GetUserWarnsCount(AntiSpamTestsService.DEFAULT_TEST_USER_ID, It.IsAny <DateTime>()))
            .Returns(100);     // to be sure that strategy always will give mute
            punishmentsCachingService
            .Setup(x => x.GetUserMutesCount(AntiSpamTestsService.DEFAULT_TEST_USER_ID, It.IsAny <DateTime>()))
            .Returns(userMutesCount);
            var punishmentStrategy = new SpamPunishmentStrategy(punishmentsCachingService.Object);

            // Act
            var punishment = punishmentStrategy.GetPunishment(AntiSpamTestsService.DEFAULT_TEST_USER_ID, SpamProbability.Sure);

            // Assert
            Assert.That(punishment.ForTime, Is.Not.Null);
            Assert.That(punishment.ForTime.Value.TotalMinutes, Is.EqualTo(expectedMinutesOfMute));
        }