Skip to content

Commit

Permalink
[REFACTOR] Make CDPMessagebus non static and injectable; fixes #280
Browse files Browse the repository at this point in the history
* Make CDPMessagebus non static and injectable.
* Review comments
* MessageBus should be a private field of Session and not public property on ISession
* Small finetuning
* Bump version numbers
  • Loading branch information
lxatstariongroup authored Jan 23, 2024
1 parent bff2567 commit f0b9fb4
Show file tree
Hide file tree
Showing 71 changed files with 1,566 additions and 1,202 deletions.
5 changes: 2 additions & 3 deletions CDP4Common/CDP4Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net462;net47;net471;net472;net48;netstandard2.0;netstandard2.1</TargetFrameworks>
<Company>RHEA System S.A.</Company>
<Title>CDP4Common Community Edition</Title>
<VersionPrefix>24.6.0</VersionPrefix>
<VersionPrefix>25.0.0</VersionPrefix>
<Description>CDP4 Common Class Library that contains DTOs, POCOs</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander, Yevhen, Nathanael, Ahmed</Authors>
Expand All @@ -20,8 +20,7 @@
<PackageTags>CDP COMET ECSS-E-TM-10-25</PackageTags>
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
<PackageReleaseNotes>
[ADD] Support for querying supported data model versions
[ADD] ValidationService and EmailAddress validation improvement
[REFACTOR] CDPMessageBus from static class to injectable interface implementation
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
50 changes: 28 additions & 22 deletions CDP4Dal.NetCore.Tests/AssemblerTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AssemblerTestFixture.cs" company="RHEA System S.A.">
// Copyright (c) 2015-2019 RHEA System S.A.
// Copyright (c) 2015-2024 RHEA System S.A.
//
// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou
//
// This file is part of CDP4-SDK Community Edition
//
// The CDP4-SDK Community Edition is free software; you can redistribute it and/or
// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate, Omar Elebiary, Jaime Bernar
//
// This file is part of CDP4-COMET SDK Community Edition
//
// The CDP4-COMET SDK Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// The CDP4-SDK Community Edition is distributed in the hope that it will be useful,
//
// The CDP4-COMET SDK Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Expand All @@ -32,6 +32,9 @@ namespace CDP4Dal.Tests
using CDP4Common.EngineeringModelData;
using CDP4Common.SiteDirectoryData;
using CDP4Common.Types;

using Moq;

using NUnit.Framework;
using Dto = CDP4Common.DTO;

Expand All @@ -42,12 +45,15 @@ public class AssemblerTestFixture
private Dto.SiteDirectory siteDir;
private Dto.SiteReferenceDataLibrary siteRdl;
private Uri uri;
private CDPMessageBus messageBus;

[SetUp]
public void SetUp()
{
this.uri = new Uri("http://www.rheagroup.com");

this.messageBus = new CDPMessageBus();

this.testInput = new List<Dto.Thing>();

//Top container
Expand Down Expand Up @@ -91,22 +97,22 @@ public void SetUp()
public void TearDown()
{
this.testInput.Clear();
CDPMessageBus.Current.ClearSubscriptions();
this.messageBus.ClearSubscriptions();
}

[Test]
public void VerifyThatAssemblerThrowsNullReferenceExceptionWhenUriIsNull()
{
Assert.Throws<NullReferenceException>(() =>
{
var assembler = new Assembler(null);
var assembler = new Assembler(null, this.messageBus);
});
}

[Test]
public void AssertThatCacheCanStoreThings()
{
var assembler = new Assembler(this.uri);
var assembler = new Assembler(this.uri, this.messageBus);

// Check that the cache is empty
Assert.IsFalse(assembler.Cache.Skip(0).Any());
Expand Down Expand Up @@ -136,7 +142,7 @@ public void AssertThatCacheCanStoreThings()
[Test]
public async Task AssertThatAssemblerSynchronizationWorks()
{
var assembler = new Assembler(this.uri);
var assembler = new Assembler(this.uri, this.messageBus);

// 1st call of Synnchronize
await assembler.Synchronize(this.testInput);
Expand Down Expand Up @@ -181,7 +187,7 @@ public async Task AssertThatAssemblerSynchronizationWorks()
[Test]
public async Task VerifyThatAssemblerCanUpdateExistingPoco()
{
var assembler = new Assembler(this.uri);
var assembler = new Assembler(this.uri, this.messageBus);
await assembler.Synchronize(this.testInput);

var siteDir = assembler.Cache.Select(x => x.Value)
Expand Down Expand Up @@ -210,7 +216,7 @@ public async Task VerifyThatAssemblerCanUpdateExistingPoco()
[Test]
public void VerifyThatArgumentThrown()
{
var assembler = new Assembler(this.uri);
var assembler = new Assembler(this.uri, this.messageBus);

Assert.ThrowsAsync<ArgumentNullException>(async() =>
{
Expand Down Expand Up @@ -238,7 +244,7 @@ public async Task VerifyThatAssemblerCanMoveThings()
category
};

var assembler = new Assembler(this.uri);
var assembler = new Assembler(this.uri, this.messageBus);
await assembler.Synchronize(dtos);

Assert.AreEqual(4, assembler.Cache.Count);
Expand Down Expand Up @@ -313,7 +319,7 @@ public void VerifyThatMultipleIterationCanBeSynchronized()
category
};

var assembler = new Assembler(this.uri);
var assembler = new Assembler(this.uri, this.messageBus);
assembler.Synchronize(dtos);

dtos = new List<Dto.Thing>
Expand All @@ -335,7 +341,7 @@ public void VerifyThatMultipleIterationCanBeSynchronized()
[Test]
public async Task VerifyThatCloseRdlWorks()
{
var assembler = new Assembler(this.uri);
var assembler = new Assembler(this.uri, this.messageBus);
// 1st call of Synnchronize
await assembler.Synchronize(this.testInput);

Expand Down Expand Up @@ -366,7 +372,7 @@ public async Task VerifyThatCitationIsResolvedWhenRdlIsLoaded()
domain.Definition.Add(definition.Iid);
definition.Citation.Add(citation.Iid);

var assembler = new Assembler(this.uri);
var assembler = new Assembler(this.uri, this.messageBus);
var input = new List<Dto.Thing>();
input.Add(sitedir);
input.Add(domain);
Expand Down Expand Up @@ -394,7 +400,7 @@ public async Task VerifyThatCitationIsResolvedWhenRdlIsLoaded()
[Test]
public async Task VerifyThatIterationIsDeletedWhenSetupIsDeleted()
{
var assembler = new Assembler(this.uri);
var assembler = new Assembler(this.uri, this.messageBus);

var model = new EngineeringModel(Guid.NewGuid(), assembler.Cache, this.uri);
var it1 = new Iteration(Guid.NewGuid(), assembler.Cache, this.uri);
Expand Down Expand Up @@ -433,7 +439,7 @@ public async Task VerifyThatIterationIsDeletedWhenSetupIsDeleted()
[Test]
public async Task VerifyThatModelIsDeletedWhenSetupIsDeleted()
{
var assembler = new Assembler(this.uri);
var assembler = new Assembler(this.uri, this.messageBus);

var model = new EngineeringModel(Guid.NewGuid(), assembler.Cache, this.uri);
var it1 = new Iteration(Guid.NewGuid(), assembler.Cache, this.uri);
Expand Down Expand Up @@ -468,7 +474,7 @@ public async Task VerifyThatModelIsDeletedWhenSetupIsDeleted()
[Test]
public async Task VerifyThatSynchronizationPreservesKeysOfOrderedItemList()
{
var assembler = new Assembler(this.uri);
var assembler = new Assembler(this.uri, this.messageBus);

var simpleUnit = new Dto.SimpleUnit(Guid.NewGuid(), 1) { Name = "Unit", ShortName = "unit" };
var ratioScale = new Dto.RatioScale(Guid.NewGuid(), 1) { Name = "Ration", ShortName = "ratio", NumberSet = NumberSetKind.INTEGER_NUMBER_SET };
Expand Down
2 changes: 1 addition & 1 deletion CDP4Dal.NetCore.Tests/DtoRouteResolverTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void Setup()
this.iteration.PossibleFiniteStateList.Add(this.statelist.Iid);
this.statelist.PossibleState.Add(new OrderedItem { K = 1, V = this.state.Iid });

this.assembler = new Assembler(this.uri);
this.assembler = new Assembler(this.uri, new CDPMessageBus());
this.session = new Mock<ISession>();
this.session.Setup(x => x.Assembler).Returns(this.assembler);

Expand Down
Loading

0 comments on commit f0b9fb4

Please sign in to comment.