Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ language: csharp
mono: none
dotnet: 2.0.0
script:
- dotnet restore ./src
- dotnet build ./**/*.csproj --configuration Release
- dotnet test ./**/*Tests*.csproj
- dotnet test ./src/SolidStack.Core.Guards.Tests/SolidStack.Core.Guards.Tests.csproj
106 changes: 105 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,105 @@
solidstack
<p align="center"><img src="https://i.imgur.com/dA6xa9g.png" alt="SolidStack"></p>

<br>

**Quick links**:
[Docs][docs-url],
[Changelog][changelog-url],
[Nuget][nuget-packages-url]

[![Build status][build-status-badge]][build-url]
[![GitHub release][github-release-badge]][license-url]
[![MIT license][license-badge]][license-url]

<br>

# What is SolidStack?

SolidStack is a .NET framework consisting of several well-divided NuGet packages that allow you to focus on business logic by providing an implementation of very general design patterns useful in every kind of applications such as the [*Option Pattern*][option-pattern-url], the [*Builder Pattern*][builder-pattern-url], the [*Repository Pattern*][repository-pattern-url], the [*Unit of Work Pattern*][unit-of-work-pattern-url] and so more. In short, if you're tired of duplicated and unreadable code, this framework if for you!

## Available NuGet packages

### SolidStack.Core

The `SolidStack.Core` namespace is the central point of all SolidStack packages, providing very generic concepts that are useful in any type of program, such as object construction, object equality, code flow and more.

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.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.

### SolidStack.Domain (coming soon...)

The `SolidStack.Domain` namespace make it easier when it's time to implement business logic by providing a strong basic implementation of the [*domain-driven design*][ddd-url] philosophy.

### SolidStack.Infrastructure (coming soon...)

The `SolidStack.Infrastructure` namespace provides a general implementation of many features that are not releated to business logic like memory deallocation, time, encryption, serialization and so on.

### SolidStack.Persistence (coming soon...)

The `SolidStack.Testing` namespace abstracts how the data is stored so that you can simply switch the way your application stores your data to almost everything such as a SQL database, a NoSQL database, local files, in memory and many more without affecting the rest of your application.

### SolidStack.Testing (coming soon...)

The `SolidStack.Testing` namespace provide classes to help you build highly reusable and readable tests so you can simply write tests on a given interface once and then validate each concrete type of that interface with those same tests.

# How do I get started?

Check out our [wiki][docs-url] to explore the documentation provided for the packages you want. There is documentation on each package available!

# 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:

```
PM> Install-Package <PackageName>
```

# I have an issue...

First, you can check if your issue has already been tracked [here][issues-url].

Otherwise, you can check if it's already fixed by pulling the [develop branch][develop-branch-url], building the solution and then using the generated DLL files direcly in your project.

If you still hit a problem, please document it and post it [here][new-issue-url].

# How can I contribute?

Contributors are greatly appreciated, just follow the following steps:

1. **Fork** the repository
2. **Clone** the project to your own machine
3. **Commit** changes to your own branch
4. **Push** your work back up to your fork
5. **Create a pull request** containing a description and your work and what is the motivation behind it
6. **Submit your pull request** so that we can review your changes

# License

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
[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
[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
[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
[unit-of-work-pattern-url]: https://martinfowler.com/eaaCatalog/unitOfWork.html
[value-object-pattern-url]: https://martinfowler.com/bliki/ValueObject.html
197 changes: 197 additions & 0 deletions src/SolidStack.Core.Guards.Tests/GuardTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using FluentAssertions;
using SolidStack.Core.Guards.Internal;
using SolidStack.Testing.Xunit;
using Xunit;

namespace SolidStack.Core.Guards.Tests
{
public class GuardTests
{
[Fact]
public void Ensures_WithMatchedPredicate_DoesntThrows()
{
Action act = () => Guard.Ensures(() => true, "error");

act.Should().NotThrow<GuardClauseException>();
}

[DebugOnlyFact]
public void Ensures_WithUnmatchedPredicateInDebug_Throws()
{
Action act = () => Guard.Ensures(() => false, "error");

act.Should().Throw<GuardClauseException>();
}

[Theory]
[InlineData(new[] { 0, 4, 6, 10 })]
public void EnsuresAll_WithMatchedPredicates_DoesntThrows(IEnumerable<int> sequence)
{
Action act = () => Guard.EnsuresAll(sequence, n => n >= 0, "error");

act.Should().NotThrow<GuardClauseException>();
}

[DebugOnlyTheory]
[InlineData(new[] { -4, 0, 6, 10 })]
[InlineData(new[] { -2, -3, -5, -3 })]
public void EnsuresAll_WithUnmatchedPredicatesInDebug_Throws(IEnumerable<int> sequence)
{
Action act = () => Guard.EnsuresAll(sequence, n => n >= 0, "error");

act.Should().Throw<GuardClauseException>();
}

[Theory]
[InlineData(new[] { 0, 4, 6, 10 })]
[InlineData(new[] { -2, -3, 5, -3 })]
[InlineData(new[] { -2, 0, -7, -5 })]
public void EnsuresAny_WithMatchedPredicates_DoesntThrows(IEnumerable<int> sequence)
{
Action act = () => Guard.EnsuresAny(sequence, n => n >= 0, "error");

act.Should().NotThrow<GuardClauseException>();
}

[DebugOnlyTheory]
[InlineData(new[] { -2, -3, -5, -3 })]
public void EnsuresAny_WithUnmatchedPredicatesInDebug_Throws(IEnumerable<int> sequence)
{
Action act = () => Guard.EnsuresAny(sequence, n => n >= 0, "error");

act.Should().Throw<GuardClauseException>();
}

[Fact]
public void EnsuresNonNull_WithNonNull_DoesntThrows()
{
const string nonNull = "";
Action act = () => Guard.EnsuresNonNull(nonNull, "error");

act.Should().NotThrow<GuardClauseException>();
}

[DebugOnlyFact]
[SuppressMessage("ReSharper", "ExpressionIsAlwaysNull")]
public void EnsuresNonNull_WithNullInDebug_Throws()
{
string @null = null;
Action act = () => Guard.EnsuresNonNull(@null, "error");

act.Should().Throw<GuardClauseException>();
}

[Fact]
public void EnsuresNoNullIn_WithNoNull_DoesntThrows()
{
var sequence = new[] { "foo", "bar", "baz" };
Action act = () => Guard.EnsuresNoNullIn(sequence, "error");

act.Should().NotThrow<GuardClauseException>();
}

[DebugOnlyFact]
public void EnsuresNoNullIn_WithNullsInDebug_Throws()
{
var sequence = new[] { "foo", null, "baz" };
Action act = () => Guard.EnsuresNoNullIn(sequence, "error");

act.Should().Throw<GuardClauseException>();
}

[Fact]
public void Requires_WithMatchedPredicate_DoesntThrows()
{
Action act = () => Guard.Requires(() => true, "error");

act.Should().NotThrow<GuardClauseException>();
}

[Fact]
public void Requires_WithUnmatchedPredicate_Throws()
{
Action act = () => Guard.Requires(() => false, "error");

act.Should().Throw<GuardClauseException>();
}

[Theory]
[InlineData(new[] { 0, 4, 6, 10 })]
public void RequiresAll_WithMatchedPredicates_DoesntThrows(IEnumerable<int> sequence)
{
Action act = () => Guard.RequiresAll(sequence, n => n >= 0, "error");

act.Should().NotThrow<GuardClauseException>();
}

[DebugOnlyTheory]
[InlineData(new[] { -4, 0, 6, 10 })]
[InlineData(new[] { -2, -3, -5, -3 })]
public void RequiresAll_WithUnmatchedPredicates_Throws(IEnumerable<int> sequence)
{
Action act = () => Guard.RequiresAll(sequence, n => n >= 0, "error");

act.Should().Throw<GuardClauseException>();
}

[Theory]
[InlineData(new[] { 0, 4, 6, 10 })]
[InlineData(new[] { -2, -3, 5, -3 })]
[InlineData(new[] { -2, 0, -7, -5 })]
public void RequiresAny_WithMatchedPredicates_DoesntThrows(IEnumerable<int> sequence)
{
Action act = () => Guard.RequiresAny(sequence, n => n >= 0, "error");

act.Should().NotThrow<GuardClauseException>();
}

[DebugOnlyTheory]
[InlineData(new[] { -2, -3, -5, -3 })]
public void RequiresAny_WithUnmatchedPredicates_Throws(IEnumerable<int> sequence)
{
Action act = () => Guard.RequiresAny(sequence, n => n >= 0, "error");

act.Should().Throw<GuardClauseException>();
}

[Fact]
public void RequiresNonNull_WithNonNull_DoesntThrows()
{
const string nonNull = "";
Action act = () => Guard.RequiresNonNull(nonNull, "error");

act.Should().NotThrow<GuardClauseException>();
}

[Fact]
[SuppressMessage("ReSharper", "ExpressionIsAlwaysNull")]
public void RequiresNonNull_WithNull_Throws()
{
string @null = null;
Action act = () => Guard.RequiresNonNull(@null, "error");

act.Should().Throw<GuardClauseException>();
}

[Fact]
public void RequiresNoNullIn_WithNoNull_DoesntThrows()
{
var sequence = new[] { "foo", "bar", "baz" };
Action act = () => Guard.RequiresNoNullIn(sequence, "error");

act.Should().NotThrow<GuardClauseException>();
}

[DebugOnlyFact]
public void RequiresNoNullIn_WithNulls_Throws()
{
var sequence = new[] { "foo", null, "baz" };
Action act = () => Guard.RequiresNoNullIn(sequence, "error");

act.Should().Throw<GuardClauseException>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="xunit" Version="2.4.0-beta.1.build3958" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0-beta.1.build3958" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SolidStack.Core.Guards\SolidStack.Core.Guards.csproj" />
<ProjectReference Include="..\SolidStack.Testing.Xunit\SolidStack.Testing.Xunit.csproj" />
</ItemGroup>

<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>

</Project>
Loading