Coder Social home page Coder Social logo

declarativecontracts's Introduction

DeclarativeContracts

Build codecov Nuget

Lightweight library that enforce design by contract approach in clean and declarative manner

Design by contract is not a brand new, but really powerful technique that could make software reliable and safe from bugs. If you not familiar with this idea, please check this link.

Precondition

Precondition helps to verify that client's of your public API does not violate declared contract that you declared. For this purpose use class Require

For example:

public void SaveClientInfo(Client client)
{
    Require.That(client, (client) => clinet != null);

    //method body implementation code

}

The following lines is a little bit clumsy and hard to read. For solving this issue DeclarativeContracts contains a lot of out of the box functions that incapsulate required functionality

For instance, above checks could be done in the following manner:

public void CheckClientInfo(Client client)
{
    Require.That(clinet, Is.NotNull);

    //TODO: method code

}

Moreover Is and Has classes provide a lot of other useful methods such as:

Is.Null

Is.NotNull

Is.Default

Is.NotDefault

Is.NotOrEmptyString

Is.Positive

Is.Negative

Is.False

Is.True

Is.Odd

Is.Even

Postcondition

Postcondition helps to be sure that you public method always returns expected result and client could be sure that call if thees methods is always save

To perform postcondition check use class: Ensure.

For example:

public VerificationResult VerifyClient(Client client)
{
    Require.That(clinet, Is.NotNull);

    var verificationResult = _verificationService.VerifyClient(client);

    Ensure.That(verificationResult, Is.NotNull);
}

As you could see, this class could be easily combine with build your custom delegates or build in functions.

Q&A

declarativecontracts's People

Contributors

arturlavrov avatar nktlitvinenko avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

nktlitvinenko

declarativecontracts's Issues

Create CI pipeline

Build project and run unit tests

I believe that GitHub actions is a perfect choice for this particular project.

Implement methods for collections

  • має хоча б один елемент (IsNotEmpty)
  • не має елементів (IsEmpty)
  • всі елементи відповідають умові (щось схоже на ALL із T-SQL)
  • хоча б один елемент відповідає умові (щось схоже на ANY із T-SQL)

Implement a following methods

IsPositive
IsNegative
IsZero
IsNotZero
IsOdd (хз, просто в голову прийшло, це мало б бути екстеншином якимось до примітивів)
IsEven (хз, просто в голову прийшло, це мало б бути екстеншином якимось до примітивів)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.