Skip to content

Commit

Permalink
[BMSPT-24] test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
BalintBende committed Oct 6, 2023
1 parent 7aa1914 commit 0257af7
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 53 deletions.
7 changes: 6 additions & 1 deletion bcf-converter.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/Highlighting/HighlightingSourceSnapshotLocation/@EntryValue">/Users/balintbende/Library/Caches/JetBrains/Rider2022.3/resharper-host/temp/Rider/vAny/CoverageData/_bcf-converter.-403555820/Snapshot/snapshot.utdcvr</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=6d37b98c_002Dda0b_002D494b_002D8ad2_002D8a7de5d81b32/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=fa33bbb3_002D98bf_002D494f_002Da627_002D44dd852087bd/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;Solution /&gt;
&lt;/SessionState&gt;</s:String>

Expand All @@ -22,6 +22,11 @@











Expand Down
6 changes: 3 additions & 3 deletions src/bcf-converter/Converter/Bcf21/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ await BcfConverter.WriteBcf<Markup, VisualizationInfo, Root, Version>(
target, markups, root);
}

public async Task ToBcf(string target, ConcurrentBag<IMarkup> markups) {
public async Task ToBcf(string target, ConcurrentBag<IMarkup> markups, IRoot root) {

Check warning on line 65 in src/bcf-converter/Converter/Bcf21/Converter.cs

View workflow job for this annotation

GitHub Actions / Running tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
//TODO fill root
var root = new Root();
await BcfConverter.WriteBcf<Markup, VisualizationInfo, Root, Version>(target, markups, root);
//var root = new Root();
//await BcfConverter.WriteBcf<Markup, VisualizationInfo, Root, Version>(target, markups, root);
}
}
2 changes: 1 addition & 1 deletion src/bcf-converter/Converter/Bcf30/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ public async Task JsonToBcf(string source, string target) {
}

public async Task ToBcf(string target, ConcurrentBag<IMarkup> markups, IRoot root) {

Check warning on line 66 in src/bcf-converter/Converter/Bcf30/Converter.cs

View workflow job for this annotation

GitHub Actions / Running tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
await BcfConverter.WriteBcf<Markup, VisualizationInfo, Root, Version>(target, markups, root);
//await BcfConverter.WriteBcf<Markup, VisualizationInfo, Root, Version>(target, markups, root);
}
}
4 changes: 2 additions & 2 deletions src/bcf-converter/Converter/ConverterContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public async Task Convert(string source, string target) {
await Converter.JsonToBcf(source, target)!;
}

internal Task ToBcf(string target, ConcurrentBag<IMarkup> markups) {
return Converter.ToBcf(target, markups);
internal Task ToBcf(string target, ConcurrentBag<IMarkup> markups, IRoot root) {
return Converter.ToBcf(target, markups, root);
}
}
9 changes: 6 additions & 3 deletions src/bcf-converter/Converter/Json/JsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public static class JsonConverter {
/// <returns></returns>
/// <exception cref="ApplicationException"></exception>
public static Task<ConcurrentBag<TMarkup>> ParseMarkups<TMarkup>(
string sourceFolder) {
string sourceFolder)
where TMarkup : IMarkup {
return Task.Run(async () => {
// A thread-safe storage for the parsed topics.
var markups = new ConcurrentBag<TMarkup>();
Expand Down Expand Up @@ -100,8 +101,10 @@ public static Task<T> ParseObject<T>(string source) {
/// <param name="markups">The list of `Markup` objects.</param>
/// <param name="root">The `Root` object.</param>
/// <returns></returns>
public static Task WriteJson<TMarkup, TRoot>(string targetFolder,
ConcurrentBag<TMarkup> markups, TRoot root) {
public static Task WriteJson<TMarkup, TRoot>(
string targetFolder,
ConcurrentBag<TMarkup> markups,
TRoot root) {
return Task.Run(async () => {
// TODO make a default serializer to avoid code repeat
var contractResolver = new DefaultContractResolver {
Expand Down
62 changes: 30 additions & 32 deletions src/tests/Converter/Bcf/BcfConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
using System.Collections.Concurrent;
using System.Linq;
using System.Threading.Tasks;
using bcf21 = bcf.bcf21;
using bcf30 = bcf.bcf30;
using bcf.Converter;
using bcf21 = BcfConverter.Model.Bcf21;
using bcf30 = BcfConverter.Model.Bcf30;
using BcfConverter;
using BcfConverter.Model;
using NUnit.Framework;

namespace Tests.Converter.Bcf;
Expand All @@ -19,7 +20,7 @@ public class BcfConverterTests {
[Category("BCF v2.1")]
public async Task ParseBcfAllPartsVisibleTest() {
var markups =
await BcfConverter.ParseMarkups<bcf21.Markup, bcf21.VisualizationInfo>(
await BcfConverter.Converter.BcfConverter.ParseMarkups<bcf21.Markup, bcf21.VisualizationInfo>(
"Resources/Bcf/v2.1/AllPartsVisible.bcfzip");
var markup = markups.FirstOrDefault()!;
Assert.AreEqual(1, markups.Count);
Expand All @@ -41,7 +42,7 @@ public async Task ParseBcfAllPartsVisibleTest() {
[Category("BCF v2.1")]
public async Task ParseBcfComponentsSelection21Test() {
var markups =
await BcfConverter.ParseMarkups<bcf21.Markup, bcf21.VisualizationInfo>(
await BcfConverter.Converter.BcfConverter.ParseMarkups<bcf21.Markup, bcf21.VisualizationInfo>(
"Resources/Bcf/v2.1/ComponentSelection.bcfzip");
var markup = markups.FirstOrDefault();
Assert.AreEqual(1, markups.Count);
Expand All @@ -64,7 +65,7 @@ public async Task ParseBcfComponentsSelection21Test() {
[Category("BCF v2.1")]
public async Task ParseBcfExternalBimSnippetTest() {
var markups =
await BcfConverter.ParseMarkups<bcf21.Markup, bcf21.VisualizationInfo>(
await BcfConverter.Converter.BcfConverter.ParseMarkups<bcf21.Markup, bcf21.VisualizationInfo>(
"Resources/Bcf/v2.1/ExternalBIMSnippet.bcfzip");
var markup = markups.FirstOrDefault()!;
Assert.AreEqual(1, markups.Count);
Expand All @@ -79,7 +80,7 @@ public async Task ParseBcfExternalBimSnippetTest() {
[Category("BCF v2.1")]
public async Task ParseBcfMultipleMarkupsTest() {
var markups =
await BcfConverter.ParseMarkups<bcf21.Markup, bcf21.VisualizationInfo>(
await BcfConverter.Converter.BcfConverter.ParseMarkups<bcf21.Markup, bcf21.VisualizationInfo>(
"Resources/Bcf/v2.1/MaximumInformation.bcfzip");
Assert.AreEqual(2, markups.Count);
}
Expand All @@ -91,7 +92,7 @@ public async Task ParseBcfMultipleMarkupsTest() {
[Category("BCF v2.1")]
public void ParseBcfNoMarkupsTest() {
Assert.That(async () =>
await BcfConverter.ParseMarkups<bcf21.Markup, bcf21.VisualizationInfo>(
await BcfConverter.Converter.BcfConverter.ParseMarkups<bcf21.Markup, bcf21.VisualizationInfo>(
"Resources/Bcf/v2.1/NoMakrups.bcfzip"), Throws.Exception);
}

Expand All @@ -103,7 +104,7 @@ public void ParseBcfNoMarkupsTest() {
[Category("BCF v2.1")]
public void ParseBcfRelatedTopics21Test() {
Assert.That(
async () => await BcfConverter.ParseMarkups<bcf21.Markup, bcf21.VisualizationInfo>(
async () => await BcfConverter.Converter.BcfConverter.ParseMarkups<bcf21.Markup, bcf21.VisualizationInfo>(
"Resources/Bcf/v2.1/RelatedTopics.bcfzip"), Throws.Exception);
// var markup1 = markups.FirstOrDefault()!;
// var markup2 = markups.ElementAt(1);
Expand All @@ -120,7 +121,7 @@ public void ParseBcfRelatedTopics21Test() {
[Category("BCF v2.1")]
public void ParseBcfSingleVisibleWallTest() {
Assert.That(async () =>
await BcfConverter.ParseMarkups<bcf21.Markup, bcf21.VisualizationInfo>(
await BcfConverter.Converter.BcfConverter.ParseMarkups<bcf21.Markup, bcf21.VisualizationInfo>(
"Resources/Bcf/v2.1/SingleVisibleWall.bcfzip"), Throws.Exception);
// var markup = markups.FirstOrDefault()!;
// var visInfo =
Expand All @@ -138,7 +139,7 @@ public void ParseBcfSingleVisibleWallTest() {
[Category("BCF v2.1")]
public async Task ParseBcfUserAssignment21Test() {
var markups =
await BcfConverter.ParseMarkups<bcf21.Markup, bcf21.VisualizationInfo>(
await BcfConverter.Converter.BcfConverter.ParseMarkups<bcf21.Markup, bcf21.VisualizationInfo>(
"Resources/Bcf/v2.1/UserAssignment.bcfzip");
var markup = markups.FirstOrDefault()!;
Assert.AreEqual("[email protected]", markup.Topic.AssignedTo);
Expand All @@ -151,8 +152,7 @@ public async Task ParseBcfUserAssignment21Test() {
[Category("BCF v3.0")]
public async Task ParseBcfComponentsSelection30Test() {
var markups =
await BcfConverter
.ParseMarkups<bcf30.Markup, bcf30.VisualizationInfo>(
await BcfConverter.Converter.BcfConverter.ParseMarkups<bcf30.Markup, bcf30.VisualizationInfo>(
"Resources/Bcf/v3.0/ComponentSelection.bcfzip");
var markup = markups.FirstOrDefault();
Assert.AreEqual(1, markups.Count);
Expand All @@ -176,8 +176,7 @@ await BcfConverter
[Category("BCF v3.0")]
public async Task ParseBcfDocumentRefExternalTest() {
var markups =
await BcfConverter
.ParseMarkups<bcf30.Markup, bcf30.VisualizationInfo>(
await BcfConverter.Converter.BcfConverter.ParseMarkups<bcf30.Markup, bcf30.VisualizationInfo>(
"Resources/Bcf/v3.0/DocumentReferenceExternal.bcfzip");
var markup = markups.FirstOrDefault()!;
Assert.AreEqual(1, markups.Count);
Expand All @@ -196,11 +195,10 @@ await BcfConverter
[Category("BCF v3.0")]
public async Task ParseBcfDocumentRefInternalTest() {
var markups =
await BcfConverter
.ParseMarkups<bcf30.Markup, bcf30.VisualizationInfo>(
await BcfConverter.Converter.BcfConverter.ParseMarkups<bcf30.Markup, bcf30.VisualizationInfo>(
"Resources/Bcf/v3.0/DocumentReferenceInternal.bcfzip");
var documentInfo =
await BcfConverter.ParseDocuments<bcf30.DocumentInfo>(
await BcfConverter.Converter.BcfConverter.ParseDocuments<bcf30.DocumentInfo>(
"Resources/Bcf/v3.0/DocumentReferenceInternal.bcfzip");
var markup = markups.FirstOrDefault()!;
Assert.AreEqual(1, markups.Count);
Expand All @@ -218,7 +216,7 @@ await BcfConverter
[Category("BCF v3.0")]
public async Task ParseBcfDueDateTest() {
var markups =
await BcfConverter
await BcfConverter.Converter.BcfConverter
.ParseMarkups<bcf30.Markup, bcf30.VisualizationInfo>(
"Resources/Bcf/v3.0/DueDate.bcfzip");
var markup = markups.FirstOrDefault()!;
Expand All @@ -235,12 +233,12 @@ await BcfConverter
[Category("BCF v3.0")]
public async Task ParseBcfLabelsTest() {
var markups =
await BcfConverter
await BcfConverter.Converter.BcfConverter
.ParseMarkups<bcf30.Markup, bcf30.VisualizationInfo>(
"Resources/Bcf/v3.0/Labels.bcfzip");
var markup = markups.FirstOrDefault()!;
var extensions =
await BcfConverter.ParseExtensions<bcf30.Extensions>(
await BcfConverter.Converter.BcfConverter.ParseExtensions<bcf30.Extensions>(
"Resources/Bcf/v3.0/Labels.bcfzip");
Assert.AreEqual(1, markups.Count);
var label = markup.Topic.Labels.FirstOrDefault();
Expand All @@ -256,12 +254,12 @@ await BcfConverter
[Category("BCF v3.0")]
public async Task ParseBcfStageTest() {
var markups =
await BcfConverter
await BcfConverter.Converter.BcfConverter
.ParseMarkups<bcf30.Markup, bcf30.VisualizationInfo>(
"Resources/Bcf/v3.0/Milestone.bcfzip");
var markup = markups.FirstOrDefault()!;
var extensions =
await BcfConverter.ParseExtensions<bcf30.Extensions>(
await BcfConverter.Converter.BcfConverter.ParseExtensions<bcf30.Extensions>(
"Resources/Bcf/v3.0/Milestone.bcfzip");
Assert.AreEqual(1, markups.Count);
var stage = markup.Topic.Stage;
Expand All @@ -277,7 +275,7 @@ await BcfConverter
[Category("BCF v3.0")]
public async Task ParseBcfRelatedTopics30Test() {
var markups =
await BcfConverter
await BcfConverter.Converter.BcfConverter
.ParseMarkups<bcf30.Markup, bcf30.VisualizationInfo>(
"Resources/Bcf/v3.0/RelatedTopics.bcfzip");
var markup1 = markups.FirstOrDefault()!;
Expand All @@ -295,7 +293,7 @@ await BcfConverter
[Category("BCF v3.0")]
public async Task ParseBcfSingleInvisibleWallTest() {
var markups =
await BcfConverter
await BcfConverter.Converter.BcfConverter
.ParseMarkups<bcf30.Markup, bcf30.VisualizationInfo>(
"Resources/Bcf/v3.0/SingleInvisibleWall.bcfzip");
var markup = markups.FirstOrDefault()!;
Expand All @@ -317,7 +315,7 @@ await BcfConverter
[Category("BCF v3.0")]
public async Task ParseBcfDifferentModelsVisibleTest() {
var markups =
await BcfConverter
await BcfConverter.Converter.BcfConverter
.ParseMarkups<bcf30.Markup, bcf30.VisualizationInfo>(
"Resources/Bcf/v3.0/TopicsWithDifferentModelsVisible.bcfzip");
var markupARC = markups.FirstOrDefault(m =>
Expand All @@ -341,7 +339,7 @@ await BcfConverter
[Category("BCF v3.0")]
public async Task ParseBcfUserAssignment30Test() {
var markups =
await BcfConverter.ParseMarkups<bcf30.Markup, bcf30.VisualizationInfo>(
await BcfConverter.Converter.BcfConverter.ParseMarkups<bcf30.Markup, bcf30.VisualizationInfo>(
"Resources/Bcf/v3.0/UserAssignment.bcfzip");
var markup = markups.FirstOrDefault()!;
Assert.AreEqual("[email protected]", markup.Topic.AssignedTo);
Expand All @@ -353,12 +351,12 @@ public async Task ParseBcfUserAssignment30Test() {
[Test]
public async Task ParseRequiredObjectTest() {
var extensions =
await BcfConverter.ParseExtensions<bcf30.Extensions>(
await BcfConverter.Converter.BcfConverter.ParseExtensions<bcf30.Extensions>(
"Resources/Bcf/v3.0/Milestone.bcfzip");
var type = extensions.TopicTypes.FirstOrDefault();
Assert.AreEqual("Error", type);

Assert.That(async () => await BcfConverter.ParseExtensions<bcf30.Extensions>(
Assert.That(async () => await BcfConverter.Converter.BcfConverter.ParseExtensions<bcf30.Extensions>(
"Resources/Bcf/v3.0/WithoutRequiredExtension.bcfzip"), Throws.Exception);
}

Expand All @@ -378,7 +376,7 @@ public async Task WriteBcfWithMinimumInformationTest() {
};
var markups = new ConcurrentBag<bcf21.Markup> { markup };
var root = new bcf21.Root();
await BcfConverter.WriteBcf<bcf21.Markup, bcf21.VisualizationInfo, bcf21.Root, bcf21.Version>(
await BcfConverter.Converter.BcfConverter.WriteBcf<bcf21.Markup, bcf21.VisualizationInfo, bcf21.Root, bcf21.Version>(
"Resources/output/Bcf/v2.1/MinimumInformation.bcfzip",
markups,
root);
Expand All @@ -399,7 +397,7 @@ public async Task WriteBcfWithoutTopicGuidTest() {
};
var markups = new ConcurrentBag<bcf21.Markup> { markup };
var root = new bcf21.Root();
await BcfConverter.WriteBcf<bcf21.Markup, bcf21.VisualizationInfo, bcf21.Root, bcf21.Version>(
await BcfConverter.Converter.BcfConverter.WriteBcf<bcf21.Markup, bcf21.VisualizationInfo, bcf21.Root, bcf21.Version>(
"Resources/output/Bcf/v2.1/WithoutTopicGuid.bcfzip",
markups,
root);
Expand All @@ -412,7 +410,7 @@ public async Task WriteBcfWithoutTopicGuidTest() {
[Category("BCF v2.1")]
public void ParseBcfMissingTopicTitleTest() {
Assert.That(async () =>
await BcfConverter.ParseMarkups<bcf21.Markup, bcf21.VisualizationInfo>(
await BcfConverter.Converter.BcfConverter.ParseMarkups<bcf21.Markup, bcf21.VisualizationInfo>(
"Resources/Bcf/v2.1/MissingTitle.bcfzip"), Throws.Exception);
}
}
5 changes: 2 additions & 3 deletions src/tests/Converter/Converter21Tests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using bcf;
using bcf.Converter;
using BcfConverter.Converter;
using NUnit.Framework;

namespace Tests.Converter;
Expand All @@ -10,7 +9,7 @@ namespace Tests.Converter;
public class Converter21Tests {
[SetUp]
public void Setup() {
_converter = new bcf.Converter.Bcf21.Converter();
_converter = new BcfConverter.Converter.Bcf21.Converter();
}

private IConverter _converter = null!;
Expand Down
4 changes: 2 additions & 2 deletions src/tests/Converter/Converter30Tests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using bcf.Converter;
using BcfConverter.Converter;
using NUnit.Framework;

namespace Tests.Converter;
Expand All @@ -9,7 +9,7 @@ namespace Tests.Converter;
public class Converter30Tests {
[SetUp]
public void Setup() {
_converter = new bcf.Converter.Bcf30.Converter();
_converter = new BcfConverter.Converter.Bcf30.Converter();
}

private IConverter _converter = null!;
Expand Down
12 changes: 6 additions & 6 deletions src/tests/Converter/Json/JsonConverterTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Linq;
using System.Threading.Tasks;
using bcf.Converter;
using NUnit.Framework;
using bcf21 = bcf.bcf21;
using bcf30 = bcf.bcf30;
using bcf21 = BcfConverter.Model.Bcf21;
using bcf30 = BcfConverter.Model.Bcf30;
using BcfConverter.Converter;

namespace Tests.Converter.Json;

Expand All @@ -18,7 +18,7 @@ public async Task ParseJsonAllPartsVisibleTest() {
var markups =
await JsonConverter.ParseMarkups<bcf21.Markup>(
"Resources/json/v2.1/AllPartsVisible");
var markup = markups.FirstOrDefault()!;
var markup = (bcf21.Markup)markups.FirstOrDefault()!;
Assert.AreEqual(1, markups.Count);
Assert.AreEqual("ee9a9498-698b-44ed-8ece-b3ae3b480a90",
markup.Topic.Guid);
Expand All @@ -42,7 +42,7 @@ public async Task ParseJsonSkippingFilesTest() {
var markups =
await JsonConverter.ParseMarkups<bcf21.Markup>(
"Resources/json/v2.1/SkippingFiles");
var markup = markups.FirstOrDefault()!;
var markup = (bcf21.Markup)markups.FirstOrDefault()!;
Assert.AreEqual(0, markups.Count);
}

Expand Down Expand Up @@ -73,7 +73,7 @@ await JsonConverter
var root =
await JsonConverter.ParseObject<bcf30.Root>(
"Resources/json/v3.0/DocumentReferenceInternal/bcfRoot.json");
var markup = markups.FirstOrDefault()!;
var markup = (bcf30.Markup)markups.FirstOrDefault()!;
Assert.AreEqual(1, markups.Count);
var documentGuid = markup.Topic.DocumentReferences.FirstOrDefault()?.DocumentGuid;
var document = root.Document?.Documents.FirstOrDefault()!;
Expand Down

0 comments on commit 0257af7

Please sign in to comment.