Skip to content

Commit c7e77e3

Browse files
committed
add tests for loading unique metadata method
1 parent a07252c commit c7e77e3

File tree

3 files changed

+92
-18
lines changed

3 files changed

+92
-18
lines changed

Flow.Launcher.Core/Plugin/PluginConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static List<PluginMetadata> Parse(string[] pluginDirectories)
5959
return uniqueList;
6060
}
6161

62-
private static (List<PluginMetadata>, List<PluginMetadata>) GetUniqueLatestPluginMetadata(List<PluginMetadata> allPluginMetadata)
62+
internal static (List<PluginMetadata>, List<PluginMetadata>) GetUniqueLatestPluginMetadata(List<PluginMetadata> allPluginMetadata)
6363
{
6464
var duplicate_list = new List<PluginMetadata>();
6565
var unique_list = new List<PluginMetadata>();

Flow.Launcher.Test/PluginLoadTest.cs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using NUnit.Framework;
2+
using Flow.Launcher.Core.Plugin;
3+
using Flow.Launcher.Plugin;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
7+
namespace Flow.Launcher.Test
8+
{
9+
[TestFixture]
10+
class PluginLoadTest
11+
{
12+
[Test]
13+
public void GivenDuplicatePluginMetadatasWhenLoadedThenShouldReturnOnlyUniqueList()
14+
{
15+
// Given
16+
var duplicateList = new List<PluginMetadata>
17+
{
18+
new PluginMetadata
19+
{
20+
ID = "CEA0TYUC6D3B4085823D60DC76F28855",
21+
Version = "1.0.0"
22+
},
23+
new PluginMetadata
24+
{
25+
ID = "CEA0TYUC6D3B4085823D60DC76F28855",
26+
Version = "1.0.1"
27+
},
28+
new PluginMetadata
29+
{
30+
ID = "CEA0TYUC6D3B4085823D60DC76F28855",
31+
Version = "1.0.2"
32+
},
33+
new PluginMetadata
34+
{
35+
ID = "CEA0TYUC6D3B4085823D60DC76F28855",
36+
Version = "1.0.0"
37+
},
38+
new PluginMetadata
39+
{
40+
ID = "CEA0TYUC6D3B4085823D60DC76F28855",
41+
Version = "1.0.0"
42+
},
43+
new PluginMetadata
44+
{
45+
ID = "CEA0TYUC6D3B7855823D60DC76F28855",
46+
Version = "1.0.0"
47+
},
48+
new PluginMetadata
49+
{
50+
ID = "CEA0TYUC6D3B7855823D60DC76F28855",
51+
Version = "1.0.0"
52+
}
53+
};
54+
55+
// When
56+
(var unique, var duplicates) = PluginConfig.GetUniqueLatestPluginMetadata(duplicateList);
57+
58+
// Then
59+
Assert.True(unique.FirstOrDefault().ID == "CEA0TYUC6D3B4085823D60DC76F28855" && unique.FirstOrDefault().Version == "1.0.2");
60+
Assert.True(unique.Count() == 1);
61+
62+
Assert.True(duplicates.Where(x => x.Version != "1.0.2" && x.ID == "CEA0TYUC6D3B4085823D60DC76F28855").Count() == 6);
63+
}
64+
65+
[Test]
66+
public void GivenDuplicatePluginMetadatasWithNoUniquePluginWhenLoadedThenShouldReturnEmptyList()
67+
{
68+
// Given
69+
var duplicateList = new List<PluginMetadata>
70+
{
71+
new PluginMetadata
72+
{
73+
ID = "CEA0TYUC6D3B7855823D60DC76F28855",
74+
Version = "1.0.0"
75+
},
76+
new PluginMetadata
77+
{
78+
ID = "CEA0TYUC6D3B7855823D60DC76F28855",
79+
Version = "1.0.0"
80+
}
81+
};
82+
83+
// When
84+
(var unique, var duplicates) = PluginConfig.GetUniqueLatestPluginMetadata(duplicateList);
85+
86+
// Then
87+
Assert.True(unique.Count() == 0);
88+
Assert.True(duplicates.Count() == 2);
89+
}
90+
}
91+
}

Flow.Launcher.Test/Plugins/PluginInitTest.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)