Skip to content

Commit

Permalink
[Update] dependencies; refactor unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samatrhea committed Apr 28, 2024
1 parent 7c31639 commit 420f046
Show file tree
Hide file tree
Showing 19 changed files with 155 additions and 135 deletions.
4 changes: 2 additions & 2 deletions CDPBatchEditor.Tests/AppTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ public void VerifyRun()
{
this.app.Run();
this.commandDispatcher.Verify(x => x.Invoke(), Times.Once);
Assert.IsTrue(this.app.StopWatch.IsRunning);
Assert.That(this.app.StopWatch.IsRunning, Is.True);
}

[Test]
public void VerifyStop()
{
this.app.Stop();
this.sessionService.Verify(x => x.CloseAndSave(), Times.Once);
Assert.IsFalse(this.app.StopWatch.IsRunning);
Assert.That(this.app.StopWatch.IsRunning, Is.False);
}
}
}
12 changes: 6 additions & 6 deletions CDPBatchEditor.Tests/CDPBatchEditor.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit.Console" Version="3.16.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit.Console" Version="3.17.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
6 changes: 3 additions & 3 deletions CDPBatchEditor.Tests/CommandArgumentsTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public void VerifyToString()
{
var summary = this.commandArguments.ToString();
Console.WriteLine(summary);
Assert.IsNull(this.errors);
Assert.IsNotNull(summary);
Assert.IsNotEmpty(summary);
Assert.That(this.errors, Is.Null);
Assert.That(summary, Is.Not.Null);
Assert.That(summary, Is.Not.Empty);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public abstract class BaseCommandTestFixture
private Person person;
private SiteDirectory siteDirectory;
private SiteReferenceDataLibrary siteReferenceDataLibrary;
private Mock<ICDPMessageBus> messageBus;

private Uri uri;

Expand Down Expand Up @@ -187,11 +188,12 @@ internal virtual void BuildAction(string action)
private void SetupData()
{
this.Transactions.Clear();
this.messageBus = new Mock<ICDPMessageBus>();
this.SessionService = new Mock<ISessionService>();
this.FilterService = new Mock<IFilterService>();
this.Session = new Mock<ISession>();
this.uri = new Uri(BaseUri);
this.Assembler = new Assembler(this.uri);
this.Assembler = new Assembler(this.uri, this.messageBus.Object);
this.siteDirectory = new SiteDirectory(Guid.NewGuid(), this.Assembler.Cache, this.uri);

this.SetupDomainPersonAndParticipant();
Expand Down
48 changes: 25 additions & 23 deletions CDPBatchEditor.Tests/Commands/Command/DomainCommandTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,30 @@ internal override void BuildAction(string action)

private static void AssertThingHasExpectedOwner(DomainOfExpertise oldOwner, DomainOfExpertise newOwner, IOwnedThing thing)
{
Assert.IsNotNull(thing);
Assert.AreNotSame(oldOwner, thing.Owner);
Assert.AreSame(newOwner, thing.Owner);
Assert.That(thing, Is.Not.Null);
Assert.That(oldOwner, Is.Not.SameAs(thing.Owner));
Assert.That(newOwner, Is.SameAs(thing.Owner));


}

[Test]
public void VerifyChangeDomain()
{
Assert.AreEqual(0, this.Transactions.Count);
Assert.That(this.Transactions.Count, Is.EqualTo(0));

Assert.IsEmpty(this.Transactions.SelectMany(x => x.UpdatedThing));
Assert.That(this.Transactions.SelectMany(x => x.UpdatedThing), Is.Empty);

var action = "--action ChangeDomain -m TEST --parameters testParameter,testParameter2,P_mean --element-definition testElementDefinition --domain testDomain --to-domain testDomain2";
this.BuildAction(action);
this.domainCommand.ChangeDomain();

Assert.AreEqual(10, this.Transactions.Count);
Assert.That(this.Transactions.Count, Is.EqualTo(10));

Assert.IsNotEmpty(this.Transactions.SelectMany(x => x.UpdatedThing));
Assert.IsEmpty(this.Transactions.SelectMany(x => x.AddedThing));
Assert.That(this.Transactions.SelectMany(x => x.UpdatedThing), Is.Not.Empty);
Assert.That(this.Transactions.SelectMany(x => x.AddedThing), Is.Empty);

Assert.IsTrue(this.Transactions.All(x => x.UpdatedThing.Any() && x.UpdatedThing.All(y => y.Value is IOwnedThing p && p.Owner == this.Domain2)));
Assert.That(this.Transactions.All(x => x.UpdatedThing.Any() && x.UpdatedThing.All(y => y.Value is IOwnedThing p && p.Owner == this.Domain2)), Is.True);

var updatedParameters = this.Transactions.SelectMany(x => x.UpdatedThing.Values.Select(t => t as Parameter).Where(e => e != null));
var updatedElementDefinitions = this.Transactions.SelectMany(x => x.UpdatedThing.Values.Select(t => t as ElementDefinition).Where(e => e != null));
Expand All @@ -78,33 +80,33 @@ public void VerifyChangeDomain()
AssertThingHasExpectedOwner(this.Domain, this.Domain2, thing);
}

Assert.IsTrue(updatedElementDefinitions.Single().ShortName == this.TestElementDefinition.ShortName);
Assert.That(updatedElementDefinitions.Single().ShortName == this.TestElementDefinition.ShortName);
}

[Test]
public void VerifyChangeDomainFails()
{
Assert.AreEqual(0, this.Transactions.Count);
Assert.That(this.Transactions.Count, Is.EqualTo(0));

Assert.IsEmpty(this.Transactions.SelectMany(x => x.UpdatedThing));
Assert.That(this.Transactions.SelectMany(x => x.UpdatedThing), Is.Empty);

var action = "--action ChangeDomain -m TEST --parameters testParameter,testParameter2 --element-definition testElementDefinition --domain bla --to-domain bla2";
this.BuildAction(action);
this.domainCommand.ChangeDomain();

Assert.AreEqual(0, this.Transactions.Count);
Assert.That(this.Transactions.Count, Is.EqualTo(0));

action = "--action ChangeDomain -m TEST --parameters testParameter,testParameter2 --element-definition testElementDefinition --domain testDomain --to-domain testDomain";
this.BuildAction(action);
this.domainCommand.ChangeDomain();

Assert.AreEqual(0, this.Transactions.Count);
Assert.That(this.Transactions.Count, Is.EqualTo(0));

action = "--action ChangeDomain -m TEST --parameters testParameter,testParameter2 --element-definition testElementDefinition --domain testDomain --to-domain bla2";
this.BuildAction(action);
this.domainCommand.ChangeDomain();

Assert.AreEqual(0, this.Transactions.Count);
Assert.That(this.Transactions.Count, Is.EqualTo(0));
}

[Test]
Expand All @@ -114,8 +116,8 @@ public void VerifyChangeParameterOwnership()
this.BuildAction(action);
this.domainCommand.ChangeParameterOwnership();

Assert.AreEqual(2, this.Transactions.Count);
Assert.IsNotEmpty(this.Transactions.SelectMany(x => x.UpdatedThing));
Assert.That(this.Transactions.Count, Is.EqualTo(2));
Assert.That(this.Transactions.SelectMany(x => x.UpdatedThing), Is.Not.Empty);

foreach (var thing in this.Transactions.SelectMany(x => x.UpdatedThing.Values.Select(t => t as IOwnedThing)))
{
Expand All @@ -133,16 +135,16 @@ public void VerifySetGenericEquipmentOwnership()
var oldOwner2 = this.Parameter6.Owner;
var oldOwner3 = this.Parameter7.Owner;

Assert.AreSame(this.Domain, oldOwner1);
Assert.AreSame(this.Domain, oldOwner2);
Assert.AreSame(this.Domain, oldOwner3);
Assert.That(this.Domain, Is.SameAs(oldOwner1));
Assert.That(this.Domain, Is.SameAs(oldOwner2));
Assert.That(this.Domain, Is.SameAs(oldOwner3));

this.domainCommand.SetGenericEquipmentOwnership();

Assert.AreEqual(3, this.Transactions.Count);
Assert.That(this.Transactions.Count, Is.EqualTo(3));

Assert.IsNotEmpty(this.Transactions.SelectMany(x => x.UpdatedThing));
Assert.IsEmpty(this.Transactions.SelectMany(x => x.AddedThing));
Assert.That(this.Transactions.SelectMany(x => x.UpdatedThing), Is.Not.Empty);
Assert.That(this.Transactions.SelectMany(x => x.AddedThing), Is.Empty);

var updateParameters = this.Transactions.SelectMany(x => x.UpdatedThing).Where(u => u.Value is Parameter p).Select(u => u.Value as Parameter).ToList();
var parameter = updateParameters.FirstOrDefault(x => x.ParameterType.ShortName == this.Parameter5.ParameterType.ShortName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ public void VerifyApplyOptionDependence()

this.BuildAction($"--action {CommandEnumeration.ApplyOptionDependence} -m TEST --parameters {parameterShortName} --element-definition {elementDefinitionShortName} --domain testDomain ");

Assert.IsTrue(this.Iteration.Element
Assert.That(this.Iteration.Element
.FirstOrDefault(e => e.ShortName == elementDefinitionShortName)?.Parameter
.Where(p => p.ParameterType.ShortName == parameterShortName)
.All(p => !p.IsOptionDependent));
.All(p => !p.IsOptionDependent), Is.True);

this.optionCommand.ApplyOrRemoveOptionDependency(false);

Assert.IsTrue(
Assert.That(
this.Transactions.Any(
t => t.UpdatedThing.Any(
a => a.Value is Parameter p
&& p.IsOptionDependent
&& p.ParameterType.ShortName == parameterShortName)));
&& p.ParameterType.ShortName == parameterShortName)), Is.True);
}

[Test]
Expand All @@ -75,19 +75,19 @@ public void VerifyRemoveOptionDependence()

this.BuildAction($"--action {CommandEnumeration.RemoveOptionDependence} -m TEST --parameters {parameterShortName} --element-definition {elementDefinitionShortName} --domain testDomain ");

Assert.IsTrue(this.Iteration.Element
Assert.That(this.Iteration.Element
.FirstOrDefault(e => e.ShortName == elementDefinitionShortName)?.Parameter
.Where(p => p.ParameterType.ShortName == parameterShortName)
.All(p => p.IsOptionDependent));
.All(p => p.IsOptionDependent), Is.True);

this.optionCommand.ApplyOrRemoveOptionDependency(true);

Assert.IsTrue(
Assert.That(
this.Transactions.Any(
t => t.UpdatedThing.Any(
a => a.Value is Parameter p
&& !p.IsOptionDependent
&& p.ParameterType.ShortName == parameterShortName)));
&& p.ParameterType.ShortName == parameterShortName)), Is.True);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,28 @@ public void VerifyAddParameters()

this.parameterCommand.Add();

Assert.IsTrue(
Assert.That(
this.SessionService.Object.Transactions.Any(
t => t.AddedThing.Any(
a => a is Parameter p
&& p.ParameterType.ShortName == parameterUserFriendlyShortName)));
&& p.ParameterType.ShortName == parameterUserFriendlyShortName)), Is.True);

Assert.IsTrue(
Assert.That(
string.IsNullOrWhiteSpace(this.CommandArguments.ParameterGroup)
|| this.SessionService.Object.Transactions.Any(
t =>
t.AddedThing.Any(
a => a is ParameterGroup g
&& g.Name == parameterGroupdShortName)));
&& g.Name == parameterGroupdShortName)), Is.True);

Assert.IsTrue(
Assert.That(
string.IsNullOrWhiteSpace(this.CommandArguments.ParameterGroup)
|| this.SessionService.Object.Transactions.Any(
t =>
t.AddedThing.Any(
a => a is Parameter p
&& p.Group.Name == parameterGroupdShortName
&& p.ParameterType.ShortName == parameterUserFriendlyShortName)));
&& p.ParameterType.ShortName == parameterUserFriendlyShortName)), Is.True);
}

[Test]
Expand All @@ -90,11 +90,11 @@ public void VerifyRemoveParameters()

this.parameterCommand.Remove();

Assert.IsTrue(
Assert.That(
this.SessionService.Object.Transactions.Any(
t => t.DeletedThing.Any(
a => a.ClassKind == ClassKind.Parameter
&& a.UserFriendlyShortName == $"{elementDefinitionShortName}.{parameterUserFriendlyShortName}")));
&& a.UserFriendlyShortName == $"{elementDefinitionShortName}.{parameterUserFriendlyShortName}")), Is.True);
}
}
}
20 changes: 10 additions & 10 deletions CDPBatchEditor.Tests/Commands/Command/ScaleCommandTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ public void VerifyAssignMeasurementScale()

this.BuildAction($"--action {CommandEnumeration.SetScale} --scale {this.KilometerScale.ShortName} -m TEST --parameters {parameterShortName} --element-definition {elementDefinitionShortName} --domain testDomain ");

Assert.IsTrue(this.Iteration.Element
Assert.That(this.Iteration.Element
.FirstOrDefault(e => e.ShortName == elementDefinitionShortName)?
.Parameter.Where(p => p.ParameterType.ShortName == parameterShortName)
.All(p => p.Scale != this.KilometerScale));
.All(p => p.Scale != this.KilometerScale), Is.True);

this.scaleCommand.AssignMeasurementScale();

Assert.IsTrue(
Assert.That(
this.Transactions.All(
t => t.UpdatedThing.All(
a => a.Value is Parameter p
&& p.Scale == this.KilometerScale
&& p.ParameterType.ShortName == parameterShortName)));
&& p.ParameterType.ShortName == parameterShortName)), Is.True);
}

[Test]
Expand All @@ -77,13 +77,13 @@ public void VerifyAssignMeasurementScaleBadArgs()

this.scaleCommand.AssignMeasurementScale();

Assert.IsEmpty(this.Transactions);
Assert.That(this.Transactions, Is.Empty);

this.BuildAction($"--action {CommandEnumeration.SetScale} --scale {this.KilometerScale.ShortName} -m TEST --element-definition {elementDefinitionShortName} --domain testDomain ");

this.scaleCommand.AssignMeasurementScale();

Assert.IsEmpty(this.Transactions);
Assert.That(this.Transactions, Is.Empty);
}

[Test]
Expand All @@ -94,22 +94,22 @@ public void VerifyStandardizeDimensionsInMillimetre()

this.BuildAction($"--action {CommandEnumeration.StandardizeDimensionsInMillimeter} -m TEST --parameters {parameterShortName} --element-definition {elementDefinitionShortName} --domain testDomain ");

Assert.IsTrue(this.Iteration.Element
Assert.That(this.Iteration.Element
.FirstOrDefault(e => e.ShortName == elementDefinitionShortName)?
.Parameter.Where(p => p.ParameterType.ShortName == parameterShortName)
.All(p => p.Scale != this.MillimeterScale));
.All(p => p.Scale != this.MillimeterScale), Is.True);

this.scaleCommand.StandardizeDimensionsInMillimetre();

Assert.IsTrue(
Assert.That(
this.Transactions.Any(
t => t.UpdatedThing.Any(
a => a.Value is Parameter p
&& p.Scale == this.MillimeterScale
&& p.ParameterType.ShortName == parameterShortName) || t.UpdatedThing.Any(
a => a.Value is ParameterSubscription p
&& p.Scale == this.MillimeterScale
&& p.ParameterType.ShortName == parameterShortName)));
&& p.ParameterType.ShortName == parameterShortName)), Is.True);
}
}
}
Loading

0 comments on commit 420f046

Please sign in to comment.