Giter VIP home page Giter VIP logo

rest-mock-core's Introduction

NuGet version Build status

rest-mock-core

A simple http server for using in test projects which test .net core based projects. It is tested with Visual Studio 2015 Update 3 and xUnit.

Problem

When I started to write test for a netcore app, I realized that many of libraries do not work in that platform. One of my problems was to find an appropriate Http Server Mock library. Therefor I started to write this project.

Install

Install-Package rest-mock-core

Usage

By default, the server will return "It Works!" by Ok status code (200).

HttpServer mockServer = new HttpServer();
mockServer.Run();

Then you can use any http client sending request to it. Default url is http://localhost:5000 which its port could be changed constructor:

HttpClient httpClient = new HttpClient(5001);

More

There are some options to manage requests better:

mockServer.Config.Get("/test/123").Send("It Really Works!");
mockServer.Config.Post("/test2/123").Send("It is not working!", 503);
mockServer.Config.Get("/testAction/123").Send(context =>
            {
                context.Response.StatusCode = 200;
                string response = "Action Test";
                byte[] buffer = System.Text.Encoding.UTF8.GetBytes(response);
                buffer = System.Text.Encoding.UTF8.GetBytes(response);
                context.Response.Body.WriteAsync(buffer, 0, buffer.Length);
            });

You can use server.Config either before or after server.Run()

For more details please check Test project. More options will be added ASAP.

rest-mock-core's People

Contributors

benyblack avatar jtone123 avatar rgparkins 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.