Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to specify wildcard for a model file name #7

Merged
merged 1 commit into from
Jul 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Several improvements have been implemented:
* Summarize how many tests passed/failed/etc
* Show tests without a category
* Ability to clear console output
* Clear indication when model files for tests can't be found
* Ability to specify a wildcard for the model filename
* All console messages are marshaled back from the test and displayed by the runner
* Test completion information is displayed in the console out as soon as the test itself is completed

Expand Down Expand Up @@ -52,7 +54,7 @@ Provides a visual interface for you to choose tests from a treeview and to visua

The input fields to set the test assembly, the working directory, and the results file, as well as the tree view where available tests are displayed, support dragging and dropping of files and folders.

![Image](https://user-images.githubusercontent.com/3942418/28271251-0822ae5c-6ad6-11e7-8028-4f2f5c03823e.png)
![RTF](RTF.png)

`File` - For saving and loading your local RTF config.

Expand Down
Binary file added RTF.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions src/Applications/RevitTestFrameworkGUI/RunnerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,6 @@ public string TestAssembly
set
{
runner.TestAssembly = value;
runner.InitializeTests();
UpdateTestCounts();
RaisePropertyChanged();
RaisePropertyChanged(nameof(Assemblies));

RaisePropertyChanged(nameof(SelectedProductIndex));

// Infer working directory from assembly, if the user hasn't set it yet
if (!workingDirSetByUser)
Expand All @@ -355,6 +349,12 @@ public string TestAssembly
{
SetResultsPath(Path.Combine(WorkingDirectory, "results.xml"));
}

runner.InitializeTests();
UpdateTestCounts();
RaisePropertyChanged();
RaisePropertyChanged(nameof(Assemblies));
RaisePropertyChanged(nameof(SelectedProductIndex));
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Framework/RevitTestFramework/Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace RTF.Framework
public class TestModelAttribute : Attribute
{
public string Path { get; private set; }
public bool IsWildcard => (Path.ToLowerInvariant().EndsWith("*.rvt") || Path.ToLowerInvariant().EndsWith("*.rfa"));

public TestModelAttribute(string path)
{
Expand Down
97 changes: 56 additions & 41 deletions src/Framework/Runner/AssemblyLoader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
Expand All @@ -21,7 +22,7 @@ public AssemblyLoader(RTFAssemblyResolver resolver)

public AssemblyData ReadAssembly(string assemblyPath, GroupingType groupType, string workingDirectory)
{
var assembly = Assembly.ReflectionOnlyLoadFrom(assemblyPath);
var assembly = Assembly.LoadFrom(assemblyPath);

var data = new AssemblyData(assemblyPath, assembly.GetName().Name, groupType);

Expand Down Expand Up @@ -93,7 +94,7 @@ public static bool ReadFixture(Type fixtureType, IAssemblyData data, string work
public static bool ReadTest(MethodInfo test, IFixtureData data, string workingDirectory)
{
//set the default modelPath to the empty.rfa file that will live in the build directory
string modelPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "empty.rfa");
List<string> modelPaths = new List<string>();

var testAttribs = CustomAttributeData.GetCustomAttributes(test);

Expand All @@ -104,65 +105,79 @@ public static bool ReadTest(MethodInfo test, IFixtureData data, string workingDi
return false;
}

var testModelAttrib =
testAttribs.FirstOrDefault(x => x.Constructor.DeclaringType.Name == "TestModelAttribute");
TestModelAttribute testModelAttrib = (TestModelAttribute)test.GetCustomAttribute(typeof(TestModelAttribute));

if (testModelAttrib != null)
{
//overwrite the model path with the one
//specified in the test model attribute
var relModelPath = testModelAttrib.ConstructorArguments.FirstOrDefault().Value.ToString();
if (workingDirectory == null)
string absolutePath;

if (Path.IsPathRooted(testModelAttrib.Path))
{
// If the working directory is not specified.
// Add the relative path to the assembly's path.
modelPath =
Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
relModelPath));
absolutePath = testModelAttrib.Path;
}
else
{
modelPath = Path.GetFullPath(Path.Combine(workingDirectory, relModelPath));
if (workingDirectory == null)
{
// If the working directory is not specified.
// Add the relative path to the assembly's path.
absolutePath = Path.GetFullPath(
Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), testModelAttrib.Path));
}
else
{
absolutePath = Path.GetFullPath(Path.Combine(workingDirectory, testModelAttrib.Path));
}
}
}

var runDynamoAttrib =
testAttribs.FirstOrDefault(x => x.Constructor.DeclaringType.Name == "RunDynamoAttribute");

var runDynamo = false;
if (runDynamoAttrib != null)
if (testModelAttrib.IsWildcard)
{
modelPaths.AddRange(Directory.GetFiles(Path.GetDirectoryName(absolutePath), Path.GetFileName(absolutePath), SearchOption.AllDirectories));
}
else
{
modelPaths.Add(absolutePath);
}
}
else
{
runDynamo = Boolean.Parse(runDynamoAttrib.ConstructorArguments.FirstOrDefault().Value.ToString());
modelPaths.Add(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "empty.rfa"));
}

var testData = new TestData(data, test.Name, modelPath, runDynamo);
data.Tests.Add(testData);
var runDynamoAttrib = (RunDynamoAttribute)test.GetCustomAttribute(typeof(RunDynamoAttribute));
var runDynamo = runDynamoAttrib?.RunDynamo ?? false;

const string EmptyCategory = "[NO CATEGORY]";
foreach (string modelPath in modelPaths)
{
var testData = new TestData(data, test.Name, modelPath, runDynamo);
data.Tests.Add(testData);

var category = string.Empty;
var categoryAttribs =
testAttribs.Where(x => x.Constructor.DeclaringType.Name == "CategoryAttribute");
const string EmptyCategory = "[NO CATEGORY]";

if (categoryAttribs.Any())
{
foreach (var categoryAttrib in categoryAttribs)
var category = string.Empty;
var categoryAttribs =
testAttribs.Where(x => x.Constructor.DeclaringType.Name == "CategoryAttribute");

if (categoryAttribs.Any())
{
category = categoryAttrib.ConstructorArguments.FirstOrDefault().Value.ToString();
if (String.IsNullOrEmpty(category))
foreach (var categoryAttrib in categoryAttribs)
{
category = EmptyCategory;
}
category = categoryAttrib.ConstructorArguments.FirstOrDefault().Value.ToString();
if (String.IsNullOrEmpty(category))
{
category = EmptyCategory;
}

AddWithCategory(data, category, testData);
AddWithCategory(data, category, testData);
}
}
else
{
AddWithCategory(data, EmptyCategory, testData);
}
}
else
{
AddWithCategory(data, EmptyCategory, testData);
}

Console.WriteLine("Loaded test: {0}", testData);
Console.WriteLine($"Loaded test: {testData} ({modelPath})");
}

return true;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Framework/Runner/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,9 @@ private bool SetupIndividualTest(
ModelSemantics modelSemantics = ModelSemantics.Open | ModelSemantics.Close)
{
if (td.ShouldRun == false)
{
return true;
}

try
{
Expand Down Expand Up @@ -1766,7 +1768,7 @@ public virtual IList<IAssemblyData> ReadAssembly(string assemblyPath, string wor
{
if (!((TestData)test).ModelExists)
{
Console.WriteLine($"WARNING: model {test.ModelPath} not found for test {test.Fixture}.{test.Name}");
Console.WriteLine($"WARNING: model {test.ModelPath} not found for test {test.Fixture.Name}.{test.Name}");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/RevitTestFramework.nuspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
<metadata>
<version>1.19.10</version>
<version>1.19.11</version>
<authors>Dynamo, Mark Vulfson</authors>
<owners>Dynamo, Mark Vulfson</owners>
<licenseUrl>https://github.com/marchello2000/RevitTestFramework#license</licenseUrl>
Expand Down