public SpamProbability GetSpamProbability(bool isUserSafe, params string[] messagesContent) { // Arrange var spamTestsService = new AntiSpamTestsService(); var userSafetyChecker = new Mock <IUserSafetyChecker>(); userSafetyChecker .Setup(x => x.IsUserSafe(AntiSpamTestsService.DEFAULT_TEST_USER_ID, GetMessagesQuery.GET_ALL_SERVERS)) .Returns(isUserSafe); var configurationService = new Mock <IConfigurationService>(); configurationService .Setup(x => x.GetConfigurationItem <PercentOfSimilarityBetweenMessagesToSuspectSpam>(It.IsAny <ulong>())) .Returns(new PercentOfSimilarityBetweenMessagesToSuspectSpam(GetMessagesQuery.GET_ALL_SERVERS)); var(request, contexts) = spamTestsService.CreateRequestAndContexts(messagesContent.Last()); var serverMessages = new ServerMessagesCacheService(); serverMessages.OverwriteMessages(messagesContent.SkipLast(1).Select(x => new SmallMessage(x, AntiSpamTestsService.DEFAULT_TEST_USER_ID, DateTime.Now, GetMessagesQuery.GET_ALL_SERVERS))); var needsConfiguration = typeof(T).GetConstructors().Any(x => x.GetParameters().Any(x => x.ParameterType == typeof(IConfigurationService))); var spamDetector = needsConfiguration ? (T)Activator.CreateInstance(typeof(T), userSafetyChecker.Object, configurationService.Object) : (T)Activator.CreateInstance(typeof(T), userSafetyChecker.Object); // Act return(spamDetector !.GetSpamProbability(serverMessages, request, contexts)); }
public void OverallSpamDetectorStrategy_ShouldNotDetectSpam(string messageContent1, string messageContent2, string messageContent3, string messageContent4, bool isUserSafe) { // Arrange var spamTestsService = new AntiSpamTestsService(); var userSafetyChecker = new Mock <IUserSafetyChecker>(); userSafetyChecker .Setup(x => x.IsUserSafe(AntiSpamTestsService.DEFAULT_TEST_USER_ID, GetMessagesQuery.GET_ALL_SERVERS)) .Returns(isUserSafe); var(request, contexts) = spamTestsService.CreateRequestAndContexts(messageContent4); var serverMessages = new ServerMessagesCacheService(); serverMessages.OverwriteMessages(new List <SmallMessage> { new SmallMessage(messageContent1, AntiSpamTestsService.DEFAULT_TEST_USER_ID, DateTime.Now, GetMessagesQuery.GET_ALL_SERVERS), new SmallMessage(messageContent2, AntiSpamTestsService.DEFAULT_TEST_USER_ID, DateTime.Now, GetMessagesQuery.GET_ALL_SERVERS), new SmallMessage(messageContent3, AntiSpamTestsService.DEFAULT_TEST_USER_ID, DateTime.Now, GetMessagesQuery.GET_ALL_SERVERS) }); var configurationService = new Mock <IConfigurationService>(); configurationService .Setup(x => x.GetConfigurationItem <PercentOfSimilarityBetweenMessagesToSuspectSpam>(It.IsAny <ulong>())) .Returns(new PercentOfSimilarityBetweenMessagesToSuspectSpam(GetMessagesQuery.GET_ALL_SERVERS)); var overallSpamDetector = OverallSpamDetectorStrategy.GetStrategyWithDefaultDetectors(serverMessages, userSafetyChecker.Object, configurationService.Object); // Act var overallSpamProbability = overallSpamDetector.GetOverallSpamProbability(request, contexts); // Assert Assert.That(overallSpamProbability, Is.EqualTo(SpamProbability.None)); }
public OverallSpamDetectorTests() { this._antiSpamTestsService = new AntiSpamTestsService(); this._configurationService = AntiSpamTestsService.GetConfigurationsMock().Object; }