Giter Club home page Giter Club logo

webassert's Introduction

WebAssert

Simple assert class to be used with ASP.NET MVC projects.

I wanted a way to call asserts inside ASP.NET MVC code. Using the usual Debug.Assert ins't ideal - yes you can configure your ASP.NET MVC website to show the failed assert dialog, but it's not a great developer experience.

I've created a custom assert class named WebAssert. Here is an example of how to use it...

public ActionResult Index(string imagePath = "")
{
    WebAssert.Assert(() => !string.IsNullOrEmpty(imagePath), "The param 'imagePath' must not be empty.");

    return View();
}

When an assert fails, one of two things will happen, depending on whether you are attached to the website with a debugger.

Debugger Attached

The code will break inside WebAssert.Assert() giving you the chance to navigate the call stack in order to investigate why the assertion has failed. Also, some debug information will be outputted to the 'Immediate Window' to give you a head start on what has happened...

2018-12-12_15-19-08

2018-12-12_15-16-46

Debugger Not Attached

If no debugger is attached, then the failed assertion details will be outputted to the browser, using a HTML file as a template.

The HTML file is called AssertFailed.cshtml. Here is an example of what you will see when an assertion fails...

2018-12-12_15-21-06

webassert's People

Contributors

mrclyfar avatar

Watchers

 avatar

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.