Skip to content

Commit

Permalink
[Improve] code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
samatstariongroup committed Dec 8, 2024
1 parent a166898 commit e6b5522
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
19 changes: 19 additions & 0 deletions DEH-CSV.Tests/CsvReaderTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TypeMap> typeMaps = new List<TypeMap>();

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);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="ThingTimeStampPropertyEvaluatorTestFixture.cs" company="Starion Group S.A.">
//
// 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.
//
// </copyright>
// -------------------------------------------------------------------------------------------------

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;

/// <summary>
/// Suite of tests for the <see cref="ThingTimeStampPropertyEvaluator"/> class
/// </summary>
[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<CacheKey, Lazy<Thing>>(),
new Uri("http://stariongroup.eu"));

var result = this.thingTimeStampPropertyEvaluator.QueryValue(domainOfExpertise, new PropertyMap(), null);

Assert.That(result, Does.StartWith("DomainOfExpertise:"));
}
}
}
6 changes: 6 additions & 0 deletions DEH-CSV.Tests/Services/DataSourceSelectorTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
7 changes: 7 additions & 0 deletions DEH-CSV.Tests/Services/IterationReaderTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit e6b5522

Please sign in to comment.