public TestBaseClassTemplate(ProjectModelBase unitTestProjectLocation, UnitTestCreationDetails unitTestCreationOptions) { this.unitTestProjectLocation = unitTestProjectLocation; this.unitTestCreationOptions = unitTestCreationOptions; this.usings.Add(this.unitTestCreationOptions.ClassUnderTestNamespace); this.usings.AddRange(this.unitTestCreationOptions.ClassUnderTestConstructor.Parameters.SelectMany(p => p.Namespaces)); }
public async Task <MethodUnderTestAnalyzerResult> AnalyzeAsync() { var componentModel = await this.asyncServiceProvider.GetAsAsync <SComponentModel, IComponentModel>(); var methodUnderTest = await this.GetMethodUnderTestAsync(componentModel); var unitTestCreationDetails = new UnitTestCreationDetails(methodUnderTest); var recommendedLocation = this.CalculateRecommendedUnitTestLocation(methodUnderTest, unitTestCreationDetails, componentModel); return(new MethodUnderTestAnalyzerResult(unitTestCreationDetails, recommendedLocation)); }
public UnitTestCreationOptions( ProjectModelBase locationForTest, UnitTestCreationDetails unitTestCreationDetails, bool shouldCreateParentFolder, bool shouldCreateUnitTestBaseClass) { this.LocationForTest = locationForTest; this.UnitTestCreationDetails = unitTestCreationDetails; this.ShouldCreateParentFolder = shouldCreateParentFolder; this.ShouldCreateUnitTestBaseClass = shouldCreateUnitTestBaseClass; }
private string GetInnerPathFromProject(Project projectUnderTest, UnitTestCreationDetails unitTestCreationDetails) { string namespaceAfterProject = string.Empty; var classUnderTestNamespace = unitTestCreationDetails.ClassUnderTestNamespace; if (classUnderTestNamespace.Contains(projectUnderTest.Name)) { namespaceAfterProject = this.GetNamespaceSubstring(projectUnderTest.Name, classUnderTestNamespace); } else if (classUnderTestNamespace.Contains(projectUnderTest.AssemblyName)) { namespaceAfterProject = this.GetNamespaceSubstring(projectUnderTest.AssemblyName, classUnderTestNamespace); } return(namespaceAfterProject); }
private RecommendedUnitTestLocationInfo CalculateRecommendedUnitTestLocation(MethodUnderTestInfo methodUnderTest, UnitTestCreationDetails unitTestCreationDetails, IComponentModel componentModel) { var workspace = componentModel.GetService <VisualStudioWorkspace>(); var documentToTest = workspace.CurrentSolution.GetDocumentIdsWithFilePath(methodUnderTest.Document.FilePath).FirstOrDefault(); var projectUnderTest = workspace.CurrentSolution.GetProject(documentToTest.ProjectId); var recommendedUnitTestProject = this.GetRecommendedUnitTestProject(workspace, projectUnderTest); var recommendedUnitTestPathFromProject = this.GetInnerPathFromProject(projectUnderTest, unitTestCreationDetails); return(new RecommendedUnitTestLocationInfo(recommendedUnitTestProject, recommendedUnitTestPathFromProject)); }
public MethodUnderTestAnalyzerResult(UnitTestCreationDetails unitTestCreationDetails, RecommendedUnitTestLocationInfo recommendedLocation) { this.UnitTestCreationDetails = unitTestCreationDetails; this.RecommendedUnitTestLocationInfo = recommendedLocation; }