-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #99
- Loading branch information
Showing
10 changed files
with
103 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
"Service": "LinkAce", | ||
"ApiToken": "", | ||
"LinkAceUri": "" | ||
} | ||
}, | ||
"IgnoredAccounts": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using BookmarkSync.Core.Entities; | ||
|
||
namespace BookmarkSync.Core.Extensions; | ||
|
||
public static class ListExtensions | ||
{ | ||
public static List<Bookmark>? RemoveAllFromIgnoredAccounts( | ||
this List<Bookmark>? bookmarks, | ||
List<string> ignoredAccounts) | ||
{ | ||
if (bookmarks is null) return bookmarks; | ||
bookmarks.RemoveAll(b => ignoredAccounts.Contains(b.Account.Name)); | ||
Check warning on line 12 in src/BookmarkSync.Core/Extensions/ListExtensions.cs GitHub Actions / build
|
||
return bookmarks; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
using System.Configuration; | ||
using System.Text; | ||
using BookmarkSync.Core.Configuration; | ||
using BookmarkSync.Core.Extensions; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace BookmarkSync.Core.Tests.Configuration; | ||
|
@@ -38,6 +40,18 @@ public void ConfigManager_HasProperties() | |
Assert.IsTrue(_configManager?.HasMethod("GetConfigValue")); | ||
} | ||
[TestMethod] | ||
[ExpectedException(typeof(ConfigurationErrorsException))] | ||
public void GetConfigValue_InvalidKey() | ||
{ | ||
// Arrange | ||
var expected = "Pinner"; | ||
|
||
// Act | ||
string? actual = _configManager?.GetConfigValue("Apps:Bookmarking:Service"); | ||
|
||
// Assert - Exception | ||
} | ||
[TestMethod] | ||
public void GetConfigValue_Success() | ||
{ | ||
// Arrange | ||
|
@@ -50,15 +64,34 @@ public void GetConfigValue_Success() | |
Assert.AreEqual(expected, actual); | ||
} | ||
[TestMethod] | ||
[ExpectedException(typeof(ConfigurationErrorsException))] | ||
public void GetConfigValue_InvalidKey() | ||
public void TestConfigManagerWithIgnoredAccountsConfigured() | ||
{ | ||
// Arrange | ||
var expected = "Pinner"; | ||
var jsonString = @" | ||
{ | ||
""App"": { | ||
""Bookmarking"": { | ||
""Service"": ""LinkAce"" | ||
}, | ||
""IgnoredAccounts"": [ | ||
""@[email protected]"", | ||
""[email protected]"" | ||
], | ||
}, | ||
""Instances"": [ | ||
""https://compostintraining.club"" | ||
] | ||
}"; | ||
var config = new ConfigurationBuilder() | ||
.AddJsonStream(new MemoryStream(Encoding.UTF8.GetBytes(jsonString))) | ||
.Build(); | ||
|
||
// Act | ||
string? actual = _configManager?.GetConfigValue("Apps:Bookmarking:Service"); | ||
var configManager = new ConfigManager(config); | ||
|
||
// Assert - Exception | ||
// Assert | ||
Assert.IsNotNull(configManager.App.IgnoredAccounts); | ||
foreach (string? account in configManager.App.IgnoredAccounts) | ||
{ | ||
Assert.IsFalse(account.HasLeadingAt()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,28 @@ namespace BookmarkSync.Core.Tests.Extensions; | |
[TestClass] | ||
public class StringExtensionsTests | ||
{ | ||
[DataTestMethod] | ||
[DataRow("@prplecake", true)] | ||
[DataRow("flipper", false)] | ||
public void HasLeadingAt_Success(string input, bool expected) | ||
{ | ||
// Act | ||
bool actual = input.HasLeadingAt(); | ||
|
||
// Assert | ||
Assert.AreEqual(expected, actual); | ||
} | ||
[DataTestMethod] | ||
[DataRow("@[email protected]", "[email protected]")] | ||
[DataRow("[email protected]", "[email protected]")] | ||
public void RemoveLeadingAt_Success(string input, string expected) | ||
{ | ||
// Act | ||
string actual = input.RemoveLeadingAt(); | ||
|
||
// Assert | ||
Assert.AreEqual(expected, actual); | ||
} | ||
[DataTestMethod] | ||
[DataRow("Example", "example")] | ||
[DataRow("TestCase", "test_case")] | ||
|