Skip to content

Commit 2f9505b

Browse files
authored
Merge pull request #2 from krukle/dev
Release 0.0.3
2 parents c547db5 + 96ec295 commit 2f9505b

File tree

4 files changed

+37
-42
lines changed

4 files changed

+37
-42
lines changed
Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Newtonsoft.Json.Linq;
21
using NUnit.Framework;
32
using System.Collections.Generic;
43

@@ -16,31 +15,11 @@ public void TestSortAscendingByParsedIntThenDescendingByText()
1615

1716
var input = new Parameters
1817
{
19-
ListToSort = JArray.FromObject(
20-
new List<Dictionary<string, string>>{
21-
new Dictionary<string, string> {
22-
{ "season", "autum-2023" },
23-
{ "month", "october" }
24-
},
25-
new Dictionary<string, string> {
26-
{ "season", "spring-2022" }
27-
},
28-
new Dictionary<string, string> {
29-
{ "season", "autum-2022" },
30-
{ "month", "november" }
31-
},
32-
new Dictionary<string, string> {
33-
{ "season", "spring-2023" }
34-
}
35-
}
36-
),
37-
Key = JToken.FromObject("season")
38-
};
39-
40-
var ret = Sort.SortAscendingByParsedIntThenDescendingByText(input, new System.Threading.CancellationToken());
41-
42-
Assert.That(ret.SortedList, Is.EqualTo(JArray.FromObject(
43-
new List<Dictionary<string, string>> {
18+
ListToSort = new List<Dictionary<string, string>> {
19+
new Dictionary<string, string> {
20+
{ "season", "autum-2023" },
21+
{ "month", "october" }
22+
},
4423
new Dictionary<string, string> {
4524
{ "season", "spring-2022" }
4625
},
@@ -50,12 +29,29 @@ public void TestSortAscendingByParsedIntThenDescendingByText()
5029
},
5130
new Dictionary<string, string> {
5231
{ "season", "spring-2023" }
53-
},
54-
new Dictionary<string, string> {
55-
{ "season", "autum-2023" },
56-
{ "month", "october" }
5732
}
58-
})));
33+
},
34+
Key = "season"
35+
};
36+
37+
var ret = Sort.SortAscendingByParsedIntThenDescendingByText(input, new System.Threading.CancellationToken());
38+
39+
Assert.That(ret.SortedList, Is.EqualTo(new List<Dictionary<string, string>> {
40+
new Dictionary<string, string> {
41+
{ "season", "spring-2022" }
42+
},
43+
new Dictionary<string, string> {
44+
{ "season", "autum-2022" },
45+
{ "month", "november" }
46+
},
47+
new Dictionary<string, string> {
48+
{ "season", "spring-2023" }
49+
},
50+
new Dictionary<string, string> {
51+
{ "season", "autum-2023" },
52+
{ "month", "october" }
53+
}
54+
}));
5955
}
6056
}
6157
}

KalmarKommun.Datalager.Sort/Definition.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma warning disable 1591
22

3-
using Newtonsoft.Json.Linq;
3+
using System.Collections.Generic;
44
using System.ComponentModel;
55
using System.ComponentModel.DataAnnotations;
66

@@ -16,14 +16,14 @@ public class Parameters
1616
/// </summary>
1717
[DisplayFormat(DataFormatString = "Expression")]
1818
[DefaultValue(null)]
19-
public JArray ListToSort { get; set; }
19+
public List<Dictionary<string, string>> ListToSort { get; set; }
2020

2121
/// <summary>
2222
/// Key of which value in dictionaries to sort list by.
2323
/// </summary>
2424
[DisplayFormat(DataFormatString = "Text")]
2525
[DefaultValue("")]
26-
public JToken Key { get; set; }
26+
public string Key { get; set; }
2727
}
2828

2929
public class Result
@@ -32,6 +32,6 @@ public class Result
3232
/// Contains SortedList which is ListToSort, sorted by the provided Key.
3333
/// </summary>
3434
[DisplayFormat(DataFormatString = "Expression")]
35-
public JArray SortedList;
35+
public List<Dictionary<string, string>> SortedList;
3636
}
3737
}

KalmarKommun.Datalager.Sort/KalmarKommun.Datalager.Sort.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Newtonsoft.Json.Linq;
2-
using System;
1+
using System;
32
using System.Linq;
43
using System.Text.RegularExpressions;
54
using System.Threading;
@@ -23,10 +22,10 @@ public static Result SortAscendingByParsedIntThenDescendingByText(Parameters inp
2322
{
2423
return new Result
2524
{
26-
SortedList = JArray.FromObject(input.ListToSort
27-
.OrderBy(x => Int32.Parse(Regex.Match(x[input.Key.ToString()].ToString(), @"\d+").Value))
28-
.ThenByDescending(x => x[input.Key.ToString()])
29-
.ToList())
25+
SortedList = input.ListToSort
26+
.OrderBy(x => Int32.Parse(Regex.Match(x[input.Key], @"\d+").Value))
27+
.ThenByDescending(x => x[input.Key])
28+
.ToList()
3029
};
3130
}
3231
}

KalmarKommun.Datalager.Sort/KalmarKommun.Datalager.Sort.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<IncludeSource>true</IncludeSource>
1010
<PackageTags>Frends</PackageTags>
1111
<GenerateDocumentationFile>true</GenerateDocumentationFile>
12-
<Version>0.0.2</Version>
12+
<Version>0.0.3</Version>
1313
</PropertyGroup>
1414

1515
<ItemGroup>

0 commit comments

Comments
 (0)