Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ pip-log.txt

#Mr Developer
.mr.developer.cfg

packages/*
src/AssemblySharedInfoGenerator/AssemblySharedInfo.cs
test/Libraries/RevitIntegrationTests/RevitTestConfiguration.xml
test/**/*.txt
Expand All @@ -225,3 +227,4 @@ test/SystemInJson

# Icon resources
/src/DynamoRevitIcons/*.resources
logs/*
198 changes: 198 additions & 0 deletions test/Libraries/RevitIntegrationTests/OOTB_D4R_SampleTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
using System;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using Dynamo.Graph.Nodes;
using NUnit.Framework;
using RevitTestServices;
using RTF.Framework;

namespace RevitSystemTests
{
/// <summary>
/// Tests for the Out-of-the-Box (OOTB) D4R sample scripts shipped as part of the
/// revit-d4r-content-samples artifact.
///
/// The .dyn files are resolved at runtime via <see cref="SetupUnzip"/> which checks,
/// in order:
/// 1. The already-deployed samples at DynamoForRevit\samples\en-US\Revit\.
/// 2. A previously-extracted cache in the user's temp directory.
/// 3. A revit-d4r-content-samples-*-net10.zip in the samples directory (extracts to temp).
Comment thread
Fusneica-FlorentinCristian marked this conversation as resolved.
Outdated
/// </summary>
[TestFixture]
class OOTB_D4R_SampleTests : RevitSystemTestBase
{
private static string SetupUnzip(string scriptFileName)
{
string assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Comment thread
Fusneica-FlorentinCristian marked this conversation as resolved.

// When deployed to Revit:
// assemblyDir = DynamoForRevit\Revit\
// parentDir = DynamoForRevit\
string parentDir = Path.GetDirectoryName(assemblyDir);

string samplesFolder = Path.Combine(parentDir, "samples");
Comment thread
Fusneica-FlorentinCristian marked this conversation as resolved.
string extractedSamplesPath = Path.Combine(Path.GetTempPath(), "D4RSamples");
string installedSamplesPath = Path.Combine(samplesFolder, @"en-US\Revit");

Comment thread
Fusneica-FlorentinCristian marked this conversation as resolved.
// Priority 1: already-deployed samples (standard Revit install)
if (Directory.Exists(installedSamplesPath))
{
var resolved = Path.Combine(installedSamplesPath, scriptFileName);
if (File.Exists(resolved))
return resolved;
}

Comment thread
Fusneica-FlorentinCristian marked this conversation as resolved.
// Priority 2: zip was already extracted from a previous test run
if (Directory.Exists(extractedSamplesPath))
{
var resolved = Path.Combine(extractedSamplesPath, @"Samples\en-US\Revit", scriptFileName);
if (File.Exists(resolved))
return resolved;
}
Comment thread
Fusneica-FlorentinCristian marked this conversation as resolved.
Outdated

// Priority 3: zip file is present — extract on first use
if (Directory.Exists(samplesFolder))
{
var zipFiles = Directory.GetFiles(
samplesFolder,
"revit-d4r-content-samples-*-net10.zip")
.OrderBy(path => path)
.ToArray();

if (zipFiles.Length > 1)
{
var matches = zipFiles.Select(path => $"\n {path}");
throw new InvalidOperationException(
$"Multiple revit-d4r-content-samples archives were found in '{samplesFolder}', " +
$"so the OOTB D4R sample source is ambiguous. Ensure exactly one matching zip is present." +
$"{string.Concat(matches)}");
}

if (zipFiles.Length == 1)
{
ZipFile.ExtractToDirectory(zipFiles[0], extractedSamplesPath, overwriteFiles: true);
var resolved = Path.Combine(extractedSamplesPath, @"Samples\en-US\Revit", scriptFileName);
if (File.Exists(resolved))
return resolved;
Comment thread
Fusneica-FlorentinCristian marked this conversation as resolved.
Outdated
}
}

// Provide a useful diagnostic message to help locate the issue
if (Directory.Exists(samplesFolder))
{
var entries = Directory.EnumerateFileSystemEntries(samplesFolder)
.Select(e => $"\n {e}");
throw new FileNotFoundException(
$"Cannot locate OOTB D4R sample script '{scriptFileName}'.\n" +
$"Checked samples folder: {samplesFolder}\n" +
$"Contents:{string.Concat(entries)}");
Comment thread
Fusneica-FlorentinCristian marked this conversation as resolved.
}
else
{
var parentEntries = Directory.Exists(parentDir)
? Directory.EnumerateDirectories(parentDir).Select(e => $"\n {e}")
: Enumerable.Empty<string>();
throw new FileNotFoundException(
$"Cannot locate OOTB D4R sample script '{scriptFileName}'.\n" +
$"Expected samples folder not found: {samplesFolder}\n" +
$"Parent dir contents:{string.Concat(parentEntries)}");
}
}

private void OpenAndRunSample(string scriptFileName)
{
string samplePath = SetupUnzip(scriptFileName);
string testPath = Path.GetFullPath(samplePath);

ViewModel.OpenCommand.Execute(testPath);

AssertNoDummyNodes();

RunCurrentModel();

var errorNodes = ViewModel.Model.CurrentWorkspace.Nodes.Where(
n => n.State == ElementState.Error || n.State == ElementState.Warning).ToList();
Comment thread
Fusneica-FlorentinCristian marked this conversation as resolved.

if (errorNodes.Any())
{
var details = string.Join("\n",
errorNodes.Select(n => $" [{n.State}] {n.Name} ({n.GUID})"));
Assert.Fail(
$"After RunCurrentModel(), {errorNodes.Count} node(s) are in error/warning state " +
$"in '{scriptFileName}':\n{details}");
}
}

[Test, Category("SmokeTests")]
[TestModel(@".\empty.rfa")]
public void Revit_Geometry_Creation_Points()
{
OpenAndRunSample("Revit Geometry Creation Points.dyn");
}

[Test, Category("SmokeTests")]
[TestModel(@".\Samples\Snowdon Towers Sample Architectural.rvt")]
Comment thread
Fusneica-FlorentinCristian marked this conversation as resolved.
Outdated
public void Revit_Geometry_Creation_Curves()
{
OpenAndRunSample("Revit Geometry Creation Curves.dyn");
}

[Test, Category("SmokeTests")]
[TestModel(@".\ConceptualMass.rfa")]
public void Revit_Geometry_Creation_Solids()
{
OpenAndRunSample("Revit Geometry Creation Solids.dyn");
}

[Test, Category("SmokeTests")]
[TestModel(@".\ConceptualMass.rfa")]
Comment thread
Fusneica-FlorentinCristian marked this conversation as resolved.
Outdated
Comment thread
Fusneica-FlorentinCristian marked this conversation as resolved.
Outdated
public void Revit_Geometry_Creation_Surfaces()
{
OpenAndRunSample("Revit Geometry Creation Surfaces.dyn");
}

[Test, Category("SmokeTests")]
[TestModel(@".\Samples\Snowdon Towers Sample Architectural.rvt")]
public void Revit_Adaptive_Component_Placement()
{
OpenAndRunSample("Revit Adaptive Component Placement.dyn");
}

[Test, Category("SmokeTests")]
[TestModel(@".\Samples\Snowdon Towers Sample Architectural.rvt")]
public void Revit_Color()
Comment thread
Fusneica-FlorentinCristian marked this conversation as resolved.
{
OpenAndRunSample("Revit Color.dyn");
}

[Test, Category("SmokeTests")]
[TestModel(@".\Samples\Snowdon Towers Sample Architectural.rvt")]
public void Revit_Floors_and_Framing()
{
OpenAndRunSample("Revit Floors and Framing.dyn");
}

[Test, Category("SmokeTests")]
[TestModel(@".\Samples\Snowdon Towers Sample Architectural.rvt")]
public void Revit_Import_Solid()
{
OpenAndRunSample("Revit Import Solid.dyn");
}

[Test, Category("SmokeTests")]
[TestModel(@".\Samples\Snowdon Towers Sample Architectural.rvt")]
public void Revit_Place_Families_By_Level_Set_Parameters()
{
OpenAndRunSample("Revit Place Families By Level Set Parameters.dyn");
}

[Test, Category("SmokeTests")]
[TestModel(@".\Samples\Snowdon Towers Sample Architectural.rvt")]
Comment thread
Fusneica-FlorentinCristian marked this conversation as resolved.
Outdated
Comment thread
Fusneica-FlorentinCristian marked this conversation as resolved.
Outdated
Comment thread
Fusneica-FlorentinCristian marked this conversation as resolved.
Outdated
Comment thread
Fusneica-FlorentinCristian marked this conversation as resolved.
Outdated
Comment thread
Fusneica-FlorentinCristian marked this conversation as resolved.
Outdated
public void Revit_Structural_Framing()
Comment thread
Fusneica-FlorentinCristian marked this conversation as resolved.
{
OpenAndRunSample("Revit Structural Framing.dyn");
}
}
}