From e6b552252a0636571e052464d23b1b98a747ba13 Mon Sep 17 00:00:00 2001 From: samatstarion Date: Sun, 8 Dec 2024 13:57:59 +0100 Subject: [PATCH] [Improve] code coverage --- DEH-CSV.Tests/CsvReaderTestFixture.cs | 19 +++++ ...ngTimeStampPropertyEvaluatorTestFixture.cs | 72 +++++++++++++++++++ .../Services/DataSourceSelectorTestFixture.cs | 6 ++ .../Services/IterationReaderTestFixture.cs | 7 ++ 4 files changed, 104 insertions(+) create mode 100644 DEH-CSV.Tests/CustomProperties/ThingTimeStampPropertyEvaluatorTestFixture.cs diff --git a/DEH-CSV.Tests/CsvReaderTestFixture.cs b/DEH-CSV.Tests/CsvReaderTestFixture.cs index e6b7d1d..c5da09d 100644 --- a/DEH-CSV.Tests/CsvReaderTestFixture.cs +++ b/DEH-CSV.Tests/CsvReaderTestFixture.cs @@ -155,5 +155,24 @@ public async Task VerifyCsvReaderImplementation() count++; } } + + [Test] + public void Verify_that_when_ReadAsync_is_called_with_null_or_empty_arguments_exception_is_thrown() + { + Stream stream = new MemoryStream(); + IReadOnlyCollection typeMaps = new List(); + + Assert.That(() => this.csvReader.ReadAsync(null, null, null), + Throws.ArgumentNullException); + + Assert.That(() => this.csvReader.ReadAsync(stream, null, null), + Throws.ArgumentNullException); + + Assert.That(() => this.csvReader.ReadAsync(stream, typeMaps, null), + Throws.ArgumentNullException); + + Assert.That(() => this.csvReader.ReadAsync(stream, typeMaps, this.session), + Throws.ArgumentException); + } } } diff --git a/DEH-CSV.Tests/CustomProperties/ThingTimeStampPropertyEvaluatorTestFixture.cs b/DEH-CSV.Tests/CustomProperties/ThingTimeStampPropertyEvaluatorTestFixture.cs new file mode 100644 index 0000000..c5fdc61 --- /dev/null +++ b/DEH-CSV.Tests/CustomProperties/ThingTimeStampPropertyEvaluatorTestFixture.cs @@ -0,0 +1,72 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright 2023-2024 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------- + +namespace STARIONGROUP.DEHCSV.Tests.CustomProperties +{ + using System; + using System.Collections.Concurrent; + using System.IO; + using System.Runtime.InteropServices; + using System.Threading.Tasks; + using CDP4Common.CommonData; + using CDP4Common.SiteDirectoryData; + using CDP4Common.Types; + using CDP4Dal; + using CDP4Dal.DAL; + using Newtonsoft.Json.Bson; + using NUnit.Framework; + + using STARIONGROUP.DEHCSV.CustomProperties; + using STARIONGROUP.DEHCSV.Mapping; + using STARIONGROUP.DEHCSV.Services; + + /// + /// Suite of tests for the class + /// + [TestFixture] + public class ThingTimeStampPropertyEvaluatorTestFixture + { + private ThingTimeStampPropertyEvaluator thingTimeStampPropertyEvaluator; + + [SetUp] + public void Setup() + { + this.thingTimeStampPropertyEvaluator = new ThingTimeStampPropertyEvaluator(); + } + + [Test] + public void Verify_that_when_Thing_is_null_exception_is_thrown() + { + Assert.That(() => this.thingTimeStampPropertyEvaluator.QueryValue(null, new PropertyMap(), null), + Throws.ArgumentNullException); ; + } + + [Test] + public void Verify_that_when_value_is_queried_expected_result_is_returned() + { + var domainOfExpertise = new DomainOfExpertise(Guid.NewGuid(), new ConcurrentDictionary>(), + new Uri("http://stariongroup.eu")); + + var result = this.thingTimeStampPropertyEvaluator.QueryValue(domainOfExpertise, new PropertyMap(), null); + + Assert.That(result, Does.StartWith("DomainOfExpertise:")); + } + } +} \ No newline at end of file diff --git a/DEH-CSV.Tests/Services/DataSourceSelectorTestFixture.cs b/DEH-CSV.Tests/Services/DataSourceSelectorTestFixture.cs index c09a99c..8626d13 100644 --- a/DEH-CSV.Tests/Services/DataSourceSelectorTestFixture.cs +++ b/DEH-CSV.Tests/Services/DataSourceSelectorTestFixture.cs @@ -48,6 +48,12 @@ public void SetUp() this.dataSourceSelector = new DataSourceSelector(this.loggerFactory); } + [Test] + public void Verify_that_when_select_is_called_with_null_uri_exception_is_thrown() + { + Assert.That(() => this.dataSourceSelector.Select(null), Throws.ArgumentNullException); + } + [Test] public void Verify_that_when_a_file_uri_is_provided_a_file_dal_is_returned() { diff --git a/DEH-CSV.Tests/Services/IterationReaderTestFixture.cs b/DEH-CSV.Tests/Services/IterationReaderTestFixture.cs index 2a8e85c..8a0dd08 100644 --- a/DEH-CSV.Tests/Services/IterationReaderTestFixture.cs +++ b/DEH-CSV.Tests/Services/IterationReaderTestFixture.cs @@ -61,6 +61,13 @@ public void Teardown() this.messageBus.Dispose(); } + [Test] + public void Verify_that_when_ReadAsync_is_called_with_null_iteration_exception_is_thrown() + { + Assert.That(() => this.iterationReader.ReadAsync(null, "DM_SPC", 1, "SYS"), + Throws.ArgumentNullException); + } + [Test] public async Task Verify_that_iteration_can_be_read_from_data_source_demo_space() {