Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sonarqube #21

Merged
merged 8 commits into from
Nov 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,16 @@
# supported CodeQL languages.
# ******** NOTE ********

name: "CodeQL"
name: "CodeQL Analyze"

on:
push:
branches: [ develop, main ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ develop ]
branches: [ develop, main ]
schedule:
- cron: '36 12 * * 3'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

strategy:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ name: Build .NET Library

on:
push:
branches: [ develop ]
pull_request:
branches: [ develop, main ]
release:
types:
- published
Expand All @@ -19,7 +21,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.301
dotnet-version: 3.1.403
- name: Install dependencies
run: dotnet restore
- name: Build
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/sonarqube-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Sonarqube Analyze
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
sonarcloud:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
- name: SonarScanner for .NET Core with pull request decoration support
uses: highbyte/sonarscan-dotnet@1.0
with:
sonarProjectKey: qatoolkit_qatoolkit-core-net
sonarProjectName: qatoolkit_qatoolkit-core-net
sonarOrganization: qatoolkit
dotnetBuildArguments: ./src/QAToolKit.Core/QAToolKit.Core.csproj
dotnetDisableTests: true
# Optional extra command arguments the the SonarScanner 'begin' command
sonarBeginArguments: /d:sonar.verbose="true" /d:sonar.language="cs"
sonarHostname: "https://sonarcloud.io"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<Version>0.2.1</Version>
<Version>0.2.2</Version>
</PropertyGroup>
</Project>
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,26 @@
![Nuget](https://img.shields.io/nuget/v/QAToolKit.Core)

## Description
`QAToolKit.Core` is a .NET Standard 2.1 library, that contains core features of the ToolKit. It's normally not used alone but is a dependency for other QAToolKit libraries.

It contains general interfaces and models for QAToolKit libraries, but also core logic and functions to modify `HttpRequest` object.
`QAToolKit.Core` is a .NET Standard 2.1 library, that contains core objects and functions of the toolkit. It's normally not used as a standalone library but is a dependency for other QAToolKit libraries.

## 1. HttpRequest functions
HttpRequest object is one of the main objects that is shared among the QA Toolkit libraries. `QAToolKit.Core` library contains `HttpRequestTools` which can manipulate the HttpRequest object.

Currently there are `HttpRequestUrlGenerator`, `HttpRequestBodyGenerator` and `HttpRequestHeaderGenerator`.
For example URL, header and Body generators: `HttpRequestUrlGenerator`, `HttpRequestBodyGenerator` and `HttpRequestHeaderGenerator`.

### 1.1. HttpRequestUrlGenerator
This is a method that will accept key/value pairs for replacement of placeholders in the `HttpRequest` object.
This is a method that will accept key/value pairs for replacement of placeholders in the `HttpRequest` object. Replacement object are stored in a dictionary, which `prevents mistakes with duplicated keys`.
Also dictionary keys are case insensitive when looking for values to replace.

```csharp
options.AddReplacementValues(new ReplacementValue[] {
new ReplacementValue()
options.AddReplacementValues(new Dictionary<string, object> {
{
Key = "version",
Value = "1"
"version",
"1"
},
{
Key = "parentId",
Value = "4"
"parentId",
"4"
}
});
```
Expand All @@ -40,11 +38,14 @@ That, does not stop there, you can also populate JSON request bodies.
For example if you set the replacement value to stringified json:

```csharp
options.AddReplacementValues(new ReplacementValue[] {
new ReplacementValue()
options.AddReplacementValues(new Dictionary<string, object> {
{
"id",
"100"
},
{
Key = "parent",
Value = "{\"id\":\"100\",\"name\":\"Parent Name\"}"
"category",
"{\"id\":1,\"name\":\"dog\"}"
}
});
```
Expand Down
44 changes: 44 additions & 0 deletions src/QAToolKit.Core.Test/Helpers/DictionaryHelperTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using QAToolKit.Core.Helpers;
using System.Collections.Generic;
using Xunit;

namespace QAToolKit.Core.Test.Helpers
{
public class DictionaryHelperTest
{
[Fact]
public void DictionaryContainsKey_Success()
{
var dictionary = new Dictionary<string, object> {
{ "Key1", "Id"},
{ "category", "cars"},
{ "Name", "MJ"}
};

Assert.True(dictionary.KeyExists("key1"));
Assert.True(dictionary.KeyExists("kEy1"));
Assert.True(dictionary.KeyExists("caTegory"));
Assert.True(dictionary.KeyExists("Category"));
Assert.True(dictionary.KeyExists("category"));
Assert.True(dictionary.KeyExists("Name"));
Assert.True(dictionary.KeyExists("name"));
}

[Fact]
public void GetDictionaryValueByCaseInsensitiveKey_Success()
{
var dictionary = new Dictionary<string, object> {
{ "Key1", "Id"},
{ "category", "cars"},
{ "Name", "MJ"}
};

Assert.Equal("Id", dictionary.GetValue("Key1"));
Assert.Equal("Id", dictionary.GetValue("key1"));
Assert.Equal("MJ", dictionary.GetValue("Name"));
Assert.Equal("MJ", dictionary.GetValue("name"));
Assert.Equal("cars", dictionary.GetValue("category"));
Assert.Equal("cars", dictionary.GetValue("Category"));
}
}
}
13 changes: 10 additions & 3 deletions src/QAToolKit.Core.Test/Helpers/StringHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,15 @@ public void ObfuscateStringBetween_Success(string input, string startTag, string
Assert.Equal(" \"Auth: ***\"", result);
}




[Theory]
[InlineData("TEST STRING 1")]
[InlineData("test string 1")]
[InlineData("Test String 1")]
[InlineData("test String 1")]
[InlineData("Test StrIng 1")]
public void StringContainsCaseInsensitive_Success(string input)
{
Assert.True(input.ContainsCaseInsensitive("Test STrinG 1"));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using QAToolKit.Core.HttpRequestTools;
using QAToolKit.Core.Models;
using System.Collections.Generic;
using System.Linq;
using Xunit;
Expand Down
Loading