Skip to content

Dev to test (1.1.3) #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest, windows-latest ]
dotnet-version: [ '7.x', '8.x' ]
dotnet-version: [ '9.x', '8.x' ]
configuration: [ 'Debug' ]
runs-on: ${{ matrix.os }}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Px.Utils.UnitTests.ModelBuilderTests.Fixtures
{
internal static class PxFileMetaEntries_Robust_1_Language_With_Range_Time_Dimension
{
public static List<KeyValuePair<string, string>> Entries =
[
new("CHARSET", "\"ANSI\""),
new("AXIS-VERSION", "\"2013\""),
new("CODEPAGE", "\"iso-8859-15\""),
new("LANGUAGE", "\"fi\""),
new("CREATION-DATE", "\"20200121 09:00\""),
new("NEXT-UPDATE", "\"20240131 08:00\""),
new("TABLEID", "\"example_table_id_for_testing\""),
new("DECIMALS", "0"),
new("SHOWDECIMALS", "1"),
new("MATRIX", "\"001_12ab_2022\""),
new("SUBJECT-CODE", "\"ABCD\""),
new("SUBJECT-AREA", "\"abcd\""),
new("COPYRIGHT", "YES"),
new("DESCRIPTION", "\"test_description_fi\""),
new("TITLE", "\"test_title_fi\""),
new("CONTENTS", "\"test_contents_fi\""),
new("UNITS", "\"test_unit_fi\""),
new("STUB", "\"Vuosi\",\"Alue\",\"Talotyyppi\""),
new("HEADING", "\"Tiedot\""),
new("CONTVARIABLE", "\"Tiedot\""),
new("VALUES(\"Vuosi\")", "\"2015\",\"2016\",\"2017\",\"2018\",\"2019\",\"2020\",\"2021\",\"2022\""),
new("VALUES(\"Alue\")", "\"Koko maa\",\"Pääkaupunkiseutu (PKS)\",\"Muu Suomi (koko maa pl. PKS)\",\"Helsinki\", \"Espoo-Kauniainen\",\"Vantaa\",\"Turku\""),
new("VALUES(\"Talotyyppi\")", "\"Talotyypit yhteensä\",\"Rivitalot\",\"Kerrostalot\""),
new("VALUES(\"Tiedot\")", "\"Indeksi (2015=100)\",\"Muutos edelliseen vuoteen (indeksi 2015=100)\",\"Kauppojen lukumäärä\""),
new("TIMEVAL(\"Vuosi\")", "TLIST(A1, \"2015-2022\")"),
new("CODES(\"Vuosi\")", "\"2015\",\"2016\",\"2017\",\"2018\",\"2019\",\"2020\",\"2021\",\"2022\""),
new("CODES(\"Alue\")", "\"ksu\",\"pks\",\"msu\",\"091\",\"049\",\"092\",\"853\""),
new("CODES(\"Talotyyppi\")", "\"0\",\"1\",\"3\""),
new("CODES(\"Tiedot\")", "\"ketjutettu_lv\",\"vmuutos_lv\",\"lkm_julk_uudet\""),
new("VARIABLE-TYPE(\"Vuosi\")", "\"Time\""),
new("VARIABLE-TYPE(\"Alue\")", "\"Classificatory\""),
new("VARIABLE-TYPE(\"Talotyyppi\")", "\"Classificatory\""),
new("MAP(\"Alue\")", "\"Alue 2018\""),
new("ELIMINATION(\"Talotyyppi\")", "\"Talotyypit yhteensä\""),
new("PRECISION(\"Tiedot\",\"Muutos edelliseen vuoteen (indeksi 2015=100)\")", "1"),
new("LAST-UPDATED(\"Indeksi (2015=100)\")", "\"20230131 08:00\""),
new("LAST-UPDATED(\"Muutos edelliseen vuoteen (indeksi 2015=100)\")", "\"20230131 09:00\""),
new("LAST-UPDATED(\"Kauppojen lukumäärä\")", "\"20230131 10:00\""),
new("UNITS(\"Indeksi (2015=100)\")", "\"indeksipisteluku\""),
new("UNITS(\"Muutos edelliseen vuoteen (indeksi 2015=100)\")", "\"%\""),
new("UNITS", "\"lukumäärä\""), // table level units
new("CONTACT(\"Indeksi (2015=100)\")", "\"test_contact1_fi\""),
new("CONTACT(\"Muutos edelliseen vuoteen (indeksi 2015=100)\")", "\"test_contact2_fi\""),
new("CONTACT(\"Kauppojen lukumäärä\")", "\"test_contact3_fi\""),
new("SOURCE", "\"test_source_fi\""),
new("OFFICIAL-STATISTICS", "YES"),
new("NOTE", "\"test_note_fi\""),
new("NOTE(\"Talotyyppi\")", "\"test_note_talotyyppi\""),
new("VALUENOTE(\"Tiedot\",\"Indeksi (2015=100)\")", "\"test_value_note_tiedot_indeksi\""),
new("VALUENOTE(\"Tiedot\",\"Muutos edelliseen vuoteen (indeksi 2015=100)\")", "\"test_value_note_tiedot_muutos\""),
new("VALUENOTE(\"Tiedot\",\"Kauppojen lukumäärä\")", "\"test_value_note_tiedot_kauppojen_lukumäärä\"")
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class MatrixMetadataBuilderTests
private MatrixMetadata Actual_1Lang_With_Table_Level_Units_And_Precision { get; } =
new MatrixMetadataBuilder().Build(PxFileMetaEntries_Robust_1_Language_With_Table_Level_Units_And_Precision.Entries);

private MatrixMetadata Actual_1Lang_With_Range_Time_Dimension { get; } =
new MatrixMetadataBuilder().Build(PxFileMetaEntries_Robust_1_Language_With_Range_Time_Dimension.Entries);

[TestMethod]
public void IEnumerableBuildTest()
{
Expand Down Expand Up @@ -228,7 +231,7 @@ public void SingleLangWithTableLevelUnitsAndPrecisionBuildTest()
}
Assert.IsFalse(Actual_1Lang_With_Table_Level_Units_And_Precision.AdditionalProperties.ContainsKey(PxFileConfiguration.Default.Tokens.KeyWords.Units));
Assert.IsFalse(Actual_1Lang_With_Table_Level_Units_And_Precision.AdditionalProperties.ContainsKey(PxFileConfiguration.Default.Tokens.KeyWords.Decimals));
Assert.IsFalse(Actual_1Lang_With_Table_Level_Units_And_Precision.AdditionalProperties.ContainsKey(PxFileConfiguration.Default.Tokens.KeyWords.ShowDecimals));
Assert.IsTrue(Actual_1Lang_With_Table_Level_Units_And_Precision.AdditionalProperties.ContainsKey(PxFileConfiguration.Default.Tokens.KeyWords.ShowDecimals));
}

#region Content Dimension Tests
Expand Down Expand Up @@ -371,6 +374,32 @@ public void MultiLangPrecisionTestFromRecommendedFixture(int index, int expected
Assert.IsFalse(contentDimension?.Values[index].AdditionalProperties.ContainsKey("PRECISION"));
}

[TestMethod]
public void MultiLangContentDimensionAdditionalPropertiesTest()
{
ContentDimension? contentDimension = (ContentDimension?)Actual_3Lang.Dimensions.Find(d => d.Type == DimensionType.Content);
Assert.IsNotNull(contentDimension);
Assert.AreEqual(3, contentDimension.Values.Count);
foreach (ContentDimensionValue value in contentDimension.Values)
{
Assert.IsTrue(value.AdditionalProperties.ContainsKey("VALUENOTE"));
Assert.IsInstanceOfType<MultilanguageStringProperty>(value.AdditionalProperties["VALUENOTE"]);
}
}

[TestMethod]
public void SingleLangContentDimensionAdditionalPropertiesTest()
{
ContentDimension? contentDimension = (ContentDimension?)Actual_1Lang.Dimensions.Find(d => d.Type == DimensionType.Content);
Assert.IsNotNull(contentDimension);
Assert.AreEqual(3, contentDimension.Values.Count);
foreach (ContentDimensionValue value in contentDimension.Values)
{
Assert.IsTrue(value.AdditionalProperties.ContainsKey("VALUENOTE"));
Assert.IsInstanceOfType<StringProperty>(value.AdditionalProperties["VALUENOTE"]);
}
}

#endregion

#region Time Dimension Tests
Expand Down Expand Up @@ -525,5 +554,56 @@ public void MultilanguageTableWithCustomMetaPropertiesAndPropetyTypes()
Assert.AreEqual(MetaPropertyType.TextArray, actual.AdditionalProperties["SINGLEITEMTEXTARRAYPROPERTY"].Type);
Assert.AreEqual(MetaPropertyType.MultilanguageTextArray, actual.AdditionalProperties["SINGLEITEMMULTILANGUAGETEXTARRAYPROPERTY"].Type);
}

[TestMethod]
public void MultilanguageTableRemovesDimensionTypeAndTimeValEntriesTest()
{
Assert.IsTrue(Actual_3Lang.Dimensions.Exists(dim => dim.Type == DimensionType.Time));
foreach (Dimension dim in Actual_3Lang.Dimensions)
{
Assert.IsFalse(dim.AdditionalProperties.ContainsKey(PxFileConfiguration.Default.Tokens.KeyWords.DimensionType));

if (dim.Type == DimensionType.Time)
{
Assert.IsTrue(dim.AdditionalProperties.TryGetValue(PxFileConfiguration.Default.Tokens.KeyWords.TimeVal, out MetaProperty? value));
Assert.AreEqual(MetaPropertyType.TextArray, value.Type);
StringListProperty property = (StringListProperty)value;
Assert.AreEqual(8, property.Value.Count);
}
}
}

[TestMethod]
public void MultilanguageWithRangeTimeDimensionTest()
{
Assert.IsTrue(Actual_1Lang_With_Range_Time_Dimension.Dimensions.Exists(dim => dim.Type == DimensionType.Time));
foreach (Dimension dim in Actual_1Lang_With_Range_Time_Dimension.Dimensions)
{
Assert.IsFalse(dim.AdditionalProperties.ContainsKey(PxFileConfiguration.Default.Tokens.KeyWords.DimensionType));

if (dim.Type == DimensionType.Time)
{
Assert.IsTrue(dim.AdditionalProperties.TryGetValue(PxFileConfiguration.Default.Tokens.KeyWords.TimeVal, out MetaProperty? value));
Assert.AreEqual(MetaPropertyType.Text, value.Type);
StringProperty property = (StringProperty)value;
Assert.AreEqual("2015-2022", property.Value);
}
}
}

[TestMethod]
public void MultilanguageRemovesTableLevelMetaEntriesTest()
{
string[] keywords = [
PxFileConfiguration.Default.Tokens.KeyWords.Units,
PxFileConfiguration.Default.Tokens.KeyWords.Precision,
PxFileConfiguration.Default.Tokens.KeyWords.Decimals
];

foreach (string keyword in keywords)
{
Assert.IsFalse(Actual_3Lang.AdditionalProperties.ContainsKey(keyword));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using Px.Utils.ModelBuilders;

namespace Px.Utils.UnitTests.ModelBuilderTests.ValueParserUtilitiesTests
{
[TestClass]
public class GetTimeValValueRangeStringTests
{
[TestMethod]
public void GetTimeValValueRangeStringTestEmptyInputThrowsException()
{
string input = "TLIST(A1)";
Assert.ThrowsException<ArgumentException>(() => ValueParserUtilities.GetTimeValValueRangeString(input));
}

[TestMethod]
public void GetTimeValValueRangeStringTestListInputThrowsException()
{
string input = "TLIST(A1), \"9000\", \"9001\", \"9002\", \"9003\", \"9004\"";
Assert.ThrowsException<ArgumentException>(() => ValueParserUtilities.GetTimeValValueRangeString(input));
}

[TestMethod]
public void GetTimeValValueRangeStringTestInvalidRangeFormatThrowsException()
{
string input = "TLIST(A1, \"9001\")";
Assert.ThrowsException<ArgumentException>(() => ValueParserUtilities.GetTimeValValueRangeString(input));
}

[TestMethod]
public void GetTimeValueStringTestValidInputReturnsString()
{
string input = "TLIST(A1, \"9000-9001\")";
string expected = "9000-9001";
string actual = ValueParserUtilities.GetTimeValValueRangeString(input);

Assert.AreEqual(expected, actual);
}

[TestMethod]
public void GetTimeValueStringTestInputWithTwoRangesThrowsException()
{
string input = "TLIST(A1, \"9000-9001\", \"9002-9003\")";
Assert.ThrowsException<ArgumentException>(() => ValueParserUtilities.GetTimeValValueRangeString(input));
}

[TestMethod]
public void GetTimeValueStringTestInputWithRangeOfThreePartRangeThrowsException()
{
string input = "TLIST(A1, \"9000-9001-9002\")";
Assert.ThrowsException<ArgumentException>(() => ValueParserUtilities.GetTimeValValueRangeString(input));
}

[TestMethod]
public void GetTimeValueStringTestInputRangeWithoutStringDelimetersThrowsException()
{
string input = "TLIST(A1, 9000-9001)";
Assert.ThrowsException<ArgumentException>(() => ValueParserUtilities.GetTimeValValueRangeString(input));
}

[TestMethod]
public void GetTimeValueStringTestInputRangeWithExtraWhitespaceReturnsString()
{
string input = "TLIST(A1, \"9000-9001\" )";
string expected = "9000-9001";
string actual = ValueParserUtilities.GetTimeValValueRangeString(input);

Assert.AreEqual(expected, actual);
}
}
}
Loading
Loading