public IListExpression <TRequest, TEntity, TResult> Search(Expression <Func <TRequest, ISearch> > property, Action <ISearchExpression <TRequest, TEntity, TResult> > action = null) { var expression = new SearchExpression <TRequest, TEntity, TResult>(property); action?.Invoke(expression); SearchDefinitions.Add(property.GetPropertyInfo(), expression); return(this); }
public void Setup() { searchDefinitions = CreateDefinitions(definitionsCount); (string, Mock <IFileSystem>)result = PrepareFileSystemMock(); searchDefinitionsPath = result.Item1; fileSystemMock = result.Item2; }
public void LoadPatternFiles_WhenDirectoryDoesExistWithFiles_ShouldReturnRules() { const string SpamDirectory = ".spam"; const string ProjectDirectory = @"C:\some-project-folder"; var definitions = new SearchDefinitions() { Definitions = new List <SearchDefinition> { new SearchDefinition() { Name = "MinimalRule", Id = "Test1002", Level = FailureLevel.Error, FileNameAllowRegex = "(?i)\\.test$", Message = "A problem occurred in '{0:scanTarget}'.", MatchExpressions = new List <MatchExpression>(new[] { new MatchExpression() { ContentsRegex = "foo", Fixes = new Dictionary <string, SimpleFix>() { { "convertToPublic", new SimpleFix() { Description = "Make class public.", Find = "foo", ReplaceWith = "bar" } } } } }) } } }; string definitionsText = JsonConvert.SerializeObject(definitions); var mockFileSystem = new Mock <IFileSystem>(); mockFileSystem.Setup(fs => fs.DirectoryExists(It.IsAny <string>())).Returns(false); mockFileSystem.Setup(fs => fs.DirectoryExists(Path.Combine(ProjectDirectory, SpamDirectory))).Returns(true); mockFileSystem.Setup(fs => fs.DirectoryEnumerateFiles(It.IsAny <string>(), It.IsAny <string>(), SearchOption.AllDirectories)).Returns(new string[] { Guid.NewGuid().ToString() }); mockFileSystem.Setup(fs => fs.FileReadAllText(It.IsAny <string>())).Returns(definitionsText); ISet <Skimmer <AnalyzeContext> > rules = SpamBackgroundAnalyzer.LoadSearchDefinitionsFiles(mockFileSystem.Object, ProjectDirectory); rules.Should().HaveCount(1); rules.First().Id.Should().Be("Test1002"); }
private static SearchDefinitions CreateDefinitions(int count) { var searchDefinitions = new SearchDefinitions() { Definitions = new List <SearchDefinition>(count) }; var random = new Random(); for (int i = 0; i < count; i++) { searchDefinitions.Definitions.Add(new SearchDefinition() { Name = "MinimalRule", Id = $"Test100{random.Next(count)}", Level = FailureLevel.Error, FileNameAllowRegex = "(?i)\\.test$", Message = "A problem occurred in '{0:scanTarget}'.", MatchExpressions = new List <MatchExpression>(new[] { new MatchExpression() { ContentsRegex = "foo", Fixes = new Dictionary <string, SimpleFix>() { { "convertToPublic", new SimpleFix() { Description = "Make class public.", Find = "foo", ReplaceWith = "bar" } } } } }) }); } return(searchDefinitions); }