This repository has been archived by the owner on Nov 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DDD]: registering services; fixing logging
- Loading branch information
Showing
10 changed files
with
175 additions
and
43 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
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
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
34 changes: 0 additions & 34 deletions
34
backend/Idontknow.Domain/ViewModels/Result/ServiceBaseResult.cs
This file was deleted.
Oops, something went wrong.
35 changes: 32 additions & 3 deletions
35
backend/Idontknow.Domain/ViewModels/Result/ServiceResult.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,10 +1,39 @@ | ||
namespace Idontknow.Domain.ViewModels.Result | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using FluentValidation.Results; | ||
|
||
namespace Idontknow.Domain.ViewModels.Result | ||
{ | ||
public class ServiceResult<TPayload> : ServiceBaseResult<TPayload> | ||
public class ServiceResult<TPayload> | ||
{ | ||
public bool IsSuccessful { get; set; } | ||
|
||
public ValidationResult Validation { get; set; } | ||
|
||
public TPayload Payload { get; set; } | ||
|
||
public string Message { get; set; } | ||
|
||
public HttpStatusCode StatusCode { get; set; } | ||
|
||
public void AddErrors(ValidationResult validation) | ||
{ | ||
if (Validation == null) | ||
Validation = new ValidationResult(); | ||
|
||
foreach (var error in validation.Errors) | ||
{ | ||
IsSuccessful = false; | ||
Validation.Errors.Add(error); | ||
} | ||
} | ||
} | ||
|
||
public class ServiceResult : ServiceBaseResult<object> | ||
public class ListServiceResult<TPayload> : ServiceResult<TPayload> | ||
{ | ||
public int Pages { get; set; } = 1; | ||
public int TotalItems { get; set; } | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...ntknow.IntegrationTests/Feature/Authentification/when_user_is_registered_and_logged_in.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,57 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Net.Http; | ||
using System.Net.Http.Headers; | ||
using System.Text; | ||
using Idontknow.Api; | ||
using Idontknow.Domain.ViewModels.Service.Account; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.TestHost; | ||
using Microsoft.Extensions.Logging; | ||
using Newtonsoft.Json; | ||
using Xunit; | ||
|
||
namespace Idontknow.IntegrationTests.Feature.Authentification | ||
{ | ||
public class when_user_is_registered | ||
{ | ||
private TestServer _server; | ||
private HttpClient _client; | ||
|
||
public when_user_is_registered() | ||
{ | ||
_server = new TestServer(new WebHostBuilder() | ||
.ConfigureLogging(options => options.AddConsole()) | ||
.UseStartup<Startup>()); | ||
_client = _server.CreateClient(); | ||
|
||
// Register | ||
var requestDataOne = new { Email = "test1@test.com", Password = "123456aA!" }; | ||
var contentOne = new StringContent(JsonConvert.SerializeObject(requestDataOne), Encoding.UTF8, "application/json"); | ||
var resultOne = _client.PostAsync("/Account/Register", contentOne).Result; | ||
resultOne.EnsureSuccessStatusCode(); | ||
|
||
// Login | ||
var requestDataTwo = new List<KeyValuePair<string, string>> | ||
{ | ||
new KeyValuePair<string, string>("grant_type", "password"), | ||
new KeyValuePair<string, string>("username", "test@test.com"), | ||
new KeyValuePair<string, string>("password", "123456aA!") | ||
}; | ||
var contentTwo = new FormUrlEncodedContent(requestDataTwo); | ||
var resultTwo = _client.PostAsync("/connect/token", contentTwo).Result; | ||
resultTwo.EnsureSuccessStatusCode(); | ||
var responseContent = resultTwo.Content.ReadAsStringAsync().Result; | ||
var token = requestDataOne; | ||
|
||
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", $"Bearer {token}"); | ||
} | ||
|
||
[Fact] | ||
public void user_should_be_able_to_access_restricted_paths() | ||
{ | ||
var resultThree = _client.GetAsync("/api/blogs").Result; | ||
resultThree.EnsureSuccessStatusCode(); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
backend/Idontknow.IntegrationTests/Feature/Blogging/when_blog_is_added.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,23 @@ | ||
using System.Net.Http; | ||
using Microsoft.AspNetCore.TestHost; | ||
using Xunit; | ||
|
||
namespace Idontknow.IntegrationTests.Feature.Blogging | ||
{ | ||
public class when_blog_is_added | ||
{ | ||
private TestServer _server; | ||
private HttpClient _client; | ||
|
||
public when_blog_is_added() | ||
{ | ||
// TODO: post | ||
} | ||
|
||
[Fact] | ||
public void then_blog_should_be_in_database() | ||
{ | ||
// TODO: get | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
backend/Idontknow.IntegrationTests/Idontknow.IntegrationTests.csproj
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,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.1" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" /> | ||
<PackageReference Include="xunit" Version="2.2.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Idontknow.Api\Idontknow.Api.csproj" /> | ||
</ItemGroup> | ||
</Project> |