<commit_before># Coding Test for AGL with Azure Functions #

This provides a sample code repository for coding test in AGL before being engaged.


## Requirements ##

Based on the instruction on [http://agl-developer-test.azurewebsites.net/](http://agl-developer-test.azurewebsites.net/), a candidate is required to submit an application to fulfill the requirements.

* Data source can be aquired from a JSON object by sending an HTTP request to [http://agl-developer-test.azurewebsites.net/people.json](http://agl-developer-test.azurewebsites.net/people.json).
* The data source needs to be processed to display result with the rules of:
  * Display all cats in alphabetical order,
  * All cats are listed under their owners' gender, and
  * Can owners' genders are considered as headings.
* Use LINQ for grouping and sorting the data source.


## Prerequisites ##

This application is written by Visual Studio Enterprise 2017 (v15.4.1). VS 2017 Community Edition is also fine to run the code.


## Implementation ##

In order to satisfy the requirements, I used the **serverless** architecture &ndash; Azure Functions, because:

* It doesn't need to setup an application environment,
* It only focuses on the code itself, which is basically business logic, and
* It's easy to build

The application consists of number of small libraries that only take care of one responsibility respectively &ndash; settings, models, services, functions and IoC. Also each project has its corresponding test projects for unit testing.


## Reproduction ##

The application can be run on either local machine or Azure Functions instance on Azure. In order to run this application, use Visual Studio or Azure Function Tooling npm package. If Visual Studio is chosen, follow the steps below:

* Clone the repository to your local machine.
* Open `AglCodingTest.sln`.
* Build the solution.
* Press F5 key to run the Azure Function instance locally.
* Open a web browser and type `http://localhost:7071/pets` to run the Azure Functions application.
* The required result will be displayed.
* A querystring parameter, `type` can be used to specify the pet type. Currently, the `type` parameter only considers three values &ndash; `Dog`, `Cat` and `Fish`

Valid requests are:

* [http://localhost:7071/pets](http://localhost:7071/pets)
* [http://localhost:7071/pets?type=cat](http://localhost:7071/pets?type=cat)
* [http://localhost:7071/pets?type=dog](http://localhost:7071/pets?type=dog)
* [http://localhost:7071/pets?type=fish](http://localhost:7071/pets?type=fish)

<commit_msg>Add local.settings.json sample to README.md<commit_after># Coding Test for AGL with Azure Functions #

This provides a sample code repository for coding test in AGL before being engaged.


## Requirements ##

Based on the instruction on [http://agl-developer-test.azurewebsites.net/](http://agl-developer-test.azurewebsites.net/), a candidate is required to submit an application to fulfill the requirements.

* Data source can be aquired from a JSON object by sending an HTTP request to [http://agl-developer-test.azurewebsites.net/people.json](http://agl-developer-test.azurewebsites.net/people.json).
* The data source needs to be processed to display result with the rules of:
  * Display all cats in alphabetical order,
  * All cats are listed under their owners' gender, and
  * Can owners' genders are considered as headings.
* Use LINQ for grouping and sorting the data source.


## Prerequisites ##

* [Visual Studio 2017 (v15.4.1)](https://www.visualstudio.com/)
* [Azure Storage Emulator v5.2](https://docs.microsoft.com/en-au/azure/storage/common/storage-use-emulator)

For your local debugging purpose, the `local.settings.json` should exist. If it doesn't, create one. The bare minimum content of it should look like:

```csharp
{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "AzureWebJobsDashboard": "UseDevelopmentStorage=true",

    "Agl.Endpoint": "http://agl-developer-test.azurewebsites.net/people.json"
  }
}
```


## Implementation ##

In order to satisfy the requirements, I used the **serverless** architecture &ndash; Azure Functions, because:

* It doesn't need to setup an application environment,
* It only focuses on the code itself, which is basically business logic, and
* It's easy to build

The application consists of number of small libraries that only take care of one responsibility respectively &ndash; settings, models, services, functions and IoC. Also each project has its corresponding test projects for unit testing.


## Reproduction ##

The application can be run on either local machine or Azure Functions instance on Azure. In order to run this application, use Visual Studio or Azure Function Tooling npm package. If Visual Studio is chosen, follow the steps below:

* Clone the repository to your local machine.
* Open `AglCodingTest.sln`.
* Build the solution.
* Press F5 key to run the Azure Function instance locally.
* Open a web browser and type `http://localhost:7071/pets` to run the Azure Functions application.
* The required result will be displayed.
* A querystring parameter, `type` can be used to specify the pet type. Currently, the `type` parameter only considers three values &ndash; `Dog`, `Cat` and `Fish`

Valid requests are:

* [http://localhost:7071/pets](http://localhost:7071/pets)
* [http://localhost:7071/pets?type=cat](http://localhost:7071/pets?type=cat)
* [http://localhost:7071/pets?type=dog](http://localhost:7071/pets?type=dog)
* [http://localhost:7071/pets?type=fish](http://localhost:7071/pets?type=fish)


{'fraction_non_alphanumeric': 0.09655541674103159, 'fraction_numerical': 0.01713367838657862, 'mean_word_length': 4.747692307692308, 'pattern_counts': {'":': 5, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2385432', 'n_tokens_mistral': 1648, 'n_tokens_neox': 1519, 'n_words': 648}