Skip to content

Commit

Permalink
Merge branch 'master' into Feature/MigrationTo3.1 (#9)
Browse files Browse the repository at this point in the history
* Migrate the package to the version of Easify

* Remove the template file from WebApi project

* Fix the integration test template

* Upgrade to the latest version of EF

* Fix the wrong logging message
  • Loading branch information
moattarwork authored Nov 17, 2020
1 parent 917092a commit 6bba6ed
Show file tree
Hide file tree
Showing 19 changed files with 244 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<LangVersion>8</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
14 changes: 14 additions & 0 deletions src/content/api/src/Easify.Template.Client/SampleClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Easify.RestEase.Client;
using Easify.Template.Common;
using RestEase;

namespace Easify.Template.Client
{
public interface ISampleClient : IRestClient
{
[Get("api/samples")]
Task<IEnumerable<SampleDto>> GetSampleListAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<LangVersion>8</LangVersion>
</PropertyGroup>

</Project>
7 changes: 7 additions & 0 deletions src/content/api/src/Easify.Template.Common/SampleDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Easify.Template.Common
{
public class SampleDto
{
public string Name { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Easify.Ef.Testing" Version="1.0.7" />
<PackageReference Include="Easify.Testing" Version="3.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="Easify.Ef.Testing" Version="3.0.9" />
<PackageReference Include="Easify.Testing" Version="3.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>8</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -11,10 +12,13 @@

<ItemGroup>
<PackageReference Include="MediatR" Version="9.0.0" />
<PackageReference Include="Easify" Version="3.0.1" />
<PackageReference Include="Easify.Ef" Version="1.0.7" />
<PackageReference Include="Easify.RestEase.Client" Version="3.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.6" />
<PackageReference Include="Easify" Version="3.0.4" />
<PackageReference Include="Easify.Ef" Version="3.0.9" />
<PackageReference Include="Easify.RestEase.Client" Version="3.0.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Easify.Template.Common\Easify.Template.Common.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using MediatR;

namespace Easify.Template.Core.Handlers
{
public class SampleRequest : IRequest<SampleRequestResult>
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Easify.Template.Core.Data;
using Easify.Template.Core.Shared.Domain;
using EfCore.UnitOfWork;
using MediatR;
using Microsoft.Extensions.Logging;

namespace Easify.Template.Core.Handlers
{
public class SampleRequestHandler : IRequestHandler<SampleRequest, SampleRequestResult>
{
private readonly IUnitOfWork<AppDbContext> _unitOfWork;
private readonly ILogger<SampleRequestHandler> _logger;

public SampleRequestHandler(IUnitOfWork<AppDbContext> unitOfWork, ILogger<SampleRequestHandler> logger)
{
_unitOfWork = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}

public async Task<SampleRequestResult> Handle(SampleRequest request, CancellationToken cancellationToken)
{
try
{
_logger.LogInformation($"Loading the list of samples");
var samples = await LoadSamplesAsync();

return SampleRequestResult.Success(samples);
}
catch (Exception e)
{
_logger.LogError("Error in loading samples", e);
return SampleRequestResult.Fail(e.Message);
}
}

private static Task<IEnumerable<Sample>> LoadSamplesAsync()
{
return Task.FromResult(new[] {new Sample("Sample #1"), new Sample("Sample #2")}.AsEnumerable());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;
using Easify.Template.Core.Shared.Domain;

namespace Easify.Template.Core.Handlers
{
public class SampleRequestResult
{
public IEnumerable<Sample> Samples { get; private set; } = new Sample[] { };
public bool HasError { get; private set; }
public string ErrorMessage { get; private set; } = "";

public static SampleRequestResult Fail(string message)
{
return new SampleRequestResult {ErrorMessage = message, HasError = true};
}

public static SampleRequestResult Success(IEnumerable<Sample> samples)
{
return new SampleRequestResult {ErrorMessage = string.Empty, HasError = false, Samples = samples};
}
}
}

This file was deleted.

14 changes: 14 additions & 0 deletions src/content/api/src/Easify.Template.Core/Shared/Domain/Sample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace Easify.Template.Core.Shared.Domain
{
public class Sample
{
public Sample(string name)
{
Name = name ?? throw new ArgumentNullException(nameof(name));
}

public string Name { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
using AutoMapper;
using Easify.Template.Common;
using Easify.Template.Core.Shared.Domain;

namespace Easify.Template.Core.Shared.Profiles
{
public class MappingProfile : Profile
{
// TODO: Rename this for app purpose
public MappingProfile()
{
CreateMap<Sample, SampleDto>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Easify.Ef.Testing" Version="1.0.7" />
<PackageReference Include="Easify.Testing.Integration" Version="3.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="Easify.Ef.Testing" Version="3.0.9" />
<PackageReference Include="Easify.Testing.Integration" Version="3.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -16,6 +16,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Easify.Template.Client\Easify.Template.Client.csproj" />
<ProjectReference Include="..\Easify.Template.WebApi\Easify.Template.WebApi.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Linq;
using System.Threading.Tasks;
using Easify.Template.Client;
using Easify.Template.WebApi.IntegrationTests.Setup;
using Easify.Testing.Integration;
using FluentAssertions;
using Xunit;

namespace Easify.Template.WebApi.IntegrationTests
{
public class SampleControllerTests : IClassFixture<IntegrationTestFixture<TestStartup>>
{
private readonly IntegrationTestFixture<TestStartup> _fixture;

public SampleControllerTests(IntegrationTestFixture<TestStartup> fixture)
{
_fixture = fixture;
}

[Fact]
public async Task Should_GetCompanyNavListAsync_ReturnTheNav_WhenTheRequestIsValid()
{
// Arrange
using var pair = _fixture.CreateClientFromServer<ISampleClient>(s => { });

// Act
var actual = (await pair.Client.GetSampleListAsync()).ToArray();

// Assert
actual.Should().NotBeNull();
actual.Should().HaveCount(2)
.And.Contain(m => m.Name == "Sample #1")
.And.Contain(m => m.Name == "Sample #2");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"ConnectionStrings": {
"AppDatabase": "Data Source=<datasource>;Integrated Security=True; Initial Catalog=<database-name>"
},
"Clients": {

},
"ApplicationInsights": {
"InstrumentationKey": "Instrument Key Here"
},
"AuthOptions": {
"AuthenticationMode": "None",
"Authentication": {
"Authority": "Azure AD authority here. such as https://login.microsoftonline.com/<tenant id>",
"Audience": "<Api Application ID>"
}
},
"Logging": {
"IncludeScopes": false,
"Serilog": {
"MinimumLevel": "Information"
},
"Loggly": {
"ServerUrl": "https://logs-01.loggly.com/",
"CustomerToken": "<Customer token comes here>",
"BufferBaseFilename": "logs\\loggly-buffer",
"NumberOfEventsInSingleBatch": 50,
"BatchPostingIntervalInSeconds": 2,
"EventBodyLimitKb": 10,
"RetainedInvalidPayloadsLimitMb": 100,
"AllowLogLevelToBeControlledRemotely": false
}
},
"Application": {
"Name": "Template.API",
"Version": "1",
"Environment": {
"Name": "Integration"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Threading.Tasks;
using Easify.Template.Core.Handlers;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace Easify.Template.WebApi.Controllers
{
[Route("api/[controller]")]
public class SamplesController : Controller
{
private readonly IMediator _mediator;

public SamplesController(IMediator mediator)
{
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
}

[HttpGet]
public async Task<IActionResult> Get()
{
var result = await _mediator.Send(new SampleRequest());
if (result.HasError)
return BadRequest(result.ErrorMessage);

return Ok(result.Samples);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

<ItemGroup>
<PackageReference Include="Flache.CacheManager" Version="1.0.10" />
<PackageReference Include="Easify.RestEase" Version="3.0.1" />
<PackageReference Include="Easify.AspNetCore.Bootstrap" Version="3.0.1" />
<PackageReference Include="Easify.Logging.SeriLog.Loggly" Version="3.0.1" />
<PackageReference Include="Easify.Logging.SeriLog.Seq" Version="3.0.1" />
<PackageReference Include="Easify.RestEase" Version="3.0.4" />
<PackageReference Include="Easify.AspNetCore.Bootstrap" Version="3.0.4" />
<PackageReference Include="Easify.Logging.SeriLog.Loggly" Version="3.0.4" />
<PackageReference Include="Easify.Logging.SeriLog.Seq" Version="3.0.4" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0" />
</ItemGroup>

Expand Down
Loading

0 comments on commit 6bba6ed

Please sign in to comment.