This repository has been archived by the owner on Oct 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from stormpath/its
Add integration tests
- Loading branch information
Showing
15 changed files
with
696 additions
and
110 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Stormpath.Owin.Middleware | ||
{ | ||
internal sealed class DefaultSmartComparer : IEqualityComparer<object> | ||
{ | ||
public new bool Equals(object x, object y) | ||
{ | ||
if (x == null || y == null) | ||
{ | ||
return false; | ||
} | ||
|
||
if (x.Equals(y)) | ||
{ | ||
return true; | ||
} | ||
|
||
if (x is string && y is string) | ||
{ | ||
return CompareStringsOrdinal(x, y); | ||
} | ||
|
||
if (IsIntegerLike(x) && IsIntegerLike(y)) | ||
{ | ||
return IntegersEquals(x, y); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public int GetHashCode(object obj) | ||
=> obj.GetHashCode(); | ||
|
||
/// <summary> | ||
/// By default, always compare strings with an Ordinal comparison. | ||
/// </summary> | ||
/// <param name="x">The first string.</param> | ||
/// <param name="y">The second string.</param> | ||
/// <returns><c>true</c> if the strings are equal.</returns> | ||
private static bool CompareStringsOrdinal(object x, object y) | ||
=> ((string)x).Equals((string)y, StringComparison.Ordinal); | ||
|
||
private static bool IsIntegerLike(object value) | ||
=> value is byte || value is short || value is int || value is long; | ||
|
||
/// <summary> | ||
/// Compares two integer-like types, regardless of the size of the underlying type. | ||
/// </summary> | ||
/// <remarks> | ||
/// This is necessary because the Stormpath SDK deserializes integers as <c>long</c> under the hood. | ||
/// </remarks> | ||
/// <param name="obj1">An integer-like type.</param> | ||
/// <param name="obj2">An integer-like type.</param> | ||
/// <returns><c>true</c> if the values are identical.</returns> | ||
private static bool IntegersEquals(object obj1, object obj2) | ||
{ | ||
var long1 = (long)Convert.ChangeType(obj1, typeof(long)); | ||
var long2 = (long)Convert.ChangeType(obj2, typeof(long)); | ||
return long1 == long2; | ||
} | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
test/Stormpath.Owin.IntegrationTest/IntegrationTestCollection.cs
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,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Stormpath.Owin.IntegrationTest | ||
{ | ||
[CollectionDefinition(nameof(IntegrationTestCollection))] | ||
public class IntegrationTestCollection : ICollectionFixture<IntegrationTestFixture> | ||
{ | ||
// Intentionally left blank. This class only serves as an anchor for CollectionDefinitionAttribute. | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
test/Stormpath.Owin.IntegrationTest/IntegrationTestFixture.cs
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,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Stormpath.SDK.Application; | ||
using Stormpath.SDK.Client; | ||
using Stormpath.SDK.Directory; | ||
using Stormpath.SDK.Http; | ||
using Stormpath.SDK.Resource; | ||
using Stormpath.SDK.Serialization; | ||
|
||
namespace Stormpath.Owin.IntegrationTest | ||
{ | ||
public class IntegrationTestFixture : IDisposable | ||
{ | ||
private readonly TestEnvironment _environment; | ||
|
||
public IntegrationTestFixture() | ||
{ | ||
Client = Clients.Builder() | ||
.SetHttpClient(HttpClients.Create().SystemNetHttpClient()) | ||
.SetSerializer(Serializers.Create().JsonNetSerializer()) | ||
.Build(); | ||
|
||
TestInstanceKey = Guid.NewGuid().ToString(); | ||
|
||
_environment = new TestEnvironment(Client, async client => | ||
{ | ||
TestApplication = await client.CreateApplicationAsync($"Stormpath.Owin IT {TestInstanceKey}", true); | ||
TestDirectory = await TestApplication.GetDefaultAccountStoreAsync() as IDirectory; | ||
return new IResource[] {TestApplication, TestDirectory}; | ||
}); | ||
} | ||
|
||
public IClient Client { get; } | ||
|
||
public string TestInstanceKey { get; } | ||
|
||
public IApplication TestApplication { get; private set; } | ||
|
||
public IDirectory TestDirectory { get; private set; } | ||
|
||
public void Dispose() | ||
{ | ||
_environment.Dispose(); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
test/Stormpath.Owin.IntegrationTest/Properties/AssemblyInfo.cs
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,19 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("Stormpath.Owin.IntegrationTest")] | ||
[assembly: AssemblyTrademark("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("2e00ec4b-a29f-4037-97ab-e1c9af7eb6a7")] |
Oops, something went wrong.