GithubHelp home page GithubHelp logo

apiproject's Introduction

APIProject

Description

It's an API Web app working depend on a class library, you give it numbers and it will calculate the numbers and get three results depend on the parameter you will give it, Average of numbers, Smallest number and Largest number.

The Class library carry the functions, and the API value controller carry the business logic. and i make the class library as a dependency.

Code View

In the below points i will put parts from the code i use in the Class library and the API

  • Class Library

    1- Average

    public int Average(int[] nums)
    {
        int total = 0;
        foreach (var num in nums)
        {
            total += num;
        }
        return total / nums.Count();
    }
    

    2- Smallest

         public int Smallest(int[] nums)
    {
        int smallest = nums[0];
        foreach (var num in nums)
        {
            if (num < smallest)
            {
                smallest = num;
            }
        }
        return smallest;
    }
    

    3- Largest

         public int Largest(int[] nums)
    {
        int largest = nums[0];
        foreach (var num in nums)
        {
            if (num > largest)
            {
                largest = num;
            }
        }
        return largest;
    }
    

Also i created a unit test for the class library to check the code covarage, please check the below unit test for Average funcation

     [TestMethod]
    public void TestAverrage()
    {
        //Arrange

        Math math1 = new Math();
        var nums = new int[] { 10, 33, 50, 2, 100 };

        //Act

        var result = math1.Average(nums);

        //Assert

        Assert.IsTrue(result == 39);

    }

The below screenshot from the unit test result

image

I used Git to push my packages to the remote repo on Azure Devops

image

I used Azure Pipeline to run a CI on the Class Library, and store the package on Nuget.org.

image

You can find my Class Library package on https://www.nuget.org/packages/SherbeenyLibrary/

  • API

    1- Average

        [HttpGet("/average")]
    public int Average([FromQuery] int[] nums)
    {
        return math.Average(nums);
    }
    

    2- Smallest

        [HttpGet("/smallest")]
    public int Smallest([FromQuery] int[] nums)
    {
    
        return math.Smallest(nums);
    }
    

    3- Largest

        [HttpGet("/largest")]
    public int Largest([FromQuery] int[] nums)
    {
        return math.Largest(nums);
    }
    

    }

Also i used Azure Pipeline to run CI/CD on the API, here is the below screenshot from the CI/CD

Continuous Integration (CI)

image

Note: This time i upload the package on Azure Artifact not Nuget.

Contiuous Deleviry (CD)

image

image

image

Note: I used MicroSoft Azure to upload My Web App but my subscription was ended.

apiproject's People

Contributors

ahmedsherbeeny 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.