All Projects → ivaylokenov → Mytested.webapi

ivaylokenov / Mytested.webapi

Licence: other
Fluent testing framework for ASP.NET Web API 2.

Projects that are alternatives of or similar to Mytested.webapi

Xclcms
XCLCMS is a lightweight CMS (content management system) background management system, Developed using asp.net MVC, it provides a simple and easy-to-use web API interface and supports multiple applications for a single merchant.
Stars: ✭ 107 (-85.12%)
Mutual labels:  webapi, asp-net
Webapiclientgen
Strongly Typed Client API Generators generate strongly typed client APIs in C# .NET and in TypeScript for jQuery and Angular 2+ from ASP.NET Web API and .NET Core Web API
Stars: ✭ 134 (-81.36%)
Mutual labels:  webapi, asp-net
Dbwebapi
(Migrated from CodePlex) DbWebApi is a .Net library that implement an entirely generic Web API (RESTful) for HTTP clients to call database (Oracle & SQL Server) stored procedures or functions in a managed way out-of-the-box without any configuration or coding.
Stars: ✭ 84 (-88.32%)
Mutual labels:  webapi, asp-net
Ps Webapi
(Migrated from CodePlex) Let PowerShell Script serve or command-line process as WebAPI. PSWebApi is a simple library for building ASP.NET Web APIs (RESTful Services) by PowerShell Scripts or batch/executable files out of the box.
Stars: ✭ 24 (-96.66%)
Mutual labels:  webapi, asp-net
WebApiToTypeScript
A tool for code generating TypeScript endpoints for your ASP.NET Web API controllers
Stars: ✭ 26 (-96.38%)
Mutual labels:  asp-net, webapi
Active Directory B2c Dotnet Webapp And Webapi
A combined sample for a .NET web application that calls a .NET Web API, both secured using Azure AD B2C
Stars: ✭ 166 (-76.91%)
Mutual labels:  webapi, asp-net
Huxley
JSON proxy for the UK National Rail Live Departure Board SOAP API
Stars: ✭ 123 (-82.89%)
Mutual labels:  webapi, asp-net
GPONMonitor
GPON Monitoring tool for Dasan Networks GPON OLTs
Stars: ✭ 26 (-96.38%)
Mutual labels:  asp-net, webapi
ByteScout-SDK-SourceCode
ALL source code samples for ByteScout SDKs and Web API API products.
Stars: ✭ 24 (-96.66%)
Mutual labels:  asp-net, webapi
codegenerator
Generate EF6 WebApi with an AngularJS font-end
Stars: ✭ 11 (-98.47%)
Mutual labels:  asp-net, webapi
TraceHub
Centralized and distributed logging for Web applications and services, extending System.Diagnostics and Essential.Diagnostics, providing structured tracing and logging withou needing to change 1 line of your application codes
Stars: ✭ 22 (-96.94%)
Mutual labels:  asp-net, webapi
DotNETCarRental
Daily car rental simulation with ASP.NET.
Stars: ✭ 13 (-98.19%)
Mutual labels:  asp-net, webapi
Openapi Specification
The OpenAPI Specification Repository
Stars: ✭ 22,603 (+3043.67%)
Mutual labels:  webapi
Orchardcore
Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
Stars: ✭ 5,591 (+677.61%)
Mutual labels:  asp-net
Nswag
The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
Stars: ✭ 4,825 (+571.07%)
Mutual labels:  webapi
Angularaspnetcore2webapiauth
Sample project demonstrating jwt-based authentication with an Angular (v5.2.1) frontend and ASP.NET Core 2 WebApi. Includes both local user registration with .NET Core Identity membership and facebook login scenarios.
Stars: ✭ 435 (-39.5%)
Mutual labels:  webapi
Cofoundry
Cofoundry is an extensible and flexible .NET Core CMS & application framework focusing on code first development
Stars: ✭ 621 (-13.63%)
Mutual labels:  asp-net
Fasthttpapi
a lightweight and high-performance http/websocket service component in the dotnet core platform that supports TLS.
Stars: ✭ 554 (-22.95%)
Mutual labels:  webapi
Bash unit
bash unit testing enterprise edition framework for professionals
Stars: ✭ 419 (-41.72%)
Mutual labels:  test-framework
Seldom
WebUI automation testing framework based on Selenium
Stars: ✭ 422 (-41.31%)
Mutual labels:  test-framework

MyTested.WebApi  MyTested.WebApi - Fluent testing
  framework for ASP.NET Web API 2

Diamond Sponsors

Gold Sponsors

Special Sponsors

The Ultimate Cross-Platform .NET Framework JetBrains

Project Description

MyTested.WebApi is a unit testing library providing easy fluent interface to test the ASP.NET Web API 2 framework. It is testing framework agnostic, so you can combine it with a test runner of your choice (e.g. NUnit, xUnit, etc.). Inspired by ChaiJS.

Build status NuGet Version Coverage Status License

Sponsors & Backers

MyTested.WebApi is a community-driven open source library. It's an independent project with its ongoing development made possible thanks to the support by these awesome backers. If you'd like to join them, please consider:

What's the difference between Patreon and OpenCollective?

Funds donated via both platforms are used for development and marketing purposes. Funds donated via OpenCollective are managed with transparent expenses. Your name/logo will receive proper recognition and exposure by donating on either platform.

Documentation

Please see the documentation for full list of available features. Everything listed in the documentation is 100% covered by more than 800 unit tests and should work correctly. Almost all items in the issues page are expected future features and enhancements.

Installation

You can install this library using NuGet into your Test class project. It will automatically reference the needed dependencies of Microsoft.AspNet.WebApi.Core (≥ 5.1.0) and Microsoft.Owin.Testing (≥ 3.0.1) for you. .NET 4.5+ is needed. Make sure your solution has the same versions of the mentioned dependencies in all projects where you are using them. For example, if you are using Microsoft.AspNet.WebApi.Core 5.2.3 in your Web project, the same version should be used after installing MyTested.WebApi in your Tests project.

Install-Package MyTested.WebApi

After the downloading is complete, just add using MyTested.WebApi; and you are ready to test in the most elegant and developer friendly way.

using MyTested.WebApi;

For other interesting packages check out:

How to use

Make sure to check out the documentation for full list of available features. You can also check out the provided samples for real-life ASP.NET Web API application testing.

Basically you can create a test case by using the fluent API the library provides. You are given a static MyWebApi class from which all assertions can be easily configured.

namespace MyApp.Tests.Controllers
{
    using MyTested.WebApi;
	
    using MyApp.Controllers;
    using NUnit.Framework;

    [TestFixture]
    public class HomeControllerShould
    {
        [Test]
        public void ReturnOkWhenCallingGetAction()
        {
            MyWebApi
                .Controller<HomeController>()
                .Calling(c => c.Get())
                .ShouldReturn()
                .Ok();
        }
    }
}

The example uses NUnit but you can use whatever testing framework you want. Basically, MyTested.WebApi throws an unhandled exception if the assertion does not pass and the test fails.

Here are some random examples of what the fluent testing API is capable of:

// tests a route for correct controller, action and resolved route values
MyWebApi
    .Routes()
    .ShouldMap("api/WebApiController/SomeAction/5")
    .WithJsonContent(@"{""SomeInt"": 1, ""SomeString"": ""Test""}")
    .And()
    .WithHttpMethod(HttpMethod.Post)
    .To<WebApiController>(c => c.SomeAction(5, new RequestModel
    {
        SomeInt = 1,
        SomeString = "Test"
    }))
    .AndAlso()
    .ToNoHandler()
    .AndAlso()
    .ToValidModelState();

// injects dependencies into controller
// and mocks authenticated user
// and tests for valid model state
// and tests response model from Ok result with specific assertions
MyWebApi
    .Controller<WebApiController>()
    .WithResolvedDependencyFor<IInjectedService>(mockedInjectedService)
    .WithResolvedDependencyFor<IAnotherInjectedService>(anotherMockedInjectedService);
    .WithAuthenticatedUser(user => user.WithUsername("NewUserName"))
    .Calling(c => c.SomeAction(requestModel))
    .ShouldHave()
    .ValidModelState()
    .AndAlso()
    .ShouldReturn()
    .Ok()
    .WithResponseModelOfType<ResponseModel>()
    .Passing(m =>
    {
        Assert.AreEqual(1, m.Id);
        Assert.AreEqual("Some property value", m.SomeProperty);
    });

// tests whether model state error exists by using lambda expression
// and specific tests for the error messages
MyWebApi
    .Controller<WebApiController>()
    .Calling(c => c.SomeAction(requestModel))
    .ShouldHave()
    .ModelStateFor<RequestModel>()
    .ContainingModelStateErrorFor(m => m.SomeProperty).ThatEquals("Error message") 
    .AndAlso()
    .ContainingModelStateErrorFor(m => m.SecondProperty).BeginningWith("Error") 
    .AndAlso()
    .ContainingModelStateErrorFor(m => m.ThirdProperty).EndingWith("message") 
    .AndAlso()
    .ContainingModelStateErrorFor(m => m.SecondProperty).Containing("ror mes"); 
	
// tests whether the action throws internal server error
// with exception of certain type and with certain message
MyWebApi
    .Controller<WebApiController>()
    .Calling(c => c.SomeAction())
    .ShouldReturn()
    .InternalServerError()
    .WithException()
    .OfType<SomeException>()
    .AndAlso()
    .WithMessage("Some exception message");
	
// run full pipeline integration test
MyWebApi
    .Server()
    .Working(httpConfiguration)
    .WithHttpRequestMessage(
        request => request
            .WithMethod(HttpMethod.Post)
            .WithRequestUri("api/WebApiController/SomeAction/1"))
    .ShouldReturnHttpResponseMessage()
    .WithStatusCode(HttpStatusCode.OK)
    .AndAlso()
    .ContainingHeader("MyCustomHeader");

License

Code by Ivaylo Kenov. Copyright 2015 Ivaylo Kenov.

This library is intended to be used in both open-source and commercial environments. To allow its use in as many situations as possible, MyTested.WebApi is dual-licensed. You may choose to use MyTested.WebApi under either the Apache License, Version 2.0, or the Microsoft Public License (Ms-PL). These licenses are essentially identical, but you are encouraged to evaluate both to determine which best fits your intended use.

Refer to the LICENSE for detailed information.

Any questions, comments or additions?

If you have a feature request or bug report, leave an issue on the issues page or send a pull request. For general questions and comments, use the StackOverflow forum.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].