Skip to content

montraydavis/APIFlow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 

Repository files navigation

alt text

APIFlow

The ultimate solution for quick API Integration testing.

This library allows developers and test engineers to quickly build API Integration tests without having to repeatedly wire up endpoints. Instead, it utilizes a simple context configuration to specify inputs and automatically forward-feeds inputs from previous requests.

(It feels very similar to Entity Framework -- but for APIs)

Check out the wiki for a more in-depth overview!

Forward-Feeding Endpoints

The main purpose of this library is to allow sequential API execution and testing without the necessity of re-writing code to wire up ModelA to ModelB.

This forward-feeding implementation is simple, yet creating complete end-to-end workflows can be done very quickly since wiring up of models only needs to happen once.

Scenario

You have two endpoints.

  1. Fetch Users /api/Users
  2. Fetch User Account Information by Id /api/Users?Id={Users.Id}

Traditionally, if you had to execute these endpoints in succession, you would need to

  1. Create each model.
  2. Make Http Requests.
  3. Wire up inputs for next endpoint payload.
  4. Repeat for remaining endpoints.

With APIFlow, step 2 & 3 is removed as the forward-feed capabilities is automatic with a one-time configuration setup.

alt text

Example Test

User Context /users
public class User{
    public int Id { get; set; }
}
  
public class UserContext : ApiContext<List<User>, HTTPDataExtender>
{
    [HttpGet()]
    [Route("https://aef3c493-6ff3-47a2-be7f-150688405f7e.mock.pstmn.io/Users")]
    public override void ApplyContext(EndpointInputModel model)
    {

    }

    public override void ConfigureClient(ref HttpClientWrapper wrapper)
    {
        base.ConfigureClient(ref wrapper);

        // Add necessary headers etc.
    }

    public UserContext(List<User> baseObject,
        EndpointInputModel inputModel) : base(baseObject, inputModel)
    {

    }
}
User Information Context /users?id={id}
public class UserInformation{
    public int Id { get; set; }
    public int Email { get; set; }
}
  
public class UserInformationContext : ApiContext<UserInformation, HTTPDataExtender>
{
    public override void ConfigureEndpoint(ref string endpoint, EndpointInputModel inputModel, bool randomizedInput = false)
    {
        // Add Query Parameter ?id={UserId.Id}
        base.ConfigureEndpoint<UserContext>("Id", (u) => u.Value?[0].Id??0);
    }
    
    [HttpGet()]
    [Route("https://aef3c493-6ff3-47a2-be7f-150688405f7e.mock.pstmn.io/UserInformation")]
    public override void ApplyContext(EndpointInputModel inputModel)
    {
        // Configure model {User.Id} => {UserInformationContext.Id} 
        base.ConfigureModel<UserContext>((u, o) => o.Id = u.Value?[0].Id??0);
    }

    public UserInformationContext(UserInformation baseObject, EndpointInputModel inputModel) : base(baseObject, inputModel)
    {

    }
}
var apiCpntext = new APIFlowContext();
    
apiContext.Execute<UserContext>()
    .Execute<UserInformationContext>();
    

About

The ultimate test framework for building API Integration tests.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages