Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bbb71732a3 | |||
| a16a66ebfc | |||
| ec327d6e91 | |||
| c669b6bb89 | |||
| dfb12644e1 | |||
| d50a294fdb | |||
| 450c6cb6b9 | |||
| 8d36fdd245 | |||
| 6b8ae8873c | |||
| c08723efae | |||
| 6e4f3d456e | |||
| 86a30bcb5d | |||
| e6194701ce | |||
| 569b0401fe | |||
| 7029199104 | |||
| fcd284e52a | |||
| c918c0cd50 | |||
| 658510402a | |||
| 09d6dd209f | |||
| d9d7ad808e |
@@ -1,2 +1,196 @@
|
||||
# xunit-Revit
|
||||
xUnit runner for Revit
|
||||
# xUnitRevit
|
||||
|
||||
[](https://teocomi.visualstudio.com/Speckle/_build/latest?definitionId=2&branchName=master)
|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
## Intro
|
||||
|
||||
An xUnit runner for Autodesk Revit.
|
||||
|
||||
Check out our blog post on this 👉 https://speckle.systems/blog/xunitrevit !
|
||||
|
||||
xUnitRevit uses [speckle.xunit.runner.wpf](https://github.com/Speckle-Next/speckle.xunit.runner.wpf) which is a fork of [xunit.runner.wpf](https://github.com/Pilchie/xunit.runner.wpf), it allows to easily develop and run xUnit tests in Revit.
|
||||
|
||||
Many thanks to all the developers of xunit and xunit.runner.wpf!
|
||||
|
||||
### Structure
|
||||
|
||||
This repo is composed of 2 projects:
|
||||
|
||||
- **xUnitRevit**: the actual Revit addin
|
||||
- **xUnitRevitUtils**: a utility library to help pass Revit data to the test libraries when running the tests
|
||||
|
||||
|
||||
|
||||
## Getting Started
|
||||
|
||||
There are very few steps required to create and run your fist unit tests with xUnitRevit:
|
||||
|
||||
1. create a copy of the [config sample file](xUnitRevit/config_sample.json) and re-name the copy to `config.json`
|
||||
2. follow the instructions [here](#configuration) to set up the config file
|
||||
2. build/install xUnitRevit
|
||||
3. create a test library
|
||||
4. start Revit, launch the xUnitRevit addin and select the test library
|
||||
5. done! Add a star ⭐ to our repo if it was useful 😉
|
||||
|
||||
### Building/installing xUnitRevit
|
||||
|
||||
After cloning this repo, all you need to do to run xUnitRevit is to build the project in **Debug mode**, by selecting the build configuration that matches your Revit version.
|
||||
|
||||

|
||||
|
||||
**This will build the project and copy its dlls to the Revit addin folder** `%appdata%\Autodesk\Revit\Addins`.
|
||||
|
||||
You can also, similarly, build the project in **Release mode**, and manually copy the built files from `xunit-Revit\Release`.
|
||||
|
||||
### Creating a test library
|
||||
|
||||
Creating a test library is pretty straightforward, at least we tried to make it as simple as possible!
|
||||
|
||||
Just follow the steps below for Revit 2021:
|
||||
|
||||
- create a new .net framework class library project (4.8 for Revit 2021)
|
||||
- add the NuGet packages
|
||||
- `xunit`
|
||||
- `xUnitRevitUtils.2021`
|
||||
|
||||
That's it, now we can start adding our tests.
|
||||
|
||||
#### Writing a simple test
|
||||
|
||||
To do almost anything with the Revit API you need a reference to the active Document, and this is where xUnitRevitUtils comes into play, with its `xru` static class. The code below shows how we can use it to get a list of Walls and check their properties.
|
||||
|
||||
Full code : https://github.com/Speckle-Next/xUnitRevit/blob/master/SampleLibrary/SampleTest.cs
|
||||
|
||||
```csharp
|
||||
[Fact]
|
||||
public void WallsHaveVolume()
|
||||
{
|
||||
var testModel = GetTestModel("walls.rvt");
|
||||
var doc = xru.OpenDoc(testModel);
|
||||
|
||||
var walls = new FilteredElementCollector(doc).WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Walls).ToElements();
|
||||
|
||||
foreach(var wall in walls)
|
||||
{
|
||||
var volumeParam = wall.get_Parameter(BuiltInParameter.HOST_VOLUME_COMPUTED);
|
||||
Assert.NotNull(volumeParam);
|
||||
Assert.True(volumeParam.AsDouble() > 0);
|
||||
}
|
||||
doc.Close(false);
|
||||
}
|
||||
```
|
||||
|
||||
#### Writing tests with fixtures
|
||||
|
||||
To be able to share context between tests, xUnits uses [fixtures](https://xunit.net/docs/shared-context). We can use fixtures for instance, to open a Revit model only once and use it across multiple tests.
|
||||
|
||||
Let's see an example, full code: https://github.com/Speckle-Next/xUnitRevit/blob/master/SampleLibrary/TestWithFixture.cs
|
||||
|
||||
```csharp
|
||||
public class DocFixture : IDisposable
|
||||
{
|
||||
public Document Doc { get; set; }
|
||||
public IList<Element> Walls { get; set; }
|
||||
|
||||
|
||||
public DocFixture()
|
||||
{
|
||||
var testModel = Utils.GetTestModel("walls.rvt");
|
||||
Doc = xru.OpenDoc(testModel);
|
||||
|
||||
Walls = new FilteredElementCollector(Doc).WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Walls).ToElements();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
public class TestWithFixture : IClassFixture<DocFixture>
|
||||
{
|
||||
DocFixture fixture;
|
||||
public TestWithFixture(DocFixture fixture)
|
||||
{
|
||||
this.fixture = fixture;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CountWalls()
|
||||
{
|
||||
Assert.Equal(4, fixture.Walls.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WallOffset()
|
||||
{
|
||||
var wall = fixture.Doc.GetElement(new ElementId(346573));
|
||||
var param = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET);
|
||||
var baseOffset = UnitUtils.ConvertFromInternalUnits(param.AsDouble(), param.DisplayUnitType);
|
||||
|
||||
Assert.Equal(2000, baseOffset);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Writing test that use Revit transactions
|
||||
|
||||
Another feature of xUnitRevitUtils is that it offers a helper method to run Transactions, so you don't have to worry about that 🤯! Check the example below: https://github.com/Speckle-Next/xUnitRevit/blob/master/SampleLibrary/TestWithFixture.cs
|
||||
|
||||
```csharp
|
||||
[Fact]
|
||||
public void MoveWallsUp()
|
||||
{
|
||||
var walls = fixture.Walls.Where(x => x.Id.IntegerValue != 346573);
|
||||
|
||||
xru.RunInTransaction(() =>
|
||||
{
|
||||
foreach(var wall in walls)
|
||||
{
|
||||
var param = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET);
|
||||
var baseOffset = UnitUtils.ConvertToInternalUnits(2000, param.DisplayUnitType);
|
||||
param.Set(baseOffset);
|
||||
}
|
||||
}, fixture.Doc)
|
||||
.Wait(); // Important! Wait for action to finish
|
||||
|
||||
foreach (var wall in walls)
|
||||
{
|
||||
var param = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET);
|
||||
var baseOffset = UnitUtils.ConvertFromInternalUnits(param.AsDouble(), param.DisplayUnitType);
|
||||
Assert.Equal(2000, baseOffset);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
## Additional Notes
|
||||
|
||||
### Configuration
|
||||
|
||||
We've added a couple of optional settings for lazy developers like me, to help speed up frequent testing of a test library. You'll see a `config_sample.json` in the root of the project. Copy the file and rename the copy to `config.json` and set it to `copy local = true`. You'll then be able to configure
|
||||
|
||||
- `startupAssemblies`: if set, automatically loads a set of assemblies when xUnitRevit starts
|
||||
- `autoStart`: if true, automatically opens the xUnitRevit window after Revit loads
|
||||
|
||||
### Dll locking
|
||||
|
||||
Dlls loaded by xUnitRevit are loaded in Revit's AppDomain, and therefore it's not possible to recompile them until Revit is closed (even if you see an auto reload option in the UI). But don't despair, since Revit 2020 it's possible to *edit & continue* your code while debugging, so you won't have to restart Revit each time.
|
||||
|
||||
### Next steps
|
||||
|
||||
As for next steps, we're planning to add additional features to run xUnitRevit from a CI/CD routine.
|
||||
|
||||
Stay tuned!
|
||||
|
||||
## Contributing
|
||||
|
||||
xUnitRevit was developed to help us develop a better Speckle 2.0 connector for Revit, we hope you'll find it useful too.
|
||||
|
||||
Want to suggest a feature, report a bug, submit a PR? Please open an issue to discuss first!
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("SampleLibrary")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("SampleLibrary")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2020")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("c3a8684e-15bb-4b8b-b46c-35ace3729c35")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\xunit.core.2.4.1\build\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.4.1\build\xunit.core.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{C3A8684E-15BB-4B8B-B46C-35ACE3729C35}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SampleLibrary</RootNamespace>
|
||||
<AssemblyName>SampleLibrary</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="AdWindows, Version=3.0.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ModPlus.Revit.API.2021.1.0.0\lib\AdWindows.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RevitAPI, Version=21.0.0.0, Culture=neutral, processorArchitecture=AMD64">
|
||||
<HintPath>..\packages\ModPlus.Revit.API.2021.1.0.0\lib\RevitAPI.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RevitAPIUI, Version=21.0.0.0, Culture=neutral, processorArchitecture=AMD64">
|
||||
<HintPath>..\packages\ModPlus.Revit.API.2021.1.0.0\lib\RevitAPIUI.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\xunit.abstractions.2.0.3\lib\net35\xunit.abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="xunit.assert, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\xunit.assert.2.4.1\lib\netstandard1.1\xunit.assert.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="xunit.core, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\xunit.extensibility.core.2.4.1\lib\net452\xunit.core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="xunit.execution.desktop, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\xunit.extensibility.execution.2.4.1\lib\net452\xunit.execution.desktop.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="xUnitRevitUtils, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\xUnitRevitUtils.2021.1.0.1\lib\netstandard2.0\xUnitRevitUtils.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="SampleTest.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="TestWithFixture.cs" />
|
||||
<Compile Include="Utils.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Analyzer Include="..\packages\xunit.analyzers.0.10.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\xunit.core.2.4.1\build\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.4.1\build\xunit.core.props'))" />
|
||||
<Error Condition="!Exists('..\packages\xunit.core.2.4.1\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.4.1\build\xunit.core.targets'))" />
|
||||
</Target>
|
||||
<Import Project="..\packages\xunit.core.2.4.1\build\xunit.core.targets" Condition="Exists('..\packages\xunit.core.2.4.1\build\xunit.core.targets')" />
|
||||
</Project>
|
||||
@@ -0,0 +1,40 @@
|
||||
using Autodesk.Revit.DB;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Xunit;
|
||||
using xUnitRevitUtils;
|
||||
|
||||
namespace SampleLibrary
|
||||
{
|
||||
public class SampleTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks wether all walls in the model have a valid volume
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void WallsHaveVolume()
|
||||
{
|
||||
var testModel = Utils.GetTestModel("walls.rvt");
|
||||
var doc = xru.OpenDoc(testModel);
|
||||
|
||||
var walls = new FilteredElementCollector(doc).WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Walls).ToElements();
|
||||
|
||||
foreach(var wall in walls)
|
||||
{
|
||||
var volumeParam = wall.get_Parameter(BuiltInParameter.HOST_VOLUME_COMPUTED);
|
||||
Assert.NotNull(volumeParam);
|
||||
Assert.True(volumeParam.AsDouble() > 0);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SampleFail()
|
||||
{
|
||||
var feet = UnitUtils.ConvertToInternalUnits(3000, DisplayUnitType.DUT_MILLIMETERS);
|
||||
Assert.Equal(5, feet);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,79 @@
|
||||
using Autodesk.Revit.DB;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
using xUnitRevitUtils;
|
||||
|
||||
namespace SampleLibrary
|
||||
{
|
||||
public class DocFixture : IDisposable
|
||||
{
|
||||
public Document Doc { get; set; }
|
||||
public IList<Element> Walls { get; set; }
|
||||
|
||||
|
||||
public DocFixture()
|
||||
{
|
||||
var testModel = Utils.GetTestModel("walls.rvt");
|
||||
Doc = xru.OpenDoc(testModel);
|
||||
|
||||
Walls = new FilteredElementCollector(Doc).WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Walls).ToElements();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
public class TestWithFixture : IClassFixture<DocFixture>
|
||||
{
|
||||
DocFixture fixture;
|
||||
public TestWithFixture(DocFixture fixture)
|
||||
{
|
||||
this.fixture = fixture;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CountWalls()
|
||||
{
|
||||
Assert.Equal(4, fixture.Walls.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WallOffset()
|
||||
{
|
||||
var wall = fixture.Doc.GetElement(new ElementId(346573));
|
||||
var param = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET);
|
||||
var baseOffset = UnitUtils.ConvertFromInternalUnits(param.AsDouble(), param.DisplayUnitType);
|
||||
|
||||
Assert.Equal(2000, baseOffset);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MoveWallsUp()
|
||||
{
|
||||
var walls = fixture.Walls.Where(x => x.Id.IntegerValue != 346573);
|
||||
|
||||
xru.RunInTransaction(() =>
|
||||
{
|
||||
foreach(var wall in walls)
|
||||
{
|
||||
var param = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET);
|
||||
var baseOffset = UnitUtils.ConvertToInternalUnits(2000, param.DisplayUnitType);
|
||||
param.Set(baseOffset);
|
||||
}
|
||||
}, fixture.Doc)
|
||||
.Wait(); // Important! Wait for action to finish
|
||||
|
||||
foreach (var wall in walls)
|
||||
{
|
||||
var param = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET);
|
||||
var baseOffset = UnitUtils.ConvertFromInternalUnits(param.AsDouble(), param.DisplayUnitType);
|
||||
Assert.Equal(2000, baseOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SampleLibrary
|
||||
{
|
||||
public static class Utils
|
||||
{
|
||||
/// <summary>
|
||||
/// Utility method to get models from local folder rather than an absolute path
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetTestModel(string filename)
|
||||
{
|
||||
var path = Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "TestModels", filename);
|
||||
return path;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="ModPlus.Revit.API.2021" version="1.0.0" targetFramework="net472" />
|
||||
<package id="xunit" version="2.4.1" targetFramework="net472" />
|
||||
<package id="xunit.abstractions" version="2.0.3" targetFramework="net472" />
|
||||
<package id="xunit.analyzers" version="0.10.0" targetFramework="net472" />
|
||||
<package id="xunit.assert" version="2.4.1" targetFramework="net472" />
|
||||
<package id="xunit.core" version="2.4.1" targetFramework="net472" />
|
||||
<package id="xunit.extensibility.core" version="2.4.1" targetFramework="net472" />
|
||||
<package id="xunit.extensibility.execution" version="2.4.1" targetFramework="net472" />
|
||||
<package id="xUnitRevitUtils.2021" version="1.0.1" targetFramework="net472" />
|
||||
</packages>
|
||||
+5
-3
@@ -6,7 +6,8 @@
|
||||
trigger:
|
||||
branches:
|
||||
include:
|
||||
- refs/tags/*
|
||||
- master
|
||||
- refs/tags/*
|
||||
|
||||
pool:
|
||||
vmImage: 'windows-latest'
|
||||
@@ -46,6 +47,7 @@ steps:
|
||||
publishLocation: 'Container'
|
||||
|
||||
- powershell: |
|
||||
nuget push -ApiKey $env:APIKEY -Source https://api.nuget.org/v3/index.json $(Build.ArtifactStagingDirectory)/**/*.nupkg
|
||||
If ($env:BRANCH.StartsWith('refs/tags/')) { nuget push -ApiKey $env:APIKEY -Source https://api.nuget.org/v3/index.json $(Build.ArtifactStagingDirectory)/**/*.nupkg }
|
||||
env:
|
||||
APIKEY: $(nuget-apikey)
|
||||
APIKEY: $(nuget-apikey)
|
||||
BRANCH: $(Build.SourceBranch)
|
||||
@@ -11,8 +11,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "xUnitRevitUtils2020", "xUni
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "xUnitRevitUtils2019", "xUnitRevitUtils2019\xUnitRevitUtils2019.csproj", "{02399359-9CA0-4B47-B467-541E290E700F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleLibrary", "SampleLibrary\SampleLibrary.csproj", "{C3A8684E-15BB-4B8B-B46C-35ACE3729C35}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug2019|Any CPU = Debug2019|Any CPU
|
||||
Debug2020|Any CPU = Debug2020|Any CPU
|
||||
Debug2021|Any CPU = Debug2021|Any CPU
|
||||
@@ -22,6 +25,8 @@ Global
|
||||
Release2021|Any CPU = Release2021|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{27A79ACA-7EA8-4406-8BB8-216578CC3AB7}.Debug|Any CPU.ActiveCfg = Debug2021|Any CPU
|
||||
{27A79ACA-7EA8-4406-8BB8-216578CC3AB7}.Debug|Any CPU.Build.0 = Debug2021|Any CPU
|
||||
{27A79ACA-7EA8-4406-8BB8-216578CC3AB7}.Debug2019|Any CPU.ActiveCfg = Debug2019|Any CPU
|
||||
{27A79ACA-7EA8-4406-8BB8-216578CC3AB7}.Debug2019|Any CPU.Build.0 = Debug2019|Any CPU
|
||||
{27A79ACA-7EA8-4406-8BB8-216578CC3AB7}.Debug2020|Any CPU.ActiveCfg = Debug2020|Any CPU
|
||||
@@ -35,6 +40,8 @@ Global
|
||||
{27A79ACA-7EA8-4406-8BB8-216578CC3AB7}.Release2020|Any CPU.Build.0 = Release2020|Any CPU
|
||||
{27A79ACA-7EA8-4406-8BB8-216578CC3AB7}.Release2021|Any CPU.ActiveCfg = Release2021|Any CPU
|
||||
{27A79ACA-7EA8-4406-8BB8-216578CC3AB7}.Release2021|Any CPU.Build.0 = Release2021|Any CPU
|
||||
{977E0B63-5706-4C2B-9C01-3C02D9EBE377}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{977E0B63-5706-4C2B-9C01-3C02D9EBE377}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{977E0B63-5706-4C2B-9C01-3C02D9EBE377}.Debug2019|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{977E0B63-5706-4C2B-9C01-3C02D9EBE377}.Debug2020|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{977E0B63-5706-4C2B-9C01-3C02D9EBE377}.Debug2021|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
@@ -45,6 +52,8 @@ Global
|
||||
{977E0B63-5706-4C2B-9C01-3C02D9EBE377}.Release2020|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{977E0B63-5706-4C2B-9C01-3C02D9EBE377}.Release2021|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{977E0B63-5706-4C2B-9C01-3C02D9EBE377}.Release2021|Any CPU.Build.0 = Release|Any CPU
|
||||
{0DEF0F23-8AE2-461B-B014-8A0DA7494088}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0DEF0F23-8AE2-461B-B014-8A0DA7494088}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0DEF0F23-8AE2-461B-B014-8A0DA7494088}.Debug2019|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0DEF0F23-8AE2-461B-B014-8A0DA7494088}.Debug2020|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0DEF0F23-8AE2-461B-B014-8A0DA7494088}.Debug2020|Any CPU.Build.0 = Debug|Any CPU
|
||||
@@ -55,6 +64,8 @@ Global
|
||||
{0DEF0F23-8AE2-461B-B014-8A0DA7494088}.Release2020|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0DEF0F23-8AE2-461B-B014-8A0DA7494088}.Release2020|Any CPU.Build.0 = Release|Any CPU
|
||||
{0DEF0F23-8AE2-461B-B014-8A0DA7494088}.Release2021|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{02399359-9CA0-4B47-B467-541E290E700F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{02399359-9CA0-4B47-B467-541E290E700F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{02399359-9CA0-4B47-B467-541E290E700F}.Debug2019|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{02399359-9CA0-4B47-B467-541E290E700F}.Debug2019|Any CPU.Build.0 = Debug|Any CPU
|
||||
{02399359-9CA0-4B47-B467-541E290E700F}.Debug2020|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
@@ -65,6 +76,22 @@ Global
|
||||
{02399359-9CA0-4B47-B467-541E290E700F}.Release2019|Any CPU.Build.0 = Release|Any CPU
|
||||
{02399359-9CA0-4B47-B467-541E290E700F}.Release2020|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{02399359-9CA0-4B47-B467-541E290E700F}.Release2021|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C3A8684E-15BB-4B8B-B46C-35ACE3729C35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C3A8684E-15BB-4B8B-B46C-35ACE3729C35}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C3A8684E-15BB-4B8B-B46C-35ACE3729C35}.Debug2019|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C3A8684E-15BB-4B8B-B46C-35ACE3729C35}.Debug2019|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C3A8684E-15BB-4B8B-B46C-35ACE3729C35}.Debug2020|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C3A8684E-15BB-4B8B-B46C-35ACE3729C35}.Debug2020|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C3A8684E-15BB-4B8B-B46C-35ACE3729C35}.Debug2021|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C3A8684E-15BB-4B8B-B46C-35ACE3729C35}.Debug2021|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C3A8684E-15BB-4B8B-B46C-35ACE3729C35}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C3A8684E-15BB-4B8B-B46C-35ACE3729C35}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C3A8684E-15BB-4B8B-B46C-35ACE3729C35}.Release2019|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C3A8684E-15BB-4B8B-B46C-35ACE3729C35}.Release2019|Any CPU.Build.0 = Release|Any CPU
|
||||
{C3A8684E-15BB-4B8B-B46C-35ACE3729C35}.Release2020|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C3A8684E-15BB-4B8B-B46C-35ACE3729C35}.Release2020|Any CPU.Build.0 = Release|Any CPU
|
||||
{C3A8684E-15BB-4B8B-B46C-35ACE3729C35}.Release2021|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C3A8684E-15BB-4B8B-B46C-35ACE3729C35}.Release2021|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"startupAssemblies": [
|
||||
"C:\\Code\\Speckle-Next\\ConverterRevit\\SpeckleRevitTests\\bin\\Debug\\SpeckleRevitTests.dll"
|
||||
"C:\\Code\\Speckle-Next\\ConverterRevit\\ConverterRevitTests\\bin\\Debug\\ConverterRevitTests.dll"
|
||||
],
|
||||
"autoStart": true
|
||||
}
|
||||
@@ -172,7 +172,7 @@
|
||||
<Version>5.4.1.1</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="speckle.xunit.runner.wpf">
|
||||
<Version>1.0.5</Version>
|
||||
<Version>1.0.8</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<AssemblyName>xUnitRevitUtils</AssemblyName>
|
||||
<RootNamespace>xUnitRevitUtils</RootNamespace>
|
||||
<PackageId>xUnitRevitUtils.2020</PackageId>
|
||||
<Version>1.0.1</Version>
|
||||
<Version>1.0.2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
+43
-13
@@ -16,15 +16,15 @@ namespace xUnitRevitUtils
|
||||
/// </summary>
|
||||
public static class xru
|
||||
{
|
||||
private static UIApplication Uiapp { get; set; }
|
||||
public static UIApplication Uiapp { get; set; }
|
||||
|
||||
private static List<Action> Queue { get; set; }
|
||||
private static ExternalEvent EventHandler { get; set; }
|
||||
|
||||
private static SynchronizationContext UiContext { get; set; }
|
||||
public static SynchronizationContext UiContext { get; set; }
|
||||
|
||||
public static void Initialize(UIApplication uiapp, SynchronizationContext uiContext, ExternalEvent eventHandler, List<Action> queue)
|
||||
{
|
||||
{
|
||||
Uiapp = uiapp;
|
||||
UiContext = uiContext;
|
||||
EventHandler = eventHandler;
|
||||
@@ -99,14 +99,15 @@ namespace xUnitRevitUtils
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Runs an Action in a Revit transaction, uses TaskCompletionSource to communicate when done
|
||||
/// </summary>
|
||||
/// <param name="action">Action to run</param>
|
||||
/// <param name="doc">Revit Document</param>
|
||||
/// <param name="transactionName">Transaction Name</param>
|
||||
/// <returns></returns>
|
||||
public static Task RunInTransaction(Action action, Document doc, string transactionName = "transaction")
|
||||
/// <summary>
|
||||
/// Runs an Action in a Revit transaction, uses TaskCompletionSource to communicate when done
|
||||
/// </summary>
|
||||
/// <param name="action">Action to run</param>
|
||||
/// <param name="doc">Revit Document</param>
|
||||
/// <param name="transactionName">Transaction Name</param>
|
||||
/// <param name="ignoreWarnings">Enable to swallow all warnings generated by the transaction and prevent them from being raised within Revit</param>
|
||||
/// <returns></returns>
|
||||
public static Task RunInTransaction(Action action, Document doc, string transactionName = "transaction", bool ignoreWarnings = false)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<string>();
|
||||
Queue.Add(new Action(() =>
|
||||
@@ -116,6 +117,14 @@ namespace xUnitRevitUtils
|
||||
using (Transaction transaction = new Transaction(doc, transactionName))
|
||||
{
|
||||
transaction.Start();
|
||||
|
||||
if (ignoreWarnings)
|
||||
{
|
||||
var options = transaction.GetFailureHandlingOptions();
|
||||
options.SetFailuresPreprocessor(new IgnoreAllWarnings());
|
||||
transaction.SetFailureHandlingOptions(options);
|
||||
}
|
||||
|
||||
action.Invoke();
|
||||
transaction.Commit();
|
||||
}
|
||||
@@ -130,7 +139,28 @@ namespace xUnitRevitUtils
|
||||
EventHandler.Raise();
|
||||
|
||||
return tcs.Task;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A failures preprocesser that clears any failures that occur within a transaction
|
||||
/// </summary>
|
||||
internal class IgnoreAllWarnings : IFailuresPreprocessor
|
||||
{
|
||||
public FailureProcessingResult PreprocessFailures(FailuresAccessor failuresAccessor)
|
||||
{
|
||||
var failList = failuresAccessor.GetFailureMessages();
|
||||
|
||||
foreach (FailureMessageAccessor failure in failList)
|
||||
{
|
||||
failuresAccessor.DeleteWarning(failure);
|
||||
}
|
||||
|
||||
return FailureProcessingResult.Continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user