Best SpecFlow code snippet using TechTalk.SpecFlow.Generator.Project.MSBuildRelativePathParser
MSBuildRelativePathParserTests.cs
Source:MSBuildRelativePathParserTests.cs
...6using TechTalk.SpecFlow.Generator.Project;7namespace TechTalk.SpecFlow.GeneratorTests8{9 10 public class MSBuildRelativePathParserTests11 {12 private string _directoryName;13 public MSBuildRelativePathParserTests()14 {15#if NET46116 string assemblyLocation = GetType().Assembly.CodeBase;17#else18 string assemblyLocation = GetType().Assembly.Location;19#endif20 string assemblyFolder = Path.GetDirectoryName(new Uri(assemblyLocation).LocalPath);21 _directoryName = Path.Combine(assemblyFolder, "Data");22 }23 [Fact]24 public void GetFiles_PathWithoutWildcards_ReturnsPath()25 {26 //ARRANGE27 var msBuildRelativePathParser = new MSBuildRelativePathParser();28 //ACT29 var files = msBuildRelativePathParser.GetFiles(_directoryName, PathHelper.SanitizeDirectorySeparatorChar(@"ExampleFeatures\Features\Subfolder1\ExternalFeature1.feature"));30 //ASSERT31 files.Should().Contain(PathHelper.SanitizeDirectorySeparatorChar(@"ExampleFeatures\Features\Subfolder1\ExternalFeature1.feature"));32 files.Count.Should().Be(1);33 }34 [Fact]35 public void GetFiles_PathWithFileWildcards_ReturnsPath()36 {37 //ARRANGE38 var msBuildRelativePathParser = new MSBuildRelativePathParser();39 //ACT40 var files = msBuildRelativePathParser.GetFiles(_directoryName, PathHelper.SanitizeDirectorySeparatorChar(@"ExampleFeatures\Features\Subfolder1\*.feature"));41 //ASSERT42 files.Should().Contain(PathHelper.SanitizeDirectorySeparatorChar(@"ExampleFeatures\Features\Subfolder1\ExternalFeature1.feature"));43 files.Count.Should().Be(1);44 }45 [Fact]46 public void GetFiles_PathWithPathWildcards_ReturnsPath()47 {48 //ARRANGE49 var msBuildRelativePathParser = new MSBuildRelativePathParser();50 //ACT51 var files = msBuildRelativePathParser.GetFiles(_directoryName, PathHelper.SanitizeDirectorySeparatorChar(@"ExampleFeatures\Features\**\*.feature"));52 //ASSERT53 files.Should().Contain(PathHelper.SanitizeDirectorySeparatorChar(@"ExampleFeatures\Features\Subfolder1\ExternalFeature1.feature"));54 files.Should().Contain(PathHelper.SanitizeDirectorySeparatorChar(@"ExampleFeatures\Features\Subfolder2\ExternalFeature2.feature"));55 files.Count.Should().Be(2);56 }57 [Fact]58 public void GetFiles_RelativePathWithFileWildcards_ReturnsPath()59 {60 //ARRANGE61 var msBuildRelativePathParser = new MSBuildRelativePathParser();62 //ACT63 var files = msBuildRelativePathParser.GetFiles(_directoryName, PathHelper.SanitizeDirectorySeparatorChar(@"..\Data\ExampleFeatures\Features\Subfolder1\*.feature"));64 //ASSERT65 files.Should().Contain(PathHelper.SanitizeDirectorySeparatorChar(@"..\Data\ExampleFeatures\Features\Subfolder1\ExternalFeature1.feature"));66 files.Count.Should().Be(1);67 }68 }69}...
MSBuildRelativePathParser.cs
Source:MSBuildRelativePathParser.cs
...3using System.IO;4using System.Linq;5namespace TechTalk.SpecFlow.Generator.Project6{7 public interface IMSBuildRelativePathParser8 {9 List<string> GetFiles(string projectFolder, string path);10 }11 class MSBuildRelativePathParser : IMSBuildRelativePathParser12 {13 public List<string> GetFiles(string projectFolder, string path)14 {15 var searchOption = path.Contains("**") ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;16 if (path.Contains("*"))17 {18 var split = path.Split(new[] { "*" }, StringSplitOptions.RemoveEmptyEntries);19 var realPath = split.Take(split.Length - 1).Aggregate((current, next) => current + next).Replace($"{Path.DirectorySeparatorChar}{Path.DirectorySeparatorChar}", $"{Path.DirectorySeparatorChar}");20 var fileName = split.Last();21 return Directory.GetFiles(Path.Combine(projectFolder, realPath), "*" + fileName, searchOption)22 .Select(i => i.Replace(projectFolder + Path.DirectorySeparatorChar, ""))23 .ToList();24 }25 return new List<string>() { path };...
MSBuildRelativePathParser
Using AI Code Generation
1using TechTalk.SpecFlow.Generator.Project;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 static void Main(string[] args)10 {11 var parser = new MSBuildRelativePathParser();
MSBuildRelativePathParser
Using AI Code Generation
1using System;2using TechTalk.SpecFlow.Generator.Project;3{4 {5 static void Main(string[] args)6 {7 var parser = new MSBuildRelativePathParser();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!