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

Features/technical test #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,5 @@ FodyWeavers.xsd
*.msp

# JetBrains Rider
.idea/
*.sln.iml
5 changes: 5 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<SolutionDir>$(MSBuildThisFileDirectory)</SolutionDir>
</PropertyGroup>
</Project>
11 changes: 11 additions & 0 deletions src/ProjectPatterns/Archetypes/SharedLibraryArchetype.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>

<Import Project="../BaseProject.props" />
<Import Project="../Patterns/LoggingAbstractionPattern.props" />

<ItemGroup>
<PackageReference Include="Ardalis.GuardClauses" Version="4.0.1" />
</ItemGroup>

</Project>
34 changes: 34 additions & 0 deletions src/ProjectPatterns/Archetypes/UnitTestingArchetype.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>

<PropertyGroup>
<GenerateDocumentation Condition="'$(GenerateDocumentation)' == ''">false</GenerateDocumentation>
<IsPackable>false</IsPackable>
<NoWarn>1701;1702;1591;</NoWarn>
<CodeAnalysisRuleSet>$(SolutionDir)/Stylecop_UnitTests.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<Import Project="../BaseProject.props" />

<ItemGroup>
<PackageReference Include="Bogus" Version="34.0.1" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="nunit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
<PackageReference Include="FluentAssertions" Version="6.2.0" />
<PackageReference Include="FluentAssertions.Analyzers" Version="0.11.4" />
<PackageReference Include="coverlet.collector" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>

</Project>
39 changes: 39 additions & 0 deletions src/ProjectPatterns/BaseProject.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<TargetFramework Condition="'$(TargetFramework)' == ''">net6.0</TargetFramework>
<RootNamespace>$(MSBuildProjectName)</RootNamespace>
<Configurations>Debug;Release</Configurations>
<NeutralLanguage>en-GB</NeutralLanguage>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<CodeAnalysisRuleSet Condition="'$(CodeAnalysisRuleSet)' == ''">$(SolutionDir)/Stylecop.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<!-- Set assembly properties -->
<PropertyGroup>
<Company Condition="'$(Company)' == ''">Bugail Consulting Ltd</Company>
<Copyright Condition="'$(Copyright)' == ''">Copyright © 2023 $(Company)</Copyright>
<Authors Condition="'$(Authors)' == ''">$(Company)</Authors>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Update="IDisposableAnalyzers" Version="4.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="$(SolutionDir)\stylecop.json" Link="stylecop.json" />
</ItemGroup>

<!-- Enable documentation generation -->
<PropertyGroup>
<GenerateDocumentationFile Condition="'$(GenerateDocumentationFile)' == ''">true</GenerateDocumentationFile>
</PropertyGroup>

</Project>
8 changes: 8 additions & 0 deletions src/ProjectPatterns/Patterns/LoggingAbstractionPattern.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
</ItemGroup>

</Project>
13 changes: 13 additions & 0 deletions src/ProjectPatterns/Patterns/LoggingPattern.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>

<ItemGroup>
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="3.1.0"/>
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0"/>
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions src/Stylecop.ruleset
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Name" Description="Description" ToolsVersion="16.0">
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<!-- <Rule Id="SA1028" Action="None" /> -->
<Rule Id="SA1101" Action="None" />
<Rule Id="SA1413" Action="None" />
<Rule Id="SA1503" Action="None" />
<Rule Id="SA1627" Action="None" />
<Rule Id="SA1629" Action="None" />
<Rule Id="SA1633" Action="None" />
<Rule Id="SA1635" Action="None" />
<Rule Id="SA1636" Action="None" />
<Rule Id="SA1638" Action="None" />
<Rule Id="SA1640" Action="None" />
<Rule Id="SA1641" Action="None" />
<Rule Id="SA1650" Action="None" />
<Rule Id="CA2254" Action="None" />
</Rules>
</RuleSet>
14 changes: 14 additions & 0 deletions src/Stylecop_UnitTests.ruleset
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Name" Description="Description" ToolsVersion="16.0">
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA1101" Action="None" />
<Rule Id="SA1413" Action="None" />
<Rule Id="SA1503" Action="Info" />
<Rule Id="SA1600" Action="None" />
<Rule Id="SA1627" Action="Info" />
<Rule Id="SA1629" Action="None" />
<Rule Id="SA1633" Action="None" />
<Rule Id="SA1650" Action="Info" />
<Rule Id="CA2254" Action="None" />
</Rules>
</RuleSet>
68 changes: 68 additions & 0 deletions src/Tests/UL.Core.Tests/Extensions/IntegerExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="IntegerExtensions.cs" company="Bugail Consulting Ltd">
// Copyright 2023 (c) Bugail Consulting Ltd. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace UL.Core.Tests
{
using System;
using FluentAssertions;
using NUnit.Framework;
using UL.Core.Extensions;

public class IntegerExtensionsTests
{
[TestCase(1, 1, true)]
[TestCase(0, 1, true)]
[TestCase(2, 3, false)]
[TestCase(15, 3, true)]
[TestCase(15, 5, true)]
[TestCase(16, 3, false)]
[TestCase(16, 5, false)]
[TestCase(16, 5, false)]
public void IsDivisableBy_ValidValues_ReturnsCorrectResult(int value, int divider, bool expectedResult)
{
// Arrange

// Act
var result = value.IsDivisableBy(divider);

// Assert
result.Should().Be(expectedResult);
}

[TestCase(0, 1)]
[TestCase(1, 1)]
[TestCase(2, 2)]
[TestCase(3, 6)]
[TestCase(4, 24)]
[TestCase(5, 120)]
[TestCase(6, 720)]
public void Factorial_PositiveValues_ReturnsValidResult(int value, int expectedResult)
{
// Act
var result = value.Factorial();

// Assert
result.Should().Be(expectedResult);
}

[TestCase(-1)]
[TestCase(-2)]
[TestCase(-3)]
[TestCase(-4)]
[TestCase(-5)]
[TestCase(-6)]
public void Factorial_NegativeValue_ThrowsException(int value)
{
// Act
var result = () => value.Factorial();

// Assert
result.Should()
.Throw<ArgumentException>()
.WithMessage("*Factorial value must be positive*");
}
}
}
31 changes: 31 additions & 0 deletions src/Tests/UL.Core.Tests/Extensions/StringExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="StringExtensionsTests.cs" company="Bugail Consulting Ltd">
// Copyright 2023 (c) Bugail Consulting Ltd. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace UL.Core.Tests
{
using FluentAssertions;
using NUnit.Framework;
using UL.Core.Extensions;

[TestFixture]
public class StringExtensionsTests
{
[TestCase("", false)]
[TestCase(null, false)]
[TestCase("bob", false)]
[TestCase("12x", false)]
[TestCase("1337", true)]
[TestCase("01", true)]
public void IsNumeric_ValidString_ReturnsCorrectResult(string value, bool expectedResult)
{
// Act
var result = value.IsNumeric();

// Assert
result.Should().Be(expectedResult);
}
}
}
10 changes: 10 additions & 0 deletions src/Tests/UL.Core.Tests/UL.Core.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="$(SolutionDir)/ProjectPatterns/Archetypes/UnitTestingArchetype.props" />

<ItemGroup>
<ProjectReference Include="..\..\UL.Core\UL.Core.csproj" />
</ItemGroup>


</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="FizzBuzzRequestValidatorTests.cs" company="Bugail Consulting Ltd">
// Copyright 2023 (c) Bugail Consulting Ltd. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace UL.Core.Tests.Validators
{
using Bogus;
using FluentValidation.TestHelper;
using NUnit.Framework;
using UL.Core.Requests;
using UL.Core.Validators;

public class FizzBuzzRequestValidatorTests
{
private FizzBuzzRequestValidator validator;

[SetUp]
public void Setup()
{
validator = new FizzBuzzRequestValidator();
}

[TestCase("")]
[TestCase(null)]
[TestCase("12x")]
public void Validate_InvalidStart_HasErrors(string value)
{
// Arrange
var model = new FizzBuzzRequest(value, string.Empty);

// Act
var result = validator.TestValidate(model);

// Assert
result.ShouldHaveValidationErrorFor(person => person.Start);
}

[TestCase("")]
[TestCase(null)]
[TestCase("12x")]
[TestCase("0")]
public void Validate_InvalidEnd_HasErrors(string value)
{
// Arrange
var model = new FizzBuzzRequest(string.Empty, value);

// Act
var result = validator.TestValidate(model);

// Assert
result.ShouldHaveValidationErrorFor(person => person.End);
}
}
}
33 changes: 33 additions & 0 deletions src/Tests/UL.Services.Tests/FactoralServiceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="FactoralServiceTests.cs" company="Bugail Consulting Ltd">
// Copyright 2023 (c) Bugail Consulting Ltd. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace UL.Services.Tests
{
using FluentAssertions;
using NUnit.Framework;

[TestFixture]
public class FactoralServiceTests
{
private FactorialService target;

[SetUp]
public void Setup()
{
this.target = new FactorialService();
}

[TestCase(3, 6)]
public void Test(int value, int expectedResult)
{
// Act
var result = this.target.Calculate(value);

// Assert
result.Should().Be(expectedResult);
}
}
}
Loading