public void BeforeCompile(IBeforeCompileContext context) { JObject rawProjectFile = null; using (var fs = File.OpenRead(context.ProjectContext.ProjectFilePath)) { rawProjectFile = JObject.Load(new JsonTextReader(new StreamReader(fs))); } var excludePatterns = PatternsCollectionHelper.GetPatternsCollection( rawProjectFile, context.ProjectContext.ProjectDirectory, context.ProjectContext.ProjectFilePath, "exclude", DefaultExcludePatterns); var matcher = new Matcher(); matcher.AddInclude("**/*.resx").AddExcludePatterns(excludePatterns); var resXFiles = matcher.GetResultsInFullPath(context.ProjectContext.ProjectDirectory); foreach (var resXFile in resXFiles) { WriteResourceFile(resXFile); } }
public void It_returns_empty_when_there_is_no_property_and_no_default_pattern() { var json = new JObject(); var patternsCollection = PatternsCollectionHelper.GetPatternsCollection( json, AppContext.BaseDirectory, string.Empty, "some non-existing property"); patternsCollection.Should().BeEmpty(); }
public void It_uses_the_passed_in_default_collection_when_the_property_is_not_in_the_json() { var json = new JObject(); var patternsCollection = PatternsCollectionHelper.GetPatternsCollection( json, AppContext.BaseDirectory, string.Empty, "some non-existing property", SomeDefaultValues); patternsCollection.Should().Contain(SomeDefaultValues); }
public void It_throws_when_the_property_value_is_neither_a_string_nor_an_array() { var json = new JObject(); json.Add(SomeProperty, new JObject()); Action action = () => PatternsCollectionHelper.GetPatternsCollection( json, AppContext.BaseDirectory, string.Empty, SomeProperty, SomeDefaultValues); action.ShouldThrow <FileFormatException>().WithMessage("Value must be either string or array."); }
public void It_uses_the_value_in_the_property_when_it_is_a_string() { var json = new JObject(); json.Add(SomeProperty, "*"); var patternsCollection = PatternsCollectionHelper.GetPatternsCollection( json, AppContext.BaseDirectory, string.Empty, SomeProperty, SomeDefaultValues); patternsCollection.Should().Contain("*"); }
public void It_uses_the_values_in_the_property_when_it_is_a_string_array() { var patterns = new[] { "*", $"**{Path.DirectorySeparatorChar}*.fs" }; var json = new JObject(); json.Add(SomeProperty, new JArray(patterns)); var patternsCollection = PatternsCollectionHelper.GetPatternsCollection( json, AppContext.BaseDirectory, string.Empty, SomeProperty, SomeDefaultValues); patternsCollection.Should().Contain(patterns); }
public void It_throws_when_we_ask_for_a_literal_and_specify_a_pattern() { var json = new JObject(); json.Add(SomeProperty, "*"); Action action = () => PatternsCollectionHelper.GetPatternsCollection( json, AppContext.BaseDirectory, string.Empty, SomeProperty, SomeDefaultValues, true); action.ShouldThrow <FileFormatException>() .WithMessage($"The '{SomeProperty}' property cannot contain wildcard characters."); }
public void It_throws_when_the_property_value_is_a_rooted_path() { var json = new JObject(); json.Add(SomeProperty, AppContext.BaseDirectory); Action action = () => PatternsCollectionHelper.GetPatternsCollection( json, AppContext.BaseDirectory, string.Empty, SomeProperty, SomeDefaultValues, true); action.ShouldThrow <FileFormatException>() .WithMessage($"The '{SomeProperty}' property cannot be a rooted path."); }