Skip to content

Commit

Permalink
[Rename] CsvReader.Read to CsvReader.ReadAsync
Browse files Browse the repository at this point in the history
[Rename] IterationReader.Read to IterationReader.ReadAsync
  • Loading branch information
samatstariongroup committed Dec 8, 2024
1 parent dcbac6b commit e6ed504
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion DEH-CSV.Tests/CsvReaderTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public async Task VerifyCsvReaderImplementation()

var domain = loftModel.Participant.Single(x => x.Person == this.session.ActivePerson).SelectedDomain;
await this.session.Read(iteration, domain);
var mappedThings = (await this.csvReader.Read(csvStream, typeMaps.ToList(), this.session)).ToList();
var mappedThings = (await this.csvReader.ReadAsync(csvStream, typeMaps.ToList(), this.session)).ToList();

Assert.Multiple(() =>
{
Expand Down
4 changes: 2 additions & 2 deletions DEH-CSV.Tests/CsvWriterTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public async Task Verify_that_demosat_model_can_be_written_to_CSV_file()

await session.Open(false);

var iteration = await this.iterationReader.Read(session, "DM_SPC", 1, "SYS");
var iteration = await this.iterationReader.ReadAsync(session, "DM_SPC", 1, "SYS");

var outputPath = Path.Combine(TestContext.CurrentContext.WorkDirectory, "CSV");
var target = new DirectoryInfo(outputPath);
Expand All @@ -117,7 +117,7 @@ public async Task Verify_that_when_ValuePrefix_is_set_CSV_File_is_Written_with_p

await session.Open(false);

var iteration = await this.iterationReader.Read(session, "DM_SPC", 1, "SYS");
var iteration = await this.iterationReader.ReadAsync(session, "DM_SPC", 1, "SYS");

var typeMaps = new List<TypeMap>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public async Task Verify_that_demosat_model_can_be_written_to_CSV_file()

await session.Open(false);

var iteration = await this.iterationReader.Read(session, "DM_SPC", 1, "SYS");
var iteration = await this.iterationReader.ReadAsync(session, "DM_SPC", 1, "SYS");

var outputPath = Path.Combine(TestContext.CurrentContext.WorkDirectory, "CSV-Thing-TimeStamped");
var target = new DirectoryInfo(outputPath);
Expand Down
8 changes: 4 additions & 4 deletions DEH-CSV.Tests/Services/IterationReaderTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public async Task Verify_that_iteration_can_be_read_from_data_source_demo_space(

await session.Open(false);

var iteration = await this.iterationReader.Read(session, "DM_SPC", 1, "SYS");
var iteration = await this.iterationReader.ReadAsync(session, "DM_SPC", 1, "SYS");

Assert.That(iteration, Is.Not.Null);
}
Expand All @@ -96,13 +96,13 @@ public async Task Verify_that_iteration_read_throws_expected_exceptions()

await session.Open(false);

Assert.That(async () => await this.iterationReader.Read(session, "XXX", 1, "SYS"),
Assert.That(async () => await this.iterationReader.ReadAsync(session, "XXX", 1, "SYS"),
Throws.Exception.With.Message.EqualTo("The EngineeringModelSetup with shortName XXX could not be found"));

Assert.That(async () => await this.iterationReader.Read(session, "DM_SPC", 12, "SYS"),
Assert.That(async () => await this.iterationReader.ReadAsync(session, "DM_SPC", 12, "SYS"),
Throws.Exception.With.Message.EqualTo("The IterationSetup with number 12 could not be found"));

Assert.That(async () => await this.iterationReader.Read(session, "DM_SPC", 1, "SYE"),
Assert.That(async () => await this.iterationReader.ReadAsync(session, "DM_SPC", 1, "SYE"),
Throws.Exception.With.Message.EqualTo("The DomainOfExpertise with shortName SYE could not be found"));
}
}
Expand Down
12 changes: 7 additions & 5 deletions DEH-CSV/CsvReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public CsvReader(ILogger<CsvReader> logger)
/// <param name="typeMaps">The collection of <see cref="TypeMap" />s</param>
/// <param name="session">The <see cref="ISession" /> that helps to retrieve <see cref="Thing" /></param>
/// <returns>A <see cref="Task{T}" /> that returns a collection of mapped <see cref="Thing" />s</returns>
public async Task<IEnumerable<Thing>> Read(Stream stream, IReadOnlyCollection<TypeMap> typeMaps, ISession session)
public async Task<IEnumerable<Thing>> ReadAsync(Stream stream, IReadOnlyCollection<TypeMap> typeMaps, ISession session)
{
ValidateReadParameters(stream, typeMaps, session);

Expand All @@ -90,7 +90,7 @@ public async Task<IEnumerable<Thing>> Read(Stream stream, IReadOnlyCollection<Ty
DetectDelimiter = true
});

await this.ReadHeader(reader, typeMaps);
await this.ReadHeaderAsync(reader, typeMaps);

while (await reader.ReadAsync())
{
Expand Down Expand Up @@ -226,6 +226,8 @@ private void ProcessPath(PropertyPath path, IReadOnlyList<Thing> previousThings,
}

break;
default:
throw new InvalidDataException("The referenced value is not a Thing or IEnumerable<Thing>");
}
}

Expand Down Expand Up @@ -434,7 +436,7 @@ private void ValidateEntryPoint(TypeMap typeMap, PropertyMap entryPoint)
/// <param name="reader">The <see cref="IReader" /> used to read CSV content</param>
/// <param name="typeMaps">The collection of <see cref="TypeMap" />s</param>
/// <returns>A <see cref="Task" /></returns>
private async Task ReadHeader(IReader reader, IEnumerable<TypeMap> typeMaps)
private async Task ReadHeaderAsync(IReader reader, IEnumerable<TypeMap> typeMaps)
{
await reader.ReadAsync();

Expand All @@ -446,15 +448,15 @@ private async Task ReadHeader(IReader reader, IEnumerable<TypeMap> typeMaps)

var headers = reader.HeaderRecord;

if (typeMaps.SelectMany(x => x.Properties).FirstOrDefault(p => Array.TrueForAll(headers, x => !x.Equals(p.Source))) is { } invalidPropertyMap)
if (typeMaps.SelectMany(x => x.Properties).FirstOrDefault(p => Array.TrueForAll(headers, x => !x.Equals(p.Source, StringComparison.Ordinal))) is { } invalidPropertyMap)
{
this.logger.LogError("The provided CSV does not contains any header for the source {0}", invalidPropertyMap.Source);
throw new InvalidDataException($"The provided CSV does not contains any header for the source {invalidPropertyMap.Source}");
}
}

/// <summary>
/// Validates all parameters provided for the <see cref="Read" /> method
/// Validates all parameters provided for the <see cref="ReadAsync" /> method
/// </summary>
/// <param name="stream">The provided <see cref="Stream" /></param>
/// <param name="typeMaps">The provided collection of <see cref="TypeMap" />s</param>
Expand Down
2 changes: 1 addition & 1 deletion DEH-CSV/ICsvReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public interface ICsvReader
/// <param name="typeMaps">The collection of <see cref="TypeMap" />s</param>
/// <param name="session">The <see cref="ISession" /> that helps to retrieve <see cref="Thing" /></param>
/// <returns>A <see cref="Task{T}" /> that returns a collection of mapped <see cref="Thing" />s</returns>
Task<IEnumerable<Thing>> Read(Stream stream, IReadOnlyCollection<TypeMap> typeMaps, ISession session);
Task<IEnumerable<Thing>> ReadAsync(Stream stream, IReadOnlyCollection<TypeMap> typeMaps, ISession session);
}
}
4 changes: 2 additions & 2 deletions DEH-CSV/Services/IIterationReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace STARIONGROUP.DEHCSV.Services
public interface IIterationReader
{
/// <summary>
/// Read the iteration from the
/// ReadAsync the iteration from the
/// </summary>
/// <param name="session">
/// The <see cref="ISession"/> object used to read the <see cref="Iteration"/> data
Expand All @@ -51,6 +51,6 @@ public interface IIterationReader
/// <returns>
/// An instance of <see cref="Iteration"/>
/// </returns>
Task<Iteration> Read(ISession session, string modelShortName, int iterationNumber, string domainOfExpertiseShortName);
Task<Iteration> ReadAsync(ISession session, string modelShortName, int iterationNumber, string domainOfExpertiseShortName);
}
}
4 changes: 2 additions & 2 deletions DEH-CSV/Services/IterationReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public IterationReader(ILoggerFactory loggerFactory = null)
}

/// <summary>
/// Read the iteration from the
/// ReadAsync the iteration from the
/// </summary>
/// <param name="session">
/// The <see cref="ISession"/> object used to read the <see cref="Iteration"/> data
Expand All @@ -73,7 +73,7 @@ public IterationReader(ILoggerFactory loggerFactory = null)
/// <returns>
/// An instance of <see cref="Iteration"/>
/// </returns>
public async Task<Iteration> Read(ISession session, string modelShortName, int iterationNumber, string domainOfExpertiseShortName)
public async Task<Iteration> ReadAsync(ISession session, string modelShortName, int iterationNumber, string domainOfExpertiseShortName)
{
this.logger.LogDebug("Setting up the read request for {modelShortName}:{iterationNumber}", modelShortName, iterationNumber);

Expand Down

0 comments on commit e6ed504

Please sign in to comment.