Skip to content

Commit

Permalink
Merge branch 'release/v1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Gélinas committed May 25, 2018
2 parents 96214cb + db989d6 commit d75df5b
Show file tree
Hide file tree
Showing 83 changed files with 2,817 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ language: csharp
mono: none
dotnet: 2.0.0
script:
- dotnet test ./src/SolidStack.Core.Guards.Tests/SolidStack.Core.Guards.Tests.csproj
- for testsProj in src/**/*Tests.csproj; do dotnet test $testsProj; done
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The `SolidStack.Core` namespace is the central point of all SolidStack packages,
Package | Description
------- | -----------
[SolidStack.Core.Guards][solidstack.core.guards-page] | `SolidStack.Core.Guards` is an extremely simple, unambiguous and lightweight [*guard clause*][guard-clauses-url] library.
SolidStack.Core.Flow (in progress...) | `SolidStack.Core.Flow` focuses on encapsulating the branching logic of your code so you can write a linear and much more readable code flow without having to deal with exceptions, null checks and unnecessary conditions.
[SolidStack.Core.Flow][solidstack.core.flow-page] | `SolidStack.Core.Flow` focuses on encapsulating the branching logic of your code so you can write a linear and much more readable code flow without having to deal with exceptions, null checks and unnecessary conditions.
SolidStack.Core.Equality (coming soon...) | `SolidStack.Core.Equality` is primarily useful when you have to tweak the equality of an object to implement the [*Value Object Pattern*][value-object-pattern-url]. All you have to do is use one of the provided abstract classes and the complex equality logic will be done for you.
SolidStack.Core.Construction (coming soon...) | `SolidStack.Core.Construction`'s only responsibility is to help you construct objects. You can use the [*Builder Pattern*][builder-pattern-url] provided implementation to build complex objects in a fluent way.

Expand All @@ -52,7 +52,7 @@ Check out our [wiki][docs-url] to explore the documentation provided for the pac

# Where can I get it?

First, [install NuGet][nuget-install-url]. Then, install the required NuGet packages avalaible on [nuget.org][nuget-idmobiles-url] using the package manager console:
First, [install NuGet][nuget-install-url]. Then, install the required NuGet packages avalaible on [nuget.org][nuget-softframe-url] using the package manager console:

```
PM> Install-Package <PackageName>
Expand Down Expand Up @@ -84,22 +84,23 @@ SolidStack is Copyright © 2018 SoftFrame under the [MIT license][license-url].
<!-- Resources: -->
[builder-pattern-url]: http://www.codinghelmet.com/?path=howto/advances-in-applying-the-builder-design-pattern
[build-status-badge]: https://img.shields.io/travis/softframe/solidstack.svg?style=flat-square
[build-url]: https://idmobiles.visualstudio.com/solidstack/_build/index?definitionId=10
[changelog-url]: https://github.com/idmobiles/solidstack/releases
[develop-branch-url]: https://github.com/idmobiles/solidstack/tree/develop
[docs-url]: https://github.com/idmobiles/solidstack/wiki
[build-url]: https://travis-ci.org/softframe/solidstack
[changelog-url]: https://github.com/softframe/solidstack/releases
[develop-branch-url]: https://github.com/softframe/solidstack/tree/develop
[docs-url]: https://github.com/softframe/solidstack/wiki
[ddd-url]: https://en.wikipedia.org/wiki/Domain-driven_design
[github-release-badge]: https://img.shields.io/github/release/idmobiles/solidstack.svg?style=flat-square
[issues-url]: https://github.com/idmobiles/solidstack/issues
[github-release-url]: https://github.com/idmobiles/solidstack/releases
[github-release-badge]: https://img.shields.io/github/release/softframe/solidstack.svg?style=flat-square
[issues-url]: https://github.com/softframe/solidstack/issues
[github-release-url]: https://github.com/softframe/solidstack/releases
[guard-clauses-url]: https://medium.com/softframe/what-are-guard-clauses-and-how-to-use-them-350c8f1b6fd2
[license-badge]: https://img.shields.io/badge/license-MIT-orange.svg?style=flat-square
[license-url]: https://github.com/idmobiles/solidstack/blob/master/LICENSE
[new-issue-url]: https://github.com/idmobiles/solidstack/issues/new
[license-url]: https://github.com/softframe/solidstack/blob/master/LICENSE
[new-issue-url]: https://github.com/softframe/solidstack/issues/new
[nuget-packages-url]: https://www.nuget.org/profiles/softframe
[nuget-install-url]: http://docs.nuget.org/docs/start-here/installing-nuget
[option-pattern-url]: http://www.codinghelmet.com/?path=howto/understanding-the-option-maybe-functional-type
[repository-pattern-url]: https://martinfowler.com/eaaCatalog/repository.html
[solidstack.core.guards-page]: https://www.nuget.org/packages/SolidStack.Core
[solidstack.core.guards-page]: https://github.com/softframe/solidstack/wiki/SolidStack.Core.Guards
[solidstack.core.flow-page]: https://github.com/softframe/solidstack/wiki/SolidStack.Core.Flow
[unit-of-work-pattern-url]: https://martinfowler.com/eaaCatalog/unitOfWork.html
[value-object-pattern-url]: https://martinfowler.com/bliki/ValueObject.html
147 changes: 147 additions & 0 deletions src/SolidStack.Core.Flow.Tests/OptionAdaptersTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using Xunit;

namespace SolidStack.Core.Flow.Tests
{
public class OptionAdaptersTests
{
[Fact]
public void AsEnumerable_WhenNone_ReturnsAnEmptySequence()
{
var option = Option.None<int>();
var sequence = option.AsEnumerable();

sequence.Should().BeEmpty();
}

[Fact]
public void AsEnumerable_WhenSome_ReturnsASequenceOfOneElement()
{
var option = Option.Some(5);
var sequence = option.AsEnumerable();

sequence.Should()
.ContainSingle(x => x == 5)
.And.HaveCount(1);
}

[Fact]
public void TryFirst_WithEmptySequence_ReturnsNone()
{
var sequence = Enumerable.Empty<int>();
var option = sequence.TryFirst();

option.AsEnumerable().Should().BeEmpty();
}

[Fact]
public void TryFirst_WithMatchingPredicate_ReturnsSome()
{
var sequence = new[] {4, 5};
var option = sequence.TryFirst(x => x < 5);

option.AsEnumerable().Should().ContainSingle(x => x == 4);
}

[Fact]
public void TryFirst_WithSequenceOfOneOrMoreElements_ReturnsSome()
{
var sequence = new[] {4, 5};
var option = sequence.TryFirst();

option.AsEnumerable().Should().ContainSingle(x => x == 4);
}

[Fact]
public void TryFirst_WithUnmatchingPredicate_ReturnsNone()
{
var sequence = Enumerable.Empty<int>();
var option = sequence.TryFirst(x => x >= 5);

option.AsEnumerable().Should().BeEmpty();
}

[Fact]
public void TryGetValue_WithExistingKey_ReturnsSome()
{
var dictionary = new Dictionary<string, int> {{"foo", 7}, {"bar", 3}};
var option = dictionary.TryGetValue("foo");

option.AsEnumerable().Should().ContainSingle(x => x == 7);
}

[Fact]
public void TryGetValue_WithUnexistingKey_ReturnsNone()
{
var dictionary = new Dictionary<string, int> {{"foo", 7}, {"bar", 3}};
var option = dictionary.TryGetValue("baz");

option.AsEnumerable().Should().BeEmpty();
}

[Fact]
public void TrySingle_WhenEmptySequence_ReturnsNone()
{
var sequence = Enumerable.Empty<int>();
var option = sequence.TrySingle();

option.AsEnumerable().Should().BeEmpty();
}

[Fact]
public void TrySingle_WithPredicateThatMatchManyElements_ReturnsNone()
{
var sequence = new[] {-2, 4, 5};
var option = sequence.TrySingle(x => x < 5);

option.AsEnumerable().Should().BeEmpty();
}

[Fact]
public void TrySingle_WithPredicateThatMatchOneElement_ReturnsSome()
{
var sequence = new[] {4, 5};
var option = sequence.TrySingle(x => x < 5);

option.AsEnumerable().Should().ContainSingle(x => x == 4);
}

[Fact]
public void TrySingle_WithSequenceOfMoreThenOneElement_ReturnsNone()
{
var sequence = new[] {4, 5};
var option = sequence.TrySingle();

option.AsEnumerable().Should().BeEmpty();
}

[Fact]
public void TrySingle_WithUnmatchingPredicate_ReturnsNone()
{
var sequence = Enumerable.Empty<int>();
var option = sequence.TrySingle(x => x >= 5);

option.AsEnumerable().Should().BeEmpty();
}

[Fact]
public void WhereSome_FiltersTheEmptyOptions()
{
var options = new[] {Option.Some(4), Option.None<int>(), Option.Some(5), Option.None<int>()};
var values = options.WhereSome();

values.Should().HaveCount(2).And.ContainInOrder(4, 5);
}

[Fact]
public void WhereSome_WithPredicate_FiltersTheEmptyOptions()
{
var sequence = new[] {4, -1, 5, -3};
var values = sequence.WhereSome(x => x >= 0 ? Option.Some(x) : Option.None<int>());

values.Should().HaveCount(2).And.ContainInOrder(4, 5);
}
}
}
Loading

0 comments on commit d75df5b

Please sign in to comment.