From 420f046def96acb98f5b4799c2668e765756da61 Mon Sep 17 00:00:00 2001 From: samatrhea Date: Sun, 28 Apr 2024 19:32:45 +0200 Subject: [PATCH] [Update] dependencies; refactor unit tests --- CDPBatchEditor.Tests/AppTestFixture.cs | 4 +- .../CDPBatchEditor.Tests.csproj | 12 ++--- .../CommandArgumentsTestFixture.cs | 6 +-- .../Command/BaseCommandTestFixture.cs | 4 +- .../Command/DomainCommandTestFixture.cs | 48 ++++++++++--------- .../Command/OptionCommandTestFixture.cs | 16 +++---- .../Command/ParameterCommandTestFixture.cs | 16 +++---- .../Command/ScaleCommandTestFixture.cs | 20 ++++---- .../Command/StateCommandTestFixture.cs | 20 ++++---- .../Command/SubscriptionCommandTestFixture.cs | 28 +++++------ .../Command/ValueSetCommandTestFixture.cs | 20 ++++---- .../Commands/ReportGeneratorTestFixture.cs | 4 +- CDPBatchEditor.Tests/ProgramTestFixture.cs | 18 +++---- .../Resources/ResourcesTestFixture.cs | 4 +- .../Services/FilterServiceTestFixture.cs | 26 +++++----- .../Services/SessionServiceTestFixture.cs | 14 +++--- CDPBatchEditor/AppContainer.cs | 4 ++ CDPBatchEditor/CDPBatchEditor.csproj | 16 +++---- CDPBatchEditor/Services/SessionService.cs | 10 +++- 19 files changed, 155 insertions(+), 135 deletions(-) diff --git a/CDPBatchEditor.Tests/AppTestFixture.cs b/CDPBatchEditor.Tests/AppTestFixture.cs index e3fe957..5d56a8e 100644 --- a/CDPBatchEditor.Tests/AppTestFixture.cs +++ b/CDPBatchEditor.Tests/AppTestFixture.cs @@ -52,7 +52,7 @@ 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] @@ -60,7 +60,7 @@ 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); } } } diff --git a/CDPBatchEditor.Tests/CDPBatchEditor.Tests.csproj b/CDPBatchEditor.Tests/CDPBatchEditor.Tests.csproj index b2d03c2..c5a387a 100644 --- a/CDPBatchEditor.Tests/CDPBatchEditor.Tests.csproj +++ b/CDPBatchEditor.Tests/CDPBatchEditor.Tests.csproj @@ -12,19 +12,19 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/CDPBatchEditor.Tests/CommandArgumentsTestFixture.cs b/CDPBatchEditor.Tests/CommandArgumentsTestFixture.cs index 651840d..56b7515 100644 --- a/CDPBatchEditor.Tests/CommandArgumentsTestFixture.cs +++ b/CDPBatchEditor.Tests/CommandArgumentsTestFixture.cs @@ -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); } } } diff --git a/CDPBatchEditor.Tests/Commands/Command/BaseCommandTestFixture.cs b/CDPBatchEditor.Tests/Commands/Command/BaseCommandTestFixture.cs index f525ed9..3f9d0ba 100644 --- a/CDPBatchEditor.Tests/Commands/Command/BaseCommandTestFixture.cs +++ b/CDPBatchEditor.Tests/Commands/Command/BaseCommandTestFixture.cs @@ -68,6 +68,7 @@ public abstract class BaseCommandTestFixture private Person person; private SiteDirectory siteDirectory; private SiteReferenceDataLibrary siteReferenceDataLibrary; + private Mock messageBus; private Uri uri; @@ -187,11 +188,12 @@ internal virtual void BuildAction(string action) private void SetupData() { this.Transactions.Clear(); + this.messageBus = new Mock(); this.SessionService = new Mock(); this.FilterService = new Mock(); this.Session = new Mock(); 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(); diff --git a/CDPBatchEditor.Tests/Commands/Command/DomainCommandTestFixture.cs b/CDPBatchEditor.Tests/Commands/Command/DomainCommandTestFixture.cs index bf052d0..5d1f5bf 100644 --- a/CDPBatchEditor.Tests/Commands/Command/DomainCommandTestFixture.cs +++ b/CDPBatchEditor.Tests/Commands/Command/DomainCommandTestFixture.cs @@ -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)); @@ -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] @@ -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))) { @@ -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); diff --git a/CDPBatchEditor.Tests/Commands/Command/OptionCommandTestFixture.cs b/CDPBatchEditor.Tests/Commands/Command/OptionCommandTestFixture.cs index 1112030..b7ef9e9 100644 --- a/CDPBatchEditor.Tests/Commands/Command/OptionCommandTestFixture.cs +++ b/CDPBatchEditor.Tests/Commands/Command/OptionCommandTestFixture.cs @@ -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] @@ -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); } } } diff --git a/CDPBatchEditor.Tests/Commands/Command/ParameterCommandTestFixture.cs b/CDPBatchEditor.Tests/Commands/Command/ParameterCommandTestFixture.cs index e3c16bb..255db50 100644 --- a/CDPBatchEditor.Tests/Commands/Command/ParameterCommandTestFixture.cs +++ b/CDPBatchEditor.Tests/Commands/Command/ParameterCommandTestFixture.cs @@ -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] @@ -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); } } } diff --git a/CDPBatchEditor.Tests/Commands/Command/ScaleCommandTestFixture.cs b/CDPBatchEditor.Tests/Commands/Command/ScaleCommandTestFixture.cs index bc8cc56..65b9a9a 100644 --- a/CDPBatchEditor.Tests/Commands/Command/ScaleCommandTestFixture.cs +++ b/CDPBatchEditor.Tests/Commands/Command/ScaleCommandTestFixture.cs @@ -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] @@ -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] @@ -94,14 +94,14 @@ 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 @@ -109,7 +109,7 @@ public void VerifyStandardizeDimensionsInMillimetre() && 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); } } } diff --git a/CDPBatchEditor.Tests/Commands/Command/StateCommandTestFixture.cs b/CDPBatchEditor.Tests/Commands/Command/StateCommandTestFixture.cs index 58eb20f..0931b88 100644 --- a/CDPBatchEditor.Tests/Commands/Command/StateCommandTestFixture.cs +++ b/CDPBatchEditor.Tests/Commands/Command/StateCommandTestFixture.cs @@ -52,19 +52,19 @@ public void VerifyApplyStateDependency() this.BuildAction($"--action {CommandEnumeration.ApplyOptionDependence} --state actualFiniteStateListTest -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.StateDependence is null)); + .All(p => p.StateDependence is null), Is.True); this.stateCommand.ApplyOrRemoveStateDependency(false); - Assert.IsTrue( + Assert.That( this.Transactions.All( t => t.UpdatedThing.All( a => a.Value is Parameter p && p.StateDependence == this.ActualPossibleFiniteStateList - && p.ParameterType.ShortName == parameterShortName))); + && p.ParameterType.ShortName == parameterShortName)), Is.True); } [Test] @@ -77,13 +77,13 @@ public void VerifyApplyStateDependencyBadArgs() this.stateCommand.ApplyOrRemoveStateDependency(false); - Assert.IsEmpty(this.Transactions); + Assert.That(this.Transactions, Is.Empty); this.BuildAction($"--action {CommandEnumeration.ApplyOptionDependence} --state actualFiniteStateListTestBad -m TEST --parameters {parameterShortName} --element-definition {elementDefinitionShortName} --domain testDomain "); this.stateCommand.ApplyOrRemoveStateDependency(false); - Assert.IsEmpty(this.Transactions); + Assert.That(this.Transactions, Is.Empty); } [Test] @@ -94,19 +94,19 @@ public void VerifyRemoveStateDependency() this.BuildAction($"--action {CommandEnumeration.RemoveStateDependence} --state actualFiniteStateListTest -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.StateDependence == this.ActualPossibleFiniteStateList)); + .All(p => p.StateDependence == this.ActualPossibleFiniteStateList), Is.True); this.stateCommand.ApplyOrRemoveStateDependency(true); - Assert.IsTrue( + Assert.That( this.Transactions.All( t => t.UpdatedThing.All( a => a.Value is Parameter p && p.StateDependence is null - && p.ParameterType.ShortName == parameterShortName))); + && p.ParameterType.ShortName == parameterShortName)), Is.True); } } } diff --git a/CDPBatchEditor.Tests/Commands/Command/SubscriptionCommandTestFixture.cs b/CDPBatchEditor.Tests/Commands/Command/SubscriptionCommandTestFixture.cs index e46df3b..c9d5bc1 100644 --- a/CDPBatchEditor.Tests/Commands/Command/SubscriptionCommandTestFixture.cs +++ b/CDPBatchEditor.Tests/Commands/Command/SubscriptionCommandTestFixture.cs @@ -51,22 +51,22 @@ public void VerifySetParameterSubscriptionsSwitch() const string parameterUserFriendlyShortName = "testParameter3", elementDefinitionShortName = "testElementDefinition"; this.BuildAction($"--action={CommandEnumeration.Subscribe} --parameter-switch REFERENCE -m TEST --parameters={parameterUserFriendlyShortName} --element-definition={elementDefinitionShortName} --domain=testDomain"); - Assert.IsTrue(this.Parameter4.ParameterSubscription.All( + Assert.That(this.Parameter4.ParameterSubscription.All( s => s.ValueSet.All( - v => v.ValueSwitch == ParameterSwitchKind.MANUAL))); + v => v.ValueSwitch == ParameterSwitchKind.MANUAL)), Is.True); this.subscriptionCommand.SetParameterSubscriptionsSwitch(); var things = this.Transactions.SelectMany(t => t.UpdatedThing.Select(a => a.Value)).ToArray(); - Assert.AreEqual(1, things.Length); + Assert.That(things.Length, Is.EqualTo(1)); var valueSet = things.First() as ParameterSubscriptionValueSet; var parameter = valueSet?.GetContainerOfType(); - Assert.IsNotNull(parameter); - Assert.IsTrue(parameter.ParameterType.ShortName == parameterUserFriendlyShortName); + Assert.That(parameter, Is.Not.Null); + Assert.That(parameter.ParameterType.ShortName == parameterUserFriendlyShortName, Is.True); - Assert.IsNotNull(valueSet); - Assert.AreEqual(ParameterSwitchKind.REFERENCE, valueSet.ValueSwitch); + Assert.That(valueSet, Is.Not.Null); + Assert.That(valueSet.ValueSwitch, Is.EqualTo(ParameterSwitchKind.REFERENCE)); } [Test] @@ -75,18 +75,18 @@ public void VerifySubscribeToParameters() const string parameterUserFriendlyShortName = "testParameter2", elementDefinitionShortName = "testElementDefinition", domain = "testDomain2"; this.BuildAction($"--action={CommandEnumeration.Subscribe} -m TEST --parameters={parameterUserFriendlyShortName} --element-definition={elementDefinitionShortName} --domain={domain}"); - Assert.IsFalse(this.Parameter2.ParameterSubscription.Any()); + Assert.That(this.Parameter2.ParameterSubscription.Any(), Is.False); this.subscriptionCommand.Subscribe(); - Assert.AreEqual(1, this.Transactions.First().UpdatedThing.Count); - Assert.AreEqual(1, this.Transactions.First().AddedThing.Count()); + Assert.That(this.Transactions.First().UpdatedThing.Count, Is.EqualTo(1)); + Assert.That(this.Transactions.First().AddedThing.Count(), Is.EqualTo(1)); - Assert.IsTrue(this.Transactions.Any(t => t.AddedThing.Any(p => p is ParameterSubscription s && s.Owner == this.Domain2))); + Assert.That(this.Transactions.Any(t => t.AddedThing.Any(p => p is ParameterSubscription s && s.Owner == this.Domain2)), Is.True); - Assert.IsTrue(this.Transactions.Any(t => t.UpdatedThing.Any(u => u.Value is Parameter p + Assert.That(this.Transactions.Any(t => t.UpdatedThing.Any(u => u.Value is Parameter p && p.ParameterSubscription.Any(s => s.Owner.ShortName == domain) - && p.ParameterType.ShortName == parameterUserFriendlyShortName))); + && p.ParameterType.ShortName == parameterUserFriendlyShortName)), Is.True); } [Test] @@ -97,7 +97,7 @@ public void VerifyBadSubscribeToParameters() this.subscriptionCommand.Subscribe(); - Assert.IsEmpty(this.Transactions); + Assert.That(this.Transactions, Is.Empty); this.BuildAction($"--action={CommandEnumeration.Subscribe} -m TEST --element-definition={elementDefinitionShortName}"); diff --git a/CDPBatchEditor.Tests/Commands/Command/ValueSetCommandTestFixture.cs b/CDPBatchEditor.Tests/Commands/Command/ValueSetCommandTestFixture.cs index 9581b79..56dfd58 100644 --- a/CDPBatchEditor.Tests/Commands/Command/ValueSetCommandTestFixture.cs +++ b/CDPBatchEditor.Tests/Commands/Command/ValueSetCommandTestFixture.cs @@ -53,33 +53,33 @@ public void VerifyMoveReferenceValuesToManualValues() this.BuildAction($"--action {CommandEnumeration.MoveReferenceValuesToManualValues} -m TEST --parameters {parameterShortName} --element-definition {elementDefinitionShortName} --domain testDomain "); var elementDefinition = this.Iteration.Element.FirstOrDefault(e => e.ShortName == elementDefinitionShortName); - Assert.IsNotNull(elementDefinition); + Assert.That(elementDefinition, Is.Not.Null); var parameter = elementDefinition.Parameter.Where(p => p.ParameterType.ShortName == parameterShortName).ToArray(); - Assert.IsNotEmpty(parameter); + Assert.That(parameter, Is.Not.Empty); - Assert.IsTrue( + Assert.That( parameter.All( p => p.ValueSet.Any( v => v.ValueSwitch == ParameterSwitchKind.REFERENCE && v.Reference - .Any(vr => vr == this.ValueSet.Reference.FirstOrDefault())))); + .Any(vr => vr == this.ValueSet.Reference.FirstOrDefault()))), Is.True); - Assert.IsTrue( + Assert.That( parameter.All( p => p.ValueSet.Any( - v => v.Manual.All(vr => vr == "-")))); + v => v.Manual.All(vr => vr == "-"))), Is.True); this.valueSetCommand.MoveReferenceValuesToManualValues(); var thing = this.Transactions.Select(t => t.AddedThing.Single(a => a is ParameterValueSet)).FirstOrDefault(); - Assert.IsTrue(thing?.GetContainerOfType().ParameterType.ShortName == parameterShortName); + Assert.That(thing?.GetContainerOfType().ParameterType.ShortName == parameterShortName, Is.True); - Assert.IsInstanceOf(thing); + Assert.That(thing, Is.InstanceOf()); var parameterValueSet = (ParameterValueSet) thing; - Assert.IsTrue(parameterValueSet.ValueSwitch == ParameterSwitchKind.MANUAL); - Assert.IsTrue(parameterValueSet.Manual.Any(vr => vr == this.ValueSet.Reference.FirstOrDefault())); + Assert.That(parameterValueSet.ValueSwitch == ParameterSwitchKind.MANUAL, Is.True); + Assert.That(parameterValueSet.Manual.Any(vr => vr == this.ValueSet.Reference.FirstOrDefault()), Is.True); } } } diff --git a/CDPBatchEditor.Tests/Commands/ReportGeneratorTestFixture.cs b/CDPBatchEditor.Tests/Commands/ReportGeneratorTestFixture.cs index c16cc5f..f9c4f9e 100644 --- a/CDPBatchEditor.Tests/Commands/ReportGeneratorTestFixture.cs +++ b/CDPBatchEditor.Tests/Commands/ReportGeneratorTestFixture.cs @@ -100,12 +100,14 @@ public void Setup() private SimpleQuantityKind parameterType4; private Mock sessionService; private ReportGenerator reportGenerator; + private Mock messageBus; private void SetupData() { + this.messageBus = new Mock(); this.sessionService = new Mock(); 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(); diff --git a/CDPBatchEditor.Tests/ProgramTestFixture.cs b/CDPBatchEditor.Tests/ProgramTestFixture.cs index 12b70df..bec9ae1 100644 --- a/CDPBatchEditor.Tests/ProgramTestFixture.cs +++ b/CDPBatchEditor.Tests/ProgramTestFixture.cs @@ -73,21 +73,21 @@ private void VerifyCalls(Times times) public void VerifyAssemblyVersion() { var version = Program.QueryBatchEditorVersion(); - Assert.IsNotNull(version); - Assert.AreEqual(4, version.Split('.').Length); - Assert.IsNotNull(new Version(version)); + Assert.That(version, Is.Not.Null); + Assert.That(version.Split('.').Length, Is.EqualTo(4)); + Assert.That(new Version(version), Is.Not.Null); } [Test] public void VerifyContainer() { AppContainer.BuildContainer(this.commandArguments.Object); - Assert.IsNotNull(AppContainer.Container); - Assert.IsNotEmpty(AppContainer.Container.ComponentRegistry.Registrations); - Assert.IsTrue(AppContainer.Container.IsRegistered()); - Assert.IsTrue(AppContainer.Container.IsRegistered()); - Assert.IsTrue(AppContainer.Container.IsRegistered()); - Assert.IsTrue(AppContainer.Container.IsRegistered()); + Assert.That(AppContainer.Container, Is.Not.Null); + Assert.That(AppContainer.Container.ComponentRegistry.Registrations, Is.Not.Empty); + Assert.That(AppContainer.Container.IsRegistered()); + Assert.That(AppContainer.Container.IsRegistered()); + Assert.That(AppContainer.Container.IsRegistered()); + Assert.That(AppContainer.Container.IsRegistered()); } [Test] diff --git a/CDPBatchEditor.Tests/Resources/ResourcesTestFixture.cs b/CDPBatchEditor.Tests/Resources/ResourcesTestFixture.cs index 2c39f27..db8b4fe 100644 --- a/CDPBatchEditor.Tests/Resources/ResourcesTestFixture.cs +++ b/CDPBatchEditor.Tests/Resources/ResourcesTestFixture.cs @@ -49,8 +49,8 @@ public void Setup() public void LoadEmbeddedResource() { var resource = this.resourceLoader.LoadEmbeddedResource(this.path); - Assert.IsNotNull(resource); - Assert.IsNotEmpty(resource); + Assert.That(resource, Is.Not.Null); + Assert.That(resource, Is.Not.Empty); Assert.Throws(() => this.resourceLoader.LoadEmbeddedResource(null)); Assert.Throws(() => this.resourceLoader.LoadEmbeddedResource("thispathdoesnotexist")); } diff --git a/CDPBatchEditor.Tests/Services/FilterServiceTestFixture.cs b/CDPBatchEditor.Tests/Services/FilterServiceTestFixture.cs index 75c1706..2c6e9d4 100644 --- a/CDPBatchEditor.Tests/Services/FilterServiceTestFixture.cs +++ b/CDPBatchEditor.Tests/Services/FilterServiceTestFixture.cs @@ -46,10 +46,11 @@ public class FilterServiceTestFixture [SetUp] public void Setup() { + this.messageBus = new Mock(); this.commandArguments = new Mock(); this.uri = new Uri(BaseUri); - this.assembler = new Assembler(this.uri); + this.assembler = new Assembler(this.uri, this.messageBus.Object); this.iteration = new Iteration(Guid.NewGuid(), this.assembler.Cache, this.uri); @@ -100,6 +101,7 @@ public void Setup() private const string BaseUri = "http://test.com"; private Mock commandArguments; + private Mock messageBus; private FilterService filterService; private Uri uri; private Assembler assembler; @@ -118,34 +120,34 @@ public void VerifyIsFilteredInOrFilterIsEmpty() { var dummyElement = new ElementDefinition() { ShortName = "null" }; this.filterService.ProcessFilters(this.iteration, this.siteDirectory.Domain); - Assert.IsTrue(this.filterService.IsFilteredInOrFilterIsEmpty(this.elementDefinition)); + Assert.That(this.filterService.IsFilteredInOrFilterIsEmpty(this.elementDefinition), Is.True); - Assert.IsFalse(this.filterService.IsFilteredInOrFilterIsEmpty(dummyElement)); + Assert.That(this.filterService.IsFilteredInOrFilterIsEmpty(dummyElement), Is.False); this.filterService.FilteredElementDefinitions.Clear(); - Assert.IsTrue(this.filterService.IsFilteredInOrFilterIsEmpty(dummyElement)); + Assert.That(this.filterService.IsFilteredInOrFilterIsEmpty(dummyElement), Is.True); } [Test] public void VerifyIsParameterSpecifiedOrAny() { - Assert.IsFalse(this.filterService.IsParameterSpecifiedOrAny(new Parameter() { ParameterType = new BooleanParameterType() { ShortName = "returnFalse" } })); + Assert.That(this.filterService.IsParameterSpecifiedOrAny(new Parameter() { ParameterType = new BooleanParameterType() { ShortName = "returnFalse" } }), Is.False); - Assert.IsTrue(this.filterService.IsParameterSpecifiedOrAny(this.parameter)); + Assert.That(this.filterService.IsParameterSpecifiedOrAny(this.parameter), Is.True); this.commandArguments.Setup(x => x.SelectedParameters).Returns(new List()); - Assert.IsEmpty(this.commandArguments.Object.SelectedParameters); - Assert.IsTrue(this.filterService.IsParameterSpecifiedOrAny(this.parameter)); + Assert.That(this.commandArguments.Object.SelectedParameters, Is.Empty); + Assert.That(this.filterService.IsParameterSpecifiedOrAny(this.parameter), Is.True); } [Test] public void VerifyProcessFilters() { - Assert.IsEmpty(this.filterService.FilteredElementDefinitions); - Assert.IsEmpty(this.filterService.IncludedOwners); + Assert.That(this.filterService.FilteredElementDefinitions, Is.Empty); + Assert.That(this.filterService.IncludedOwners, Is.Empty); this.filterService.ProcessFilters(this.iteration, this.siteDirectory.Domain); - Assert.IsNotEmpty(this.filterService.FilteredElementDefinitions); - Assert.AreEqual(2, this.filterService.IncludedOwners.Count); + Assert.That(this.filterService.FilteredElementDefinitions, Is.Not.Empty); + Assert.That(this.filterService.IncludedOwners.Count, Is.EqualTo(2)); } } } diff --git a/CDPBatchEditor.Tests/Services/SessionServiceTestFixture.cs b/CDPBatchEditor.Tests/Services/SessionServiceTestFixture.cs index a00b3ba..e646ab9 100644 --- a/CDPBatchEditor.Tests/Services/SessionServiceTestFixture.cs +++ b/CDPBatchEditor.Tests/Services/SessionServiceTestFixture.cs @@ -48,11 +48,12 @@ public class SessionServiceTestFixture [SetUp] public void Setup() { + this.messageBus = new Mock(); this.commandArguments = new Mock(); this.filterService = new Mock(); this.session = new Mock(); 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); var iterationSetup = new IterationSetup(Guid.NewGuid(), this.assembler.Cache, this.uri); @@ -91,7 +92,7 @@ public void Setup() this.commandArguments.Setup(x => x.UserName).Returns("admin"); this.commandArguments.Setup(x => x.DryRun).Returns(false); - this.sessionService = new SessionService(this.commandArguments.Object, this.filterService.Object, this.session.Object); + this.sessionService = new SessionService(this.commandArguments.Object, this.filterService.Object, this.session.Object, this.messageBus.Object); } private const string BaseUri = "http://test.com"; @@ -107,6 +108,7 @@ public void Setup() private Mock filterService; private Mock commandArguments; private EngineeringModel engineeringModel; + private Mock messageBus; private ThingTransaction CreateDummyTransactions() { @@ -133,7 +135,7 @@ public void VerifySaveClose() this.sessionService.Transactions.Add(this.CreateDummyTransactions()); this.sessionService.Transactions.Add(this.CreateDummyTransactions()); - Assert.AreEqual(3, this.sessionService.Transactions.Count); + Assert.That(this.sessionService.Transactions.Count, Is.EqualTo(3)); this.sessionService.CloseAndSave(); this.sessionService.Transactions.Clear(); @@ -141,20 +143,20 @@ public void VerifySaveClose() this.session.Verify(x => x.Write(It.IsAny()), Times.Exactly(3)); this.session.Setup(x => x.RetrieveSiteDirectory()); - Assert.IsFalse(this.sessionService.IsSessionOpen()); + Assert.That(this.sessionService.IsSessionOpen(), Is.False); this.sessionService.Close(); } [Test] public void VerifySessionOpen() { - Assert.IsTrue(this.sessionService.IsSessionOpen()); + Assert.That(this.sessionService.IsSessionOpen(), Is.True); } [Test] public void VerifySetProperties() { - Assert.IsTrue(this.sessionService.SetProperties()); + Assert.That(this.sessionService.SetProperties(), Is.True); } } } diff --git a/CDPBatchEditor/AppContainer.cs b/CDPBatchEditor/AppContainer.cs index c0eb7f9..4629a6f 100644 --- a/CDPBatchEditor/AppContainer.cs +++ b/CDPBatchEditor/AppContainer.cs @@ -36,6 +36,8 @@ namespace CDPBatchEditor using CDPBatchEditor.Services; using CDPBatchEditor.Services.Interfaces; + using CDP4Dal; + /// /// Provides a /// @@ -68,6 +70,8 @@ public static void BuildContainer(ICommandArguments commandArguments) containerBuilder.RegisterType().As(); containerBuilder.RegisterType().As(); containerBuilder.RegisterType().As(); + containerBuilder.RegisterType().As().SingleInstance(); + Container = containerBuilder.Build(); } } diff --git a/CDPBatchEditor/CDPBatchEditor.csproj b/CDPBatchEditor/CDPBatchEditor.csproj index f5d1502..1b38a7c 100644 --- a/CDPBatchEditor/CDPBatchEditor.csproj +++ b/CDPBatchEditor/CDPBatchEditor.csproj @@ -46,14 +46,14 @@ - - - - - - - - + + + + + + + + diff --git a/CDPBatchEditor/Services/SessionService.cs b/CDPBatchEditor/Services/SessionService.cs index b51bbb6..b6f8719 100644 --- a/CDPBatchEditor/Services/SessionService.cs +++ b/CDPBatchEditor/Services/SessionService.cs @@ -61,6 +61,11 @@ public class SessionService : ISessionService /// private readonly IFilterService filterService; + /// + /// The (injected) + /// + private readonly ICDPMessageBus messageBus; + /// /// Holds the credentials used to connect to the server /// @@ -69,11 +74,12 @@ public class SessionService : ISessionService /// /// Empty constructor used for test purpose /// - public SessionService(ICommandArguments commandArguments, IFilterService filterService, ISession session) + public SessionService(ICommandArguments commandArguments, IFilterService filterService, ISession session, ICDPMessageBus messageBus) { this.commandArguments = commandArguments; this.filterService = filterService; this.Session = session; + this.messageBus = messageBus; } /// @@ -135,7 +141,7 @@ public void Open() var dal = new CdpServicesDal(); this.credentials = new Credentials(this.commandArguments.UserName, this.commandArguments.Password, this.commandArguments.ServerUri); - this.Session ??= new Session(dal, this.credentials); + this.Session ??= new Session(dal, this.credentials, this.messageBus); this.Session.Open().GetAwaiter().GetResult(); if (this.SetProperties())