-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
223 additions
and
32 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
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,6 +1,6 @@ | ||
{ | ||
"Version": "3.1.434", | ||
"BumpTime": "2023-10-28T22:39:54.0779711Z", | ||
"Version": "3.1.436", | ||
"BumpTime": "2023-11-18T00:52:54.0879268Z", | ||
"Prerelease": false, | ||
"DeprecatedVersion": "3.0.400" | ||
} |
2 changes: 1 addition & 1 deletion
2
Samples/VpnHood.Samples.SimpleClient.Droid/Resources/Resource.designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,176 @@ | ||
using System; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using VpnHood.Common.Client; | ||
using VpnHood.Common.Exceptions; | ||
|
||
namespace VpnHood.Test.Utils; | ||
|
||
public static class TestUtil | ||
{ | ||
public class AssertException : Exception | ||
{ | ||
public AssertException(string? message = null) | ||
: base(message) | ||
{ | ||
} | ||
|
||
public AssertException(string message, Exception innerException) | ||
: base(message, innerException) | ||
{ | ||
} | ||
} | ||
|
||
public static async Task<bool> WaitForValue<TValue>(object? expectedValue, Func<TValue?> valueFactory, int timeout = 5000) | ||
{ | ||
const int waitTime = 100; | ||
for (var elapsed = 0; elapsed < timeout; elapsed += waitTime) | ||
{ | ||
if (Equals(expectedValue, valueFactory())) | ||
return true; | ||
|
||
await Task.Delay(waitTime); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public static async Task<bool> WaitForValue<TValue>(object? expectedValue, Func<Task<TValue?>> valueFactory, int timeout = 5000) | ||
{ | ||
const int waitTime = 100; | ||
for (var elapsed = 0; elapsed < timeout; elapsed += waitTime) | ||
{ | ||
if (Equals(expectedValue, await valueFactory())) | ||
return true; | ||
|
||
await Task.Delay(waitTime); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private static void AssertEquals(object? expected, object? actual, string? message) | ||
{ | ||
message ??= "Unexpected Value"; | ||
if (!Equals(expected, actual)) | ||
throw new AssertException($"{message}. Expected: {expected}, Actual: {actual}"); | ||
} | ||
|
||
public static async Task AssertEqualsWait<TValue>(object? expectedValue, Func<TValue?> valueFactory, | ||
string? message = null, int timeout = 5000) | ||
{ | ||
await WaitForValue(expectedValue, valueFactory, timeout); | ||
AssertEquals(expectedValue, valueFactory(), message); | ||
} | ||
|
||
public static async Task AssertEqualsWait<TValue>(object? expectedValue, Func<Task<TValue?>> valueFactory, | ||
string? message = null, int timeout = 5000) | ||
{ | ||
await WaitForValue(expectedValue, valueFactory, timeout); | ||
AssertEquals(expectedValue, await valueFactory(), message); | ||
} | ||
|
||
public static Task AssertApiException(HttpStatusCode expectedStatusCode, Task task, string? message = null) | ||
{ | ||
return AssertApiException((int)expectedStatusCode, task, message); | ||
} | ||
|
||
private static void AssertExceptionContains(Exception ex, string? contains) | ||
{ | ||
if (contains != null && !ex.Message.Contains(contains, StringComparison.OrdinalIgnoreCase)) | ||
throw new Exception($"Actual error message does not contain \"{contains}\"."); | ||
} | ||
|
||
public static async Task AssertApiException(int expectedStatusCode, Task task, | ||
string? message = null, string? contains = null) | ||
{ | ||
try | ||
{ | ||
await task; | ||
throw new AssertException($"Expected {expectedStatusCode} but the actual was OK. {message}"); | ||
} | ||
catch (ApiException ex) | ||
{ | ||
if (ex.StatusCode != expectedStatusCode) | ||
throw new Exception($"Expected {expectedStatusCode} but the actual was {ex.StatusCode}. {message}"); | ||
|
||
AssertExceptionContains(ex, contains); | ||
} | ||
|
||
} | ||
|
||
public static Task AssertApiException<T>(Task task, string? message = null, string? contains = null) | ||
{ | ||
return AssertApiException(typeof(T).Name, task, message, contains); | ||
} | ||
|
||
public static async Task AssertApiException(string expectedExceptionType, Task task, | ||
string? message = null, string? contains = null) | ||
{ | ||
try | ||
{ | ||
await task; | ||
throw new AssertException($"Expected {expectedExceptionType} exception but was OK. {message}"); | ||
} | ||
catch (ApiException ex) | ||
{ | ||
if (ex.ExceptionTypeName != expectedExceptionType) | ||
throw new AssertException($"Expected {expectedExceptionType} but was {ex.ExceptionTypeName}. {message}"); | ||
|
||
AssertExceptionContains(ex, contains); | ||
} | ||
catch (Exception ex) when (ex is not AssertException) | ||
{ | ||
if (ex.GetType().Name != expectedExceptionType) | ||
throw new AssertException($"Expected {expectedExceptionType} but was {ex.GetType().Name}. {message}", ex); | ||
|
||
AssertExceptionContains(ex, contains); | ||
} | ||
} | ||
|
||
public static async Task AssertNotExistsException(Task task, string? message = null, string? contains = null) | ||
{ | ||
try | ||
{ | ||
await task; | ||
throw new AssertException($"Expected kind of {nameof(NotExistsException)} but was OK. {message}"); | ||
} | ||
catch (ApiException ex) | ||
{ | ||
if (ex.ExceptionTypeName != nameof(NotExistsException)) | ||
throw new AssertException($"Expected {nameof(NotExistsException)} but was {ex.ExceptionTypeName}. {message}"); | ||
|
||
AssertExceptionContains(ex, contains); | ||
} | ||
catch (Exception ex) when (ex is not AssertException) | ||
{ | ||
if (!NotExistsException.Is(ex)) | ||
throw new AssertException($"Expected kind of {nameof(NotExistsException)} but was {ex.GetType().Name}. {message}", ex); | ||
|
||
AssertExceptionContains(ex, contains); | ||
} | ||
} | ||
|
||
public static async Task AssertAlreadyExistsException(Task task, string? message = null, string? contains = null) | ||
{ | ||
try | ||
{ | ||
await task; | ||
throw new AssertException($"Expected kind of {nameof(AlreadyExistsException)} but was OK. {message}"); | ||
} | ||
catch (ApiException ex) | ||
{ | ||
if (ex.ExceptionTypeName != nameof(AlreadyExistsException)) | ||
throw new AssertException($"Expected {nameof(AlreadyExistsException)} but was {ex.ExceptionTypeName}. {message}"); | ||
|
||
AssertExceptionContains(ex, contains); | ||
} | ||
catch (Exception ex) when (ex is not AssertException) | ||
{ | ||
if (!AlreadyExistsException.Is(ex)) | ||
throw new AssertException($"Expected kind of {nameof(AlreadyExistsException)} but was {ex.GetType().Name}. {message}", ex); | ||
|
||
AssertExceptionContains(ex, contains); | ||
} | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
VpnHood.Client.App.Android.Xamarin/Properties/AndroidManifest.aab.xml
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
2 changes: 1 addition & 1 deletion
2
VpnHood.Client.App.Android.Xamarin/Properties/AndroidManifest.xml
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
2 changes: 1 addition & 1 deletion
2
VpnHood.Client.App.Android.Xamarin/Resources/Resource.designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Binary file not shown.
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
2 changes: 1 addition & 1 deletion
2
VpnHood.Client.Device.Android.Xamarin/Resources/Resource.designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.