Skip to content

Commit

Permalink
Merge branch 'release/2.1.0' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
craigfowler committed Aug 21, 2020
2 parents 050ce5c + c9b3665 commit cc43c4f
Show file tree
Hide file tree
Showing 42 changed files with 252 additions and 734 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ TestResult.formatted.xml
packages/*/*
*.nupkg
.vs/
*.feature.cs
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
language: csharp
solution: CSF.Security.sln

install:
- nuget restore CSF.Security.sln
- nuget install NUnit.ConsoleRunner -Version 3.6.1 -OutputDirectory testrunner
language: csharp
mono: none
dotnet: 2.2.207

script:
- xbuild /p:Configuration=Debug CSF.Security.sln
- mono "./testrunner/NUnit.ConsoleRunner.3.6.1/tools/nunit3-console.exe" $(find ./CSF.Security.Tests/ -type f -path "*/bin/Debug/*" -name "CSF.Security.Tests.dll")
- dotnet build
- dotnet test
20 changes: 0 additions & 20 deletions CSF.Security.Tests/App.config

This file was deleted.

195 changes: 0 additions & 195 deletions CSF.Security.Tests/Authentication/Authentication.feature.cs

This file was deleted.

108 changes: 69 additions & 39 deletions CSF.Security.Tests/Authentication/JsonCredentialsSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,51 +31,81 @@

namespace CSF.Security.Tests.Authentication
{
[TestFixture]
public class JsonCredentialsSerializerTests
{
#region tests

[Test,AutoMoqData]
public void Serialize_creates_expected_json(StubCredentials credentials,
JsonCredentialsSerializer sut)
[TestFixture]
public class JsonCredentialsSerializerTests
{
// Arrange
credentials.InitialisationNumber = 5;
credentials.Key = "My key";
credentials.Salt = "Salty goodness";
/// <summary>
/// Some credentials created using the old mechanism of indicating the Assebmly-Qualified type name.
/// </summary>
const string ValidOldStyleCredentials = "CSF.Security.Tests.Stubs.StubCredentials, CSF.Security.Tests:{\"Key\":\"My key\",\"Salt\":\"Salty goodness\",\"InitialisationNumber\":5}";

var expectedJson = "CSF.Security.Tests.Stubs.StubCredentials, CSF.Security.Tests:{\"Key\":\"My key\",\"Salt\":\"Salty goodness\",\"InitialisationNumber\":5}";
/// <summary>
/// Some credentials created using the new mechanism of indicating the Assebmly-Qualified type name.
/// </summary>
const string ValidNewStyleCredentials = "{\"$type\":\"CSF.Security.Tests.Stubs.StubCredentials, CSF.Security.Tests\",\"Key\":\"My key\",\"Salt\":\"Salty goodness\",\"InitialisationNumber\":5}";

// Act
var result = sut.Serialize(credentials);
#region tests

// Assert
Assert.AreEqual(expectedJson, result);
}
[Test, AutoMoqData]
public void Serialize_creates_expected_json(StubCredentials credentials,
JsonCredentialsSerializer sut)
{
// Arrange
credentials.InitialisationNumber = 5;
credentials.Key = "My key";
credentials.Salt = "Salty goodness";

[Test,AutoMoqData]
public void Deserialize_creates_expected_object(JsonCredentialsSerializer sut)
{
// Arrange
var json = "CSF.Security.Tests.Stubs.StubCredentials, CSF.Security.Tests:{\"Key\":\"My key\",\"Salt\":\"Salty goodness\",\"InitialisationNumber\":5}";
var expectedCredentials = new StubCredentials {
InitialisationNumber = 5,
Key = "My key",
Salt = "Salty goodness",
};
var expectedJson = "{\"$type\":\"CSF.Security.Tests.Stubs.StubCredentials, CSF.Security.Tests\",\"Key\":\"My key\",\"Salt\":\"Salty goodness\",\"InitialisationNumber\":5}";

// Act
var result = sut.Deserialize(json);
// Act
var result = sut.Serialize(credentials);

// Assert
Assert.IsInstanceOf<StubCredentials>(result, "Type");
var typedResult = (StubCredentials) result;
Assert.AreEqual(expectedCredentials.InitialisationNumber, typedResult.InitialisationNumber, "InitialisationNumber");
Assert.AreEqual(expectedCredentials.Key, typedResult.Key, "Key");
Assert.AreEqual(expectedCredentials.Salt, typedResult.Salt, "Salt");
}
// Assert
Assert.That(result, Is.EqualTo(expectedJson));
}

[Test, AutoMoqData, Description(@"Prior to v2.1.0, the saved credential format included a prefix which indicated a type.
From 2.1.0, Newtonsoft JSON's built-in type handling functionality is used instead.
For backwards-compatibility this class must be able to read the old-format until we are ready to move to 3.0.0.")]
public void Deserialize_can_read_credentials_which_use_a_type_prefix(JsonCredentialsSerializer sut)
{
var result = sut.Deserialize(ValidOldStyleCredentials);

Assert.That(result, Is.InstanceOf<StubCredentials>(), "Expected type");
var typedResult = (StubCredentials)result;
Assert.That(typedResult.InitialisationNumber, Is.EqualTo(5), nameof(StubCredentials.InitialisationNumber));
Assert.That(typedResult.Key, Is.EqualTo("My key"), nameof(StubCredentials.Key));
Assert.That(typedResult.Salt, Is.EqualTo("Salty goodness"), nameof(StubCredentials.Salt));
}

#endregion
}
[Test, AutoMoqData]
public void Deserialize_can_read_credentials_which_use_a_JSON_type_property(JsonCredentialsSerializer sut)
{
var result = sut.Deserialize(ValidNewStyleCredentials);

Assert.That(result, Is.InstanceOf<StubCredentials>(), "Expected type");
var typedResult = (StubCredentials)result;
Assert.That(typedResult.InitialisationNumber, Is.EqualTo(5), nameof(StubCredentials.InitialisationNumber));
Assert.That(typedResult.Key, Is.EqualTo("My key"), nameof(StubCredentials.Key));
Assert.That(typedResult.Salt, Is.EqualTo("Salty goodness"), nameof(StubCredentials.Salt));
}

[Test, AutoMoqData]
public void Serialize_writes_credentials_using_a_JSON_type_property(JsonCredentialsSerializer sut)
{
var credentials = new StubCredentials
{
InitialisationNumber = 5,
Key = "My key",
Salt = "Salty goodness",
};
var result = sut.Serialize(credentials);

Assert.That(result, Does.Match(@"\$type"), "Includes a $type element");
Assert.That(result, Does.Match(@"^\{"), "Begins with an open-brace");
}


#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
using CSF.Security.Tests.Stubs;
using Moq;
using NUnit.Framework;
using Ploeh.AutoFixture.NUnit3;
using AutoFixture.NUnit3;

namespace CSF.Security.Tests.Authentication
{
Expand Down
8 changes: 4 additions & 4 deletions CSF.Security.Tests/AutoMoqDataAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using Ploeh.AutoFixture;
using Ploeh.AutoFixture.AutoMoq;
using Ploeh.AutoFixture.NUnit3;
using AutoFixture;
using AutoFixture.AutoMoq;
using AutoFixture.NUnit3;

namespace CSF.Security.Tests
{
[AttributeUsage(AttributeTargets.Method)]
public class AutoMoqDataAttribute : AutoDataAttribute
{
public AutoMoqDataAttribute() : base(new Fixture().Customize(new AutoMoqCustomization())) {}
public AutoMoqDataAttribute() : base(() => new Fixture().Customize(new AutoMoqCustomization())) {}
}
}
Loading

0 comments on commit cc43c4f

Please sign in to comment.