Skip to content

Commit

Permalink
Added IFC structure testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
CBenghi committed May 3, 2024
1 parent f6ded39 commit 6e8748b
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ids-lib/LibraryInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ public static class LibraryInformation
/// <summary>
/// Static field with hardcoded DLL version number.
/// </summary>
public static string AssemblyVersion => "1.0.72";
public static string AssemblyVersion => "1.0.73";
}
2 changes: 1 addition & 1 deletion ids-lib/ids-lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReleaseNotes>First implementation.</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
<!-- Github actions are setup so that when this version is bumped the nuget package is uploaded -->
<AssemblyVersion>1.0.72</AssemblyVersion>
<AssemblyVersion>1.0.73</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<Version>$(AssemblyVersion)</Version>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
73 changes: 73 additions & 0 deletions ids-tool.tests/Helpers/XbimFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using idsTool.tests.Helpers;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NSubstitute;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xbim.Common.Configuration;
using Xunit;
using static idsTool.tests.IfcFilesTests;

namespace idsTool.tests.Helpers
{

public class XbimFixture : IDisposable
{
public ILogger<XbimFixture> Logger { get; }

public XbimFixture()
{
// ... initialize xbim context ...
Logger = Substitute.For<ILogger<XbimFixture>>();

XbimServices.Current.ConfigureServices(s =>
s.AddXbimToolkit(opt => opt.AddMemoryModel())
.AddLogging(c => configure(c, Logger))
);
}
private void configure(ILoggingBuilder loggingBuilder, ILogger<XbimFixture> lg)
{
loggingBuilder.AddProvider(new MyLoggerProvider(lg));
}

public void Dispose()
{
// ... clean up test data from the database ...
}
}


public class MyLoggerProvider : ILoggerProvider
{
ILogger ret;

public MyLoggerProvider(ILogger val)
{
ret = val;
}

public void Dispose()
{
// Dispose any resources if needed
}

public ILogger CreateLogger(string categoryName)
{
return ret;
}
}



[CollectionDefinition("xbim collection")]
public class DatabaseCollection : ICollectionFixture<XbimFixture>
{
// This class has no code, and is never created. Its purpose is simply
// to be the place to apply [CollectionDefinition] and all the
// ICollectionFixture<> interfaces.
}

}
24 changes: 21 additions & 3 deletions ids-tool.tests/IfcFilesTests.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
using FluentAssertions;
using FluentAssertions.Common;
using idsTool.tests.Helpers;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NSubstitute;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xbim.Common.Configuration;
using Xbim.Ifc;
using Xbim.Ifc4.Interfaces;
using Xbim.IO.Parser;
using Xunit;
using Xunit.Abstractions;

namespace idsTool.tests
{
public class IfcFilesTests : BuildingSmartRepoFiles
[Collection("Database collection")]

public class IfcFilesTests : BuildingSmartRepoFiles, IClassFixture<XbimFixture>
{
public IfcFilesTests(ITestOutputHelper outputHelper)
XbimFixture xbimContext;
public IfcFilesTests(XbimFixture fixture, ITestOutputHelper outputHelper)
{
XunitOutputHelper = outputHelper;
xbimContext = fixture;
XunitOutputHelper = outputHelper;
}

private ITestOutputHelper XunitOutputHelper { get; }

[SkippableTheory]
Expand All @@ -38,10 +49,17 @@ public void IfcFileIsOk(string developmentIfcFile)
];

XunitOutputHelper.WriteLine($"Opening file `{ifcFile.FullName}`");
xbimContext.Logger.ClearReceivedCalls();
using var store = IfcStore.Open(ifcFile.FullName);
TestPredefinedType(store, musthave.Contains(ifcFile.Name));
if (ifcFile.Name == "bad.ifc")
xbimContext.Logger.ReceivedWithAnyArgs(1).Log(default, default);
else
xbimContext.Logger.ReceivedWithAnyArgs(0).Log(default, default);
}



private void TestPredefinedType(IfcStore store, bool mustHaveObjType)
{
var toTest = store.Instances.OfType<IIfcObject>().ToList();
Expand Down
2 changes: 1 addition & 1 deletion ids-tool.tests/ids-tool.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<IsPackable>false</IsPackable>
<IsPublishable>false</IsPublishable>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>idsTool.tests</RootNamespace>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
2 changes: 1 addition & 1 deletion ids-tool/ids-tool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageIcon>icon.png</PackageIcon>
<PackageTags>IDS, buildingSmart</PackageTags>
<!-- Github actions are setup so that when this version is bumped the nuget package is uploaded -->
<AssemblyVersion>1.0.72</AssemblyVersion>
<AssemblyVersion>1.0.73</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<Version>$(AssemblyVersion)</Version>
<RepositoryUrl>https://github.com/buildingSMART/IDS-Audit-tool.git</RepositoryUrl>
Expand Down

0 comments on commit 6e8748b

Please sign in to comment.