Skip to content

Commit d75df5b

Browse files
author
Maxime Gélinas
committed
Merge branch 'release/v1.1.0'
2 parents 96214cb + db989d6 commit d75df5b

83 files changed

Lines changed: 2817 additions & 48 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ language: csharp
22
mono: none
33
dotnet: 2.0.0
44
script:
5-
- dotnet test ./src/SolidStack.Core.Guards.Tests/SolidStack.Core.Guards.Tests.csproj
5+
- for testsProj in src/**/*Tests.csproj; do dotnet test $testsProj; done

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The `SolidStack.Core` namespace is the central point of all SolidStack packages,
2626
Package | Description
2727
------- | -----------
2828
[SolidStack.Core.Guards][solidstack.core.guards-page] | `SolidStack.Core.Guards` is an extremely simple, unambiguous and lightweight [*guard clause*][guard-clauses-url] library.
29-
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.
29+
[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.
3030
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.
3131
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.
3232

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

5353
# Where can I get it?
5454

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

5757
```
5858
PM> Install-Package <PackageName>
@@ -84,22 +84,23 @@ SolidStack is Copyright © 2018 SoftFrame under the [MIT license][license-url].
8484
<!-- Resources: -->
8585
[builder-pattern-url]: http://www.codinghelmet.com/?path=howto/advances-in-applying-the-builder-design-pattern
8686
[build-status-badge]: https://img.shields.io/travis/softframe/solidstack.svg?style=flat-square
87-
[build-url]: https://idmobiles.visualstudio.com/solidstack/_build/index?definitionId=10
88-
[changelog-url]: https://github.com/idmobiles/solidstack/releases
89-
[develop-branch-url]: https://github.com/idmobiles/solidstack/tree/develop
90-
[docs-url]: https://github.com/idmobiles/solidstack/wiki
87+
[build-url]: https://travis-ci.org/softframe/solidstack
88+
[changelog-url]: https://github.com/softframe/solidstack/releases
89+
[develop-branch-url]: https://github.com/softframe/solidstack/tree/develop
90+
[docs-url]: https://github.com/softframe/solidstack/wiki
9191
[ddd-url]: https://en.wikipedia.org/wiki/Domain-driven_design
92-
[github-release-badge]: https://img.shields.io/github/release/idmobiles/solidstack.svg?style=flat-square
93-
[issues-url]: https://github.com/idmobiles/solidstack/issues
94-
[github-release-url]: https://github.com/idmobiles/solidstack/releases
92+
[github-release-badge]: https://img.shields.io/github/release/softframe/solidstack.svg?style=flat-square
93+
[issues-url]: https://github.com/softframe/solidstack/issues
94+
[github-release-url]: https://github.com/softframe/solidstack/releases
9595
[guard-clauses-url]: https://medium.com/softframe/what-are-guard-clauses-and-how-to-use-them-350c8f1b6fd2
9696
[license-badge]: https://img.shields.io/badge/license-MIT-orange.svg?style=flat-square
97-
[license-url]: https://github.com/idmobiles/solidstack/blob/master/LICENSE
98-
[new-issue-url]: https://github.com/idmobiles/solidstack/issues/new
97+
[license-url]: https://github.com/softframe/solidstack/blob/master/LICENSE
98+
[new-issue-url]: https://github.com/softframe/solidstack/issues/new
9999
[nuget-packages-url]: https://www.nuget.org/profiles/softframe
100100
[nuget-install-url]: http://docs.nuget.org/docs/start-here/installing-nuget
101101
[option-pattern-url]: http://www.codinghelmet.com/?path=howto/understanding-the-option-maybe-functional-type
102102
[repository-pattern-url]: https://martinfowler.com/eaaCatalog/repository.html
103-
[solidstack.core.guards-page]: https://www.nuget.org/packages/SolidStack.Core
103+
[solidstack.core.guards-page]: https://github.com/softframe/solidstack/wiki/SolidStack.Core.Guards
104+
[solidstack.core.flow-page]: https://github.com/softframe/solidstack/wiki/SolidStack.Core.Flow
104105
[unit-of-work-pattern-url]: https://martinfowler.com/eaaCatalog/unitOfWork.html
105106
[value-object-pattern-url]: https://martinfowler.com/bliki/ValueObject.html
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using FluentAssertions;
4+
using Xunit;
5+
6+
namespace SolidStack.Core.Flow.Tests
7+
{
8+
public class OptionAdaptersTests
9+
{
10+
[Fact]
11+
public void AsEnumerable_WhenNone_ReturnsAnEmptySequence()
12+
{
13+
var option = Option.None<int>();
14+
var sequence = option.AsEnumerable();
15+
16+
sequence.Should().BeEmpty();
17+
}
18+
19+
[Fact]
20+
public void AsEnumerable_WhenSome_ReturnsASequenceOfOneElement()
21+
{
22+
var option = Option.Some(5);
23+
var sequence = option.AsEnumerable();
24+
25+
sequence.Should()
26+
.ContainSingle(x => x == 5)
27+
.And.HaveCount(1);
28+
}
29+
30+
[Fact]
31+
public void TryFirst_WithEmptySequence_ReturnsNone()
32+
{
33+
var sequence = Enumerable.Empty<int>();
34+
var option = sequence.TryFirst();
35+
36+
option.AsEnumerable().Should().BeEmpty();
37+
}
38+
39+
[Fact]
40+
public void TryFirst_WithMatchingPredicate_ReturnsSome()
41+
{
42+
var sequence = new[] {4, 5};
43+
var option = sequence.TryFirst(x => x < 5);
44+
45+
option.AsEnumerable().Should().ContainSingle(x => x == 4);
46+
}
47+
48+
[Fact]
49+
public void TryFirst_WithSequenceOfOneOrMoreElements_ReturnsSome()
50+
{
51+
var sequence = new[] {4, 5};
52+
var option = sequence.TryFirst();
53+
54+
option.AsEnumerable().Should().ContainSingle(x => x == 4);
55+
}
56+
57+
[Fact]
58+
public void TryFirst_WithUnmatchingPredicate_ReturnsNone()
59+
{
60+
var sequence = Enumerable.Empty<int>();
61+
var option = sequence.TryFirst(x => x >= 5);
62+
63+
option.AsEnumerable().Should().BeEmpty();
64+
}
65+
66+
[Fact]
67+
public void TryGetValue_WithExistingKey_ReturnsSome()
68+
{
69+
var dictionary = new Dictionary<string, int> {{"foo", 7}, {"bar", 3}};
70+
var option = dictionary.TryGetValue("foo");
71+
72+
option.AsEnumerable().Should().ContainSingle(x => x == 7);
73+
}
74+
75+
[Fact]
76+
public void TryGetValue_WithUnexistingKey_ReturnsNone()
77+
{
78+
var dictionary = new Dictionary<string, int> {{"foo", 7}, {"bar", 3}};
79+
var option = dictionary.TryGetValue("baz");
80+
81+
option.AsEnumerable().Should().BeEmpty();
82+
}
83+
84+
[Fact]
85+
public void TrySingle_WhenEmptySequence_ReturnsNone()
86+
{
87+
var sequence = Enumerable.Empty<int>();
88+
var option = sequence.TrySingle();
89+
90+
option.AsEnumerable().Should().BeEmpty();
91+
}
92+
93+
[Fact]
94+
public void TrySingle_WithPredicateThatMatchManyElements_ReturnsNone()
95+
{
96+
var sequence = new[] {-2, 4, 5};
97+
var option = sequence.TrySingle(x => x < 5);
98+
99+
option.AsEnumerable().Should().BeEmpty();
100+
}
101+
102+
[Fact]
103+
public void TrySingle_WithPredicateThatMatchOneElement_ReturnsSome()
104+
{
105+
var sequence = new[] {4, 5};
106+
var option = sequence.TrySingle(x => x < 5);
107+
108+
option.AsEnumerable().Should().ContainSingle(x => x == 4);
109+
}
110+
111+
[Fact]
112+
public void TrySingle_WithSequenceOfMoreThenOneElement_ReturnsNone()
113+
{
114+
var sequence = new[] {4, 5};
115+
var option = sequence.TrySingle();
116+
117+
option.AsEnumerable().Should().BeEmpty();
118+
}
119+
120+
[Fact]
121+
public void TrySingle_WithUnmatchingPredicate_ReturnsNone()
122+
{
123+
var sequence = Enumerable.Empty<int>();
124+
var option = sequence.TrySingle(x => x >= 5);
125+
126+
option.AsEnumerable().Should().BeEmpty();
127+
}
128+
129+
[Fact]
130+
public void WhereSome_FiltersTheEmptyOptions()
131+
{
132+
var options = new[] {Option.Some(4), Option.None<int>(), Option.Some(5), Option.None<int>()};
133+
var values = options.WhereSome();
134+
135+
values.Should().HaveCount(2).And.ContainInOrder(4, 5);
136+
}
137+
138+
[Fact]
139+
public void WhereSome_WithPredicate_FiltersTheEmptyOptions()
140+
{
141+
var sequence = new[] {4, -1, 5, -3};
142+
var values = sequence.WhereSome(x => x >= 0 ? Option.Some(x) : Option.None<int>());
143+
144+
values.Should().HaveCount(2).And.ContainInOrder(4, 5);
145+
}
146+
}
147+
}

0 commit comments

Comments
 (0)