-
Notifications
You must be signed in to change notification settings - Fork 4
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
17 changed files
with
288 additions
and
24 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# These owners will be the default owners for everything in the repo and | ||
# will be requested for review when someone opens a pull request. | ||
* @stefan-lindegger @Speeedy01 @marco-bertschi @pascalberger @christianbumann @x-jokay @silanosa @georgesgoetz | ||
* @stefan-lindegger @Speeedy01 @marco-bertschi @pascalberger @christianbumann @eoehen @georgesgoetz |
This file was deleted.
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
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
File renamed without changes.
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,53 @@ | ||
namespace BBT.MaybePattern.Tests | ||
{ | ||
using BBT.MaybePattern; | ||
using BBT.MaybePattern.Tests.TestData; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
public sealed class MaybeIntTests | ||
{ | ||
public sealed class SerializeAndDeserialize | ||
{ | ||
/// <summary> | ||
/// Serialize and deserialize a maybe of int. | ||
/// </summary> | ||
[Fact] | ||
public void Should_Work_For_None() | ||
{ | ||
// Arrange | ||
var maybe = Maybe.None<object>(); | ||
var testData = new TestDataClass() { Maybe = maybe }; | ||
|
||
// Act & Assert | ||
using (var stream = TestUtils.SerializeToStream(testData)) | ||
{ | ||
var testDataDeserialized = (TestDataClass)TestUtils.DeserializeFromStream(stream); | ||
|
||
testDataDeserialized.Maybe.ShouldBeOfType<Maybe<object>>(); | ||
testDataDeserialized.Maybe.HasValue.ShouldBeFalse(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Serialize and deserialize a maybe of int. | ||
/// </summary> | ||
[Fact] | ||
public void Should_Work_For_Some() | ||
{ | ||
// Arrange | ||
var maybe = Maybe.Some<object>(new object()); | ||
var testData = new TestDataClass() { Maybe = maybe }; | ||
|
||
// Act & Assert | ||
using (var stream = TestUtils.SerializeToStream(testData)) | ||
{ | ||
var testDataDeserialized = (TestDataClass)TestUtils.DeserializeFromStream(stream); | ||
|
||
testDataDeserialized.Maybe.ShouldBeOfType<Maybe<object>>(); | ||
testDataDeserialized.Maybe.HasValue.ShouldBeTrue(); | ||
} | ||
} | ||
} | ||
} | ||
} |
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,53 @@ | ||
namespace BBT.MaybePattern.Tests | ||
{ | ||
using BBT.MaybePattern; | ||
using BBT.MaybePattern.Tests.TestData; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
public sealed class MaybeStructIntTests | ||
{ | ||
public sealed class SerializeAndDeserialize | ||
{ | ||
/// <summary> | ||
/// Serialize and deserialize a maybe of int. | ||
/// </summary> | ||
[Fact] | ||
public void Should_Work_For_None() | ||
{ | ||
// Arrange | ||
var maybeStruct = Maybe.NoneStruct<int>(); | ||
var testData = new TestDataStruct() { MaybeStruct = maybeStruct }; | ||
|
||
// Act & Assert | ||
using (var stream = TestUtils.SerializeToStream(testData)) | ||
{ | ||
var testDataDeserialized = (TestDataStruct)TestUtils.DeserializeFromStream(stream); | ||
|
||
testDataDeserialized.MaybeStruct.ShouldBeOfType<MaybeStruct<int>>(); | ||
testDataDeserialized.MaybeStruct.HasValue.ShouldBeFalse(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Serialize and deserialize a maybe of int. | ||
/// </summary> | ||
[Fact] | ||
public void Should_Work_For_Some() | ||
{ | ||
// Arrange | ||
var maybeStruct = Maybe.SomeStruct<int>(5); | ||
var testData = new TestDataStruct() { MaybeStruct = maybeStruct }; | ||
|
||
// Act & Assert | ||
using (var stream = TestUtils.SerializeToStream(testData)) | ||
{ | ||
var testDataDeserialized = (TestDataStruct)TestUtils.DeserializeFromStream(stream); | ||
|
||
testDataDeserialized.MaybeStruct.ShouldBeOfType<MaybeStruct<int>>(); | ||
testDataDeserialized.MaybeStruct.HasValue.ShouldBeTrue(); | ||
} | ||
} | ||
} | ||
} | ||
} |
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,16 @@ | ||
namespace BBT.MaybePattern.Tests.TestData | ||
{ | ||
using System; | ||
|
||
/// <summary> | ||
/// Used for test purposes. | ||
/// </summary> | ||
[Serializable] | ||
public class TestDataClass | ||
{ | ||
/// <summary> | ||
/// Gets or sets the maybe. | ||
/// </summary> | ||
public Maybe<object> Maybe { get; set; } | ||
} | ||
} |
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,16 @@ | ||
namespace BBT.MaybePattern.Tests.TestData | ||
{ | ||
using System; | ||
|
||
/// <summary> | ||
/// Used for test purposes. | ||
/// </summary> | ||
[Serializable] | ||
public class TestDataStruct | ||
{ | ||
/// <summary> | ||
/// Gets or sets the maybe. | ||
/// </summary> | ||
public MaybeStruct<int> MaybeStruct { get; set; } | ||
} | ||
} |
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,50 @@ | ||
namespace BBT.MaybePattern.Tests | ||
{ | ||
using System; | ||
using System.IO; | ||
using System.Runtime.Serialization.Formatters.Binary; | ||
|
||
/// <summary> | ||
/// Provides utility method for test purposes. | ||
/// </summary> | ||
public class TestUtils | ||
{ | ||
/// <summary> | ||
/// Serializes the given object into memory stream. | ||
/// </summary> | ||
/// <param name="objectType">the object to be serialized.</param> | ||
/// <returns>The serialized object as memory stream.</returns> | ||
public static MemoryStream SerializeToStream(object objectType) | ||
{ | ||
var stream = new MemoryStream(); | ||
try | ||
{ | ||
var lFormatter = new BinaryFormatter(); | ||
lFormatter.Serialize(stream, objectType); | ||
return stream; | ||
} | ||
catch | ||
{ | ||
if (stream != null) | ||
{ | ||
stream.Dispose(); | ||
} | ||
} | ||
|
||
throw new InvalidOperationException(); | ||
} | ||
|
||
/// <summary> | ||
/// Deserializes as an object. | ||
/// </summary> | ||
/// <param name="stream">the stream to deserialize.</param> | ||
/// <returns>the deserialized object.</returns> | ||
public static object DeserializeFromStream(MemoryStream stream) | ||
{ | ||
var formatter = new BinaryFormatter(); | ||
stream.Seek(0, SeekOrigin.Begin); | ||
var objectType = formatter.Deserialize(stream); | ||
return objectType; | ||
} | ||
} | ||
} |
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.