-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into Feature/MigrationTo3.1 (#9)
* 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
1 parent
917092a
commit 6bba6ed
Showing
19 changed files
with
244 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/content/api/src/Easify.Template.Client/SampleClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/content/api/src/Easify.Template.Core/Handlers/SampleRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
{ | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/content/api/src/Easify.Template.Core/Handlers/SampleRequestHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/content/api/src/Easify.Template.Core/Handlers/SampleRequestResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; | ||
} | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
src/content/api/src/Easify.Template.Core/Shared/Domain/.gitkeep
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
src/content/api/src/Easify.Template.Core/Shared/Domain/Sample.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
7 changes: 6 additions & 1 deletion
7
src/content/api/src/Easify.Template.Core/Shared/Profiles/MappingProfile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/content/api/src/Easify.Template.WebApi.IntegrationTests/SampleControllerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/content/api/src/Easify.Template.WebApi.IntegrationTests/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/content/api/src/Easify.Template.WebApi/Controllers/SamplesController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
41 changes: 0 additions & 41 deletions
41
src/content/api/src/Easify.Template.WebApi/Controllers/ValuesController.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.