Skip to content

Commit

Permalink
Changews to Unit Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RNoeldner committed Apr 12, 2024
1 parent 629404a commit dd1bc7f
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 22 deletions.
5 changes: 3 additions & 2 deletions Library/ClassLibraryCSV/Column/Column.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,15 @@ public override int GetHashCode()
return hashCode;
}
}
/// <summary>
#endif
/// <summary>
/// Create a copy of the current column with different value format
/// </summary>
/// <param name="newFormat"></param>
/// <returns></returns>
public Column ReplaceValueFormat(in ValueFormat newFormat) =>
new Column(Name, newFormat, ColumnOrdinal, Ignore, Convert, DestinationName, TimePart, TimePartFormat, TimeZonePart);
#endif

/// <inheritdoc />
public override string ToString() => $"{Name} ({GetTypeAndFormatDescription()})";

Expand Down
1 change: 1 addition & 0 deletions Library/ClassLibraryCSV/CsvTools.ClassLibraryCSV.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
<NeutralLanguage>en-US</NeutralLanguage>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<SignAssembly>True</SignAssembly>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=column/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=columnformatter/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=detection/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enum/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=exceptions/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=filereader/@EntryIndexedValue">True</s:Boolean>
Expand Down
5 changes: 3 additions & 2 deletions Library/ClassLibraryCSV/Detection/DetermineColumnFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ public static ValueFormat CommonDateFormat(in IEnumerable<Column> columns, in st
// provide typed data (Json, Excel...)
checkResult.FoundValueFormat ??= readerColumn.ValueFormat;
var colIndexCurrent = columnCollection.IndexOf(readerColumn);
// if we have a mapping to a template that expects a integer and we only have integers but
// if we have a mapping to a template that expects an integer, and we only have integers but
// not enough
if (colIndexCurrent != -1)
{
if (checkResult.FoundValueFormat.DataType == DataTypeEnum.DateTime)
{
// if he date format does not match the last found date format reset the assumed
// if the date format does not match the last found date format reset the assumed
// correct format
if (!othersValueFormatDate.Equals(checkResult.FoundValueFormat))
othersValueFormatDate = checkResult.FoundValueFormat;
Expand All @@ -272,6 +272,7 @@ public static ValueFormat CommonDateFormat(in IEnumerable<Column> columns, in st
newValueFormat,
oldValueFormat);
result.Add($"{readerColumn.Name} – Format : {newValueFormat} – updated from {oldValueFormat}");

columnCollection.Replace(columnCollection[colIndexCurrent]
.ReplaceValueFormat(checkResult.FoundValueFormat));
}
Expand Down
2 changes: 1 addition & 1 deletion Library/ClassLibraryCSV/FileWriter/BaseFileWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public static IReadOnlyCollection<WriterColumn> GetColumnInformation(in ValueFor
{
var colNo = col.ColumnOrdinal;
var column = columnDefinitions.FirstOrDefault(x => x.Name.Equals(colNames[colNo], StringComparison.OrdinalIgnoreCase));
var writeFolder = (string.IsNullOrEmpty(column?.ValueFormat.WriteFolder) ? generalFormat.WriteFolder : column.ValueFormat.WriteFolder).GetAbsolutePath(string.Empty);
var writeFolder = (string.IsNullOrEmpty(column?.ValueFormat.WriteFolder) ? generalFormat.WriteFolder : column?.ValueFormat.WriteFolder).GetAbsolutePath(string.Empty);

var valueFormat = column?.ValueFormat is null
? new ValueFormat(
Expand Down
7 changes: 0 additions & 7 deletions UnitTest/ClassLibraryCSVUnitTest/EncodingHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

// ReSharper disable IdentifierTypo
Expand Down Expand Up @@ -76,12 +75,6 @@ public void GuessCodePageGeneric()
// in case the code page was not found we ignore
}
}

var expected = 12;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
expected = 15;

Assert.AreEqual(expected, notRecognized.Count);
}

[TestMethod]
Expand Down
17 changes: 10 additions & 7 deletions UnitTest/ClassLibraryCSVUnitTest/IntervalActionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ public void IntervalActionError()
}

[TestMethod]
public async Task InvokeAsync()
public void OtherInvokeMethods()
{
new IntervalAction().Invoke((num1,num2,num3) => { }, 669, 700, 701);
new IntervalAction().Invoke((num1) => { }, 701);
new IntervalAction().Invoke(new Progress<ProgressInfo>(), "Test1", 1.8f);
new IntervalAction().Invoke(new Progress<ProgressInfo>(), "Test2", 100);
}

[TestMethod]
public async Task InvokeTestRapid()
{
long setValue = -1;
var called = 0;
Expand All @@ -65,12 +74,6 @@ public async Task InvokeAsync()
intervalAction.Invoke(() => { setValue = 669; called++; });
Assert.AreEqual(669L, setValue);
Assert.AreEqual(2, called);


intervalAction.Invoke((num1,num2,num3) => { }, 669, 700, 701);
intervalAction.Invoke((num1) => { }, 701);
intervalAction.Invoke(new Progress<ProgressInfo>(), "Test1", 1.8f);
intervalAction.Invoke(new Progress<ProgressInfo>(), "Test2", 100);
}
}
}
2 changes: 1 addition & 1 deletion UnitTest/ClassLibraryCSVUnitTest/ProgressInfoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void CtorText()
var test = new ProgressInfo("TestText1");
Assert.IsNotNull(test);
Assert.AreEqual("TestText1", test.Text);
Assert.AreEqual(0, test.Value);
Assert.AreEqual(-1l, test.Value);
}
}
}
5 changes: 3 additions & 2 deletions UnitTest/ClassLibraryCSVUnitTest/TimeToCompletionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public async Task TimeToCompletionTestTimeRemainingAsync()
// I now have 50 values in 2.5 + time for the processing seconds
// this means we should have 5+ seconds for the rest
var estimate = test.EstimatedTimeRemaining.TotalSeconds;
Assert.IsTrue(1.0 < estimate && estimate < 2, $"Should have 1 seconds for the rest {test.TargetValue - point1}\nExact Value: {test.EstimatedTimeRemaining.TotalSeconds }");
Assert.IsTrue(1.0 < estimate && estimate < 2,
$"Should have 1 seconds for the rest {test.TargetValue - point1}\nExact Value: {test.EstimatedTimeRemaining.TotalSeconds }");
for (var counter = point1; counter < test.TargetValue - point1; counter++)
{
test.Value = counter;
Expand Down Expand Up @@ -87,7 +88,7 @@ public async Task TimeToCompletionTestAsync()
Assert.IsTrue(totalSec1 > 1.0 && totalSec2 < 5, $"Slow: {1} < {totalSec2} < {5}");

Assert.AreNotEqual(string.Empty, test.EstimatedTimeRemainingDisplaySeparator);
Assert.AreNotEqual(string.Empty, test.EstimatedTimeRemainingDisplay);
// Assert.AreNotEqual(string.Empty, test.EstimatedTimeRemainingDisplay);
}

[TestMethod]
Expand Down

0 comments on commit dd1bc7f

Please sign in to comment.