Merge branch 'Dev' of https://github.com/dotnet/eShopOnContainers into Dev
This commit is contained in:
commit
1238961414
@ -62,7 +62,7 @@ services:
|
|||||||
- SpaClient=http://localhost:5104
|
- SpaClient=http://localhost:5104
|
||||||
- ConnectionStrings__DefaultConnection=Server=sql.data;Database=Microsoft.eShopOnContainers.Service.IdentityDb;User Id=sa;Password=Pass@word
|
- ConnectionStrings__DefaultConnection=Server=sql.data;Database=Microsoft.eShopOnContainers.Service.IdentityDb;User Id=sa;Password=Pass@word
|
||||||
#- MvcClient=http://13.88.8.119:5100 #Remote: VM Needs to have public access at 5105.
|
#- MvcClient=http://13.88.8.119:5100 #Remote: VM Needs to have public access at 5105.
|
||||||
- MvcClient=http://localhost:5100 #Local: You need a entry in windows host file to run identity in local docker.
|
#- MvcClient=http://localhost:5100 #Local: You need a entry in windows host file to run identity in local docker.
|
||||||
- MvcClient=http://10.0.75.1:5100 #Local: You need to open windows firewall at range 5100-5105.
|
- MvcClient=http://10.0.75.1:5100 #Local: You need to open windows firewall at range 5100-5105.
|
||||||
ports:
|
ports:
|
||||||
- "5105:5105"
|
- "5105:5105"
|
||||||
|
@ -73,7 +73,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "eShopOnContainers.UITests",
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "eShopOnContainers.Core", "src\Mobile\eShopOnContainers\eShopOnContainers.Core\eShopOnContainers.Core.csproj", "{67F9D3A8-F71E-4428-913F-C37AE82CDB24}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "eShopOnContainers.Core", "src\Mobile\eShopOnContainers\eShopOnContainers.Core\eShopOnContainers.Core.csproj", "{67F9D3A8-F71E-4428-913F-C37AE82CDB24}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Ordering.Application", "src\Services\Ordering\Ordering.Application\Ordering.Application.xproj", "{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}"
|
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "UnitTest", "test\Services\UnitTest\UnitTest.xproj", "{7796F5D8-31FC-45A4-B673-19DE5BA194CF}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -908,54 +908,54 @@ Global
|
|||||||
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.Release|x64.Build.0 = Release|Any CPU
|
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.Release|x64.Build.0 = Release|Any CPU
|
||||||
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.Release|x86.ActiveCfg = Release|Any CPU
|
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.Release|x86.Build.0 = Release|Any CPU
|
{67F9D3A8-F71E-4428-913F-C37AE82CDB24}.Release|x86.Build.0 = Release|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|x64.Build.0 = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Ad-Hoc|x64.Build.0 = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Ad-Hoc|x86.Build.0 = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Ad-Hoc|x86.Build.0 = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|Any CPU.Build.0 = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.AppStore|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|ARM.ActiveCfg = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.AppStore|ARM.ActiveCfg = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|ARM.Build.0 = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.AppStore|ARM.Build.0 = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|iPhone.Build.0 = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.AppStore|iPhone.Build.0 = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|x64.ActiveCfg = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.AppStore|x64.ActiveCfg = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|x64.Build.0 = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.AppStore|x64.Build.0 = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|x86.ActiveCfg = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.AppStore|x86.ActiveCfg = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.AppStore|x86.Build.0 = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.AppStore|x86.Build.0 = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|ARM.Build.0 = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|iPhone.ActiveCfg = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Debug|iPhone.ActiveCfg = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|iPhone.Build.0 = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Debug|iPhone.Build.0 = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|x64.ActiveCfg = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|x64.Build.0 = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|x86.ActiveCfg = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Debug|x86.Build.0 = Debug|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|Any CPU.Build.0 = Release|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|ARM.ActiveCfg = Release|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Release|ARM.ActiveCfg = Release|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|ARM.Build.0 = Release|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Release|ARM.Build.0 = Release|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|iPhone.ActiveCfg = Release|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Release|iPhone.ActiveCfg = Release|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|iPhone.Build.0 = Release|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Release|iPhone.Build.0 = Release|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|x64.ActiveCfg = Release|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|x64.Build.0 = Release|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Release|x64.Build.0 = Release|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|x86.ActiveCfg = Release|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7}.Release|x86.Build.0 = Release|Any CPU
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@ -990,6 +990,6 @@ Global
|
|||||||
{621E7211-58D0-45FD-9600-1CB490BD930E} = {EF0337F2-ED00-4643-89FD-EE10863F1870}
|
{621E7211-58D0-45FD-9600-1CB490BD930E} = {EF0337F2-ED00-4643-89FD-EE10863F1870}
|
||||||
{E3B18084-842C-4B80-8E4A-A7E588EC3137} = {B7B1D395-4E06-4036-BE86-C216756B9367}
|
{E3B18084-842C-4B80-8E4A-A7E588EC3137} = {B7B1D395-4E06-4036-BE86-C216756B9367}
|
||||||
{67F9D3A8-F71E-4428-913F-C37AE82CDB24} = {778289CA-31F7-4464-8C2A-612EE846F8A7}
|
{67F9D3A8-F71E-4428-913F-C37AE82CDB24} = {778289CA-31F7-4464-8C2A-612EE846F8A7}
|
||||||
{4193CAA3-A1C3-4818-A06F-A2D85FDE77E7} = {0BD0DB92-2D98-44D9-9AC0-C59186D59B0B}
|
{7796F5D8-31FC-45A4-B673-19DE5BA194CF} = {EF0337F2-ED00-4643-89FD-EE10863F1870}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
@ -82,7 +82,8 @@ namespace eShopOnContainers.Identity.Configuration
|
|||||||
RedirectUris = new List<string>
|
RedirectUris = new List<string>
|
||||||
{
|
{
|
||||||
$"{clientsUrl["Mvc"]}/signin-oidc",
|
$"{clientsUrl["Mvc"]}/signin-oidc",
|
||||||
"http://104.40.62.65:5100/signin-oidc"
|
"http://104.40.62.65:5100/signin-oidc",
|
||||||
|
"http://localhost:5100"
|
||||||
},
|
},
|
||||||
PostLogoutRedirectUris = new List<string>
|
PostLogoutRedirectUris = new List<string>
|
||||||
{
|
{
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
using Api.Application.Commands;
|
using Api.Application.Commands;
|
||||||
using Api.Application.Queries;
|
using Api.Application.Queries;
|
||||||
using AspNetCore.Authorization;
|
using AspNetCore.Authorization;
|
||||||
|
using Infrastructure.Services;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Models;
|
using Models;
|
||||||
@ -16,8 +17,9 @@
|
|||||||
{
|
{
|
||||||
private readonly IMediator _mediator;
|
private readonly IMediator _mediator;
|
||||||
private readonly IOrderQueries _orderQueries;
|
private readonly IOrderQueries _orderQueries;
|
||||||
|
private readonly IIdentityService _identityService;
|
||||||
|
|
||||||
public OrdersController(IMediator mediator, IOrderQueries orderQueries)
|
public OrdersController(IMediator mediator, IOrderQueries orderQueries, IIdentityService identityService)
|
||||||
{
|
{
|
||||||
if (mediator == null)
|
if (mediator == null)
|
||||||
{
|
{
|
||||||
@ -29,21 +31,24 @@
|
|||||||
throw new ArgumentNullException(nameof(orderQueries));
|
throw new ArgumentNullException(nameof(orderQueries));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (identityService == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException(nameof(identityService));
|
||||||
|
}
|
||||||
|
|
||||||
_mediator = mediator;
|
_mediator = mediator;
|
||||||
_orderQueries = orderQueries;
|
_orderQueries = orderQueries;
|
||||||
|
_identityService = identityService;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("new")]
|
[Route("new")]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> AddOrder([FromBody]NewOrderRequest order)
|
public async Task<IActionResult> AddOrder([FromBody]NewOrderRequest order)
|
||||||
{
|
{
|
||||||
if (order.CardExpiration == DateTime.MinValue)
|
|
||||||
order.CardExpiration = DateTime.Now.AddYears(5);
|
|
||||||
|
|
||||||
if (order.CardTypeId == 0)
|
if (order.CardTypeId == 0)
|
||||||
order.CardTypeId = 1;
|
order.CardTypeId = 1;
|
||||||
|
|
||||||
order.Buyer = GetUserName();
|
order.Buyer = _identityService.GetUserIdentity();
|
||||||
|
|
||||||
var added = await _mediator.SendAsync(order);
|
var added = await _mediator.SendAsync(order);
|
||||||
if (added)
|
if (added)
|
||||||
@ -86,17 +91,7 @@
|
|||||||
|
|
||||||
return Ok(cardTypes);
|
return Ok(cardTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the GUID corresponding to the Id of the authenticated user.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>GUID (string)</returns>
|
|
||||||
string GetUserName()
|
|
||||||
{
|
|
||||||
return HttpContext.User.FindFirst("sub").Value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services
|
||||||
|
{
|
||||||
|
public interface IIdentityService
|
||||||
|
{
|
||||||
|
string GetUserIdentity();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services
|
||||||
|
{
|
||||||
|
public class IdentityService : IIdentityService
|
||||||
|
{
|
||||||
|
private IHttpContextAccessor _context;
|
||||||
|
|
||||||
|
public IdentityService(IHttpContextAccessor context)
|
||||||
|
{
|
||||||
|
if (context == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(context));
|
||||||
|
}
|
||||||
|
|
||||||
|
_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetUserIdentity()
|
||||||
|
{
|
||||||
|
return _context.HttpContext.User.FindFirst("sub").Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,12 @@
|
|||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API
|
namespace Microsoft.eShopOnContainers.Services.Ordering.API
|
||||||
{
|
{
|
||||||
|
using AspNetCore.Http;
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using Autofac.Extensions.DependencyInjection;
|
using Autofac.Extensions.DependencyInjection;
|
||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
using Infrastructure.AutofacModules;
|
using Infrastructure.AutofacModules;
|
||||||
using Infrastructure.Filters;
|
using Infrastructure.Filters;
|
||||||
|
using Infrastructure.Services;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@ -74,7 +76,10 @@
|
|||||||
.AllowCredentials());
|
.AllowCredentials());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add application services.
|
||||||
|
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||||
services.AddSingleton<IConfiguration>(this.Configuration);
|
services.AddSingleton<IConfiguration>(this.Configuration);
|
||||||
|
services.AddTransient<IIdentityService,IdentityService>();
|
||||||
|
|
||||||
services.AddOptions();
|
services.AddOptions();
|
||||||
|
|
||||||
|
@ -7,9 +7,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Dynamic;
|
using System.Dynamic;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
public class OrderQueries
|
public class OrderQueries
|
||||||
:IOrderQueries
|
: IOrderQueries
|
||||||
{
|
{
|
||||||
private string _connectionString = string.Empty;
|
private string _connectionString = string.Empty;
|
||||||
|
|
||||||
@ -97,5 +98,31 @@
|
|||||||
|
|
||||||
return order;
|
return order;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO/CCE: try to use this method instead actual.
|
||||||
|
//private object MapOrderItems(dynamic result)
|
||||||
|
//{
|
||||||
|
// IEnumerable<dynamic> items = (result as System.Collections.IEnumerable).Cast<dynamic>();
|
||||||
|
// var order = new
|
||||||
|
// {
|
||||||
|
// ordernumber = result[0].ordernumbe,
|
||||||
|
// date = result[0].date,
|
||||||
|
// status = result[0].status,
|
||||||
|
// street = result[0].street,
|
||||||
|
// city = result[0].city,
|
||||||
|
// zipcode = result[0].zipcode,
|
||||||
|
// country = result[0].country,
|
||||||
|
// total = items.Select(r => (int)r.units * (int)r.unitprice).Sum(),
|
||||||
|
// orderItems = items.Select(r => new
|
||||||
|
// {
|
||||||
|
// productname = r.productname,
|
||||||
|
// units = r.units,
|
||||||
|
// unitprice = r.unitprice,
|
||||||
|
// pictureurl = r.pictureurl
|
||||||
|
// })
|
||||||
|
// };
|
||||||
|
|
||||||
|
// return order;
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,9 +33,6 @@ namespace Microsoft.eShopOnContainers.WebMVC
|
|||||||
// builder.AddUserSecrets();
|
// builder.AddUserSecrets();
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//builder.AddJsonFile("appsettings.override.json");
|
|
||||||
//builder.AddEnvironmentVariables();
|
|
||||||
|
|
||||||
Configuration = builder.Build();
|
Configuration = builder.Build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +48,7 @@ namespace Microsoft.eShopOnContainers.WebMVC
|
|||||||
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||||
|
|
||||||
services.AddTransient<ICatalogService, CatalogService>();
|
services.AddTransient<ICatalogService, CatalogService>();
|
||||||
services.AddSingleton<IOrderingService, OrderingService>(); //CCE: Once services are integrated, a singleton is not needed we can left transient.
|
services.AddTransient<IOrderingService, OrderingService>();
|
||||||
services.AddTransient<IBasketService, BasketService>();
|
services.AddTransient<IBasketService, BasketService>();
|
||||||
services.AddTransient<IIdentityParser<ApplicationUser>, IdentityParser>();
|
services.AddTransient<IIdentityParser<ApplicationUser>, IdentityParser>();
|
||||||
}
|
}
|
||||||
@ -86,9 +83,6 @@ namespace Microsoft.eShopOnContainers.WebMVC
|
|||||||
var callBackUrl = Configuration.GetValue<string>("CallBackUrl");
|
var callBackUrl = Configuration.GetValue<string>("CallBackUrl");
|
||||||
var log = loggerFactory.CreateLogger("identity");
|
var log = loggerFactory.CreateLogger("identity");
|
||||||
|
|
||||||
log.LogDebug(identityUrl.ToString());
|
|
||||||
log.LogDebug(callBackUrl.ToString());
|
|
||||||
|
|
||||||
var oidcOptions = new OpenIdConnectOptions
|
var oidcOptions = new OpenIdConnectOptions
|
||||||
{
|
{
|
||||||
AuthenticationScheme = "oidc",
|
AuthenticationScheme = "oidc",
|
||||||
|
34
test/Services/UnitTest/Catalog/CatalogControllertest.cs
Normal file
34
test/Services/UnitTest/Catalog/CatalogControllertest.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.eShopOnContainers.Services.Catalog.API.Controllers;
|
||||||
|
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
|
||||||
|
using Microsoft.eShopOnContainers.Services.Catalog.API.Model;
|
||||||
|
using Moq;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace UnitTest.Catalog
|
||||||
|
{
|
||||||
|
public class CatalogControllerTest
|
||||||
|
{
|
||||||
|
private readonly Mock<CatalogContext> _mockContext;
|
||||||
|
private readonly Mock<IQueryable<CatalogItem>> _mockItems;
|
||||||
|
public CatalogControllerTest()
|
||||||
|
{
|
||||||
|
_mockContext = new Mock<CatalogContext>();
|
||||||
|
_mockItems = new Mock<IQueryable<CatalogItem>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Items_ReturnsOKObject_WhenItemsFound()
|
||||||
|
{
|
||||||
|
//CCE: TODO
|
||||||
|
Assert.True(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,92 @@
|
|||||||
|
using MediatR;
|
||||||
|
using Microsoft.eShopOnContainers.Services.Ordering.Api.Application.Commands;
|
||||||
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain;
|
||||||
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Repositories;
|
||||||
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork;
|
||||||
|
using Moq;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace UnitTest.Ordering.Application
|
||||||
|
{
|
||||||
|
public class NewOrderRequestHandlerTest
|
||||||
|
{
|
||||||
|
private readonly Mock<IBuyerRepository> _buyerRepositoryMock;
|
||||||
|
private readonly Mock<IOrderRepository> _orderRepositoryMock;
|
||||||
|
|
||||||
|
public NewOrderRequestHandlerTest()
|
||||||
|
{
|
||||||
|
//Mocks;
|
||||||
|
_buyerRepositoryMock = new Mock<IBuyerRepository>();
|
||||||
|
_orderRepositoryMock = new Mock<IOrderRepository>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Handle_ReturnsTrue_WhenOrderIsPersistedSuccesfully()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.FindAsync(FakeOrderRequestWithBuyer().Buyer))
|
||||||
|
.Returns(Task.FromResult<Buyer>(FakeBuyer()));
|
||||||
|
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.UnitOfWork.SaveChangesAsync(default(CancellationToken)))
|
||||||
|
.Returns(Task.FromResult(1));
|
||||||
|
|
||||||
|
_orderRepositoryMock.Setup(or => or.Add(FakeOrder())).Returns(FakeOrder());
|
||||||
|
_orderRepositoryMock.Setup(or => or.UnitOfWork.SaveChangesAsync(default(CancellationToken))).Returns(Task.FromResult(1));
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var handler = new NewOrderRequestHandler(_buyerRepositoryMock.Object, _orderRepositoryMock.Object);
|
||||||
|
var result = await handler.Handle(FakeOrderRequestWithBuyer());
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
Assert.True(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Handle_ReturnsFalse_WhenOrderIsNotPersisted()
|
||||||
|
{
|
||||||
|
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.FindAsync(FakeOrderRequestWithBuyer().Buyer))
|
||||||
|
.Returns(Task.FromResult<Buyer>(FakeBuyer()));
|
||||||
|
_buyerRepositoryMock.Setup(buyerRepo => buyerRepo.UnitOfWork.SaveChangesAsync(default(CancellationToken)))
|
||||||
|
.Returns(Task.FromResult(1));
|
||||||
|
|
||||||
|
_orderRepositoryMock.Setup(or => or.Add(FakeOrder())).Returns(FakeOrder());
|
||||||
|
_orderRepositoryMock.Setup(or => or.UnitOfWork.SaveChangesAsync(default(CancellationToken))).Returns(Task.FromResult(0));
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var handler = new NewOrderRequestHandler(_buyerRepositoryMock.Object, _orderRepositoryMock.Object);
|
||||||
|
var result = await handler.Handle(FakeOrderRequestWithBuyer());
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
Assert.False(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Buyer FakeBuyer()
|
||||||
|
{
|
||||||
|
return new Buyer(Guid.NewGuid().ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Order FakeOrder()
|
||||||
|
{
|
||||||
|
return new Order(1, 1)
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private NewOrderRequest FakeOrderRequestWithBuyer()
|
||||||
|
{
|
||||||
|
return new NewOrderRequest
|
||||||
|
{
|
||||||
|
Buyer = "1234",
|
||||||
|
CardNumber = "1234",
|
||||||
|
CardExpiration = DateTime.Now.AddYears(1),
|
||||||
|
CardSecurityNumber = "123",
|
||||||
|
CardHolderName = "XXX"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,152 @@
|
|||||||
|
using System;
|
||||||
|
using Xunit;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Moq;
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.eShopOnContainers.Services.Ordering.API.Controllers;
|
||||||
|
using Microsoft.eShopOnContainers.Services.Ordering.Api.Application.Commands;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services;
|
||||||
|
using Microsoft.eShopOnContainers.Services.Ordering.Api.Application.Queries;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace UnitTest.Ordering.Controllers
|
||||||
|
{
|
||||||
|
public class OrderControllerTest
|
||||||
|
{
|
||||||
|
private readonly Mock<IMediator> _mediatorMock;
|
||||||
|
private readonly Mock<IIdentityService> _identityMock;
|
||||||
|
private readonly Mock<IOrderQueries> _queriesMock;
|
||||||
|
|
||||||
|
public OrderControllerTest()
|
||||||
|
{
|
||||||
|
//Mocks;
|
||||||
|
_mediatorMock = new Mock<IMediator>();
|
||||||
|
_identityMock = new Mock<IIdentityService>();
|
||||||
|
_queriesMock = new Mock<IOrderQueries>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task AddOrder_ReturnsBadRequestResult_WhenPersitenceOperationFails()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var orderRequest = new object() as IAsyncRequest<bool>;
|
||||||
|
|
||||||
|
_mediatorMock.Setup(mediator => mediator.SendAsync(OrderFakeNotExpired()))
|
||||||
|
.Returns(Task.FromResult(false));
|
||||||
|
|
||||||
|
_identityMock.Setup(identity => identity.GetUserIdentity())
|
||||||
|
.Returns(Guid.NewGuid().ToString());
|
||||||
|
|
||||||
|
var controller = new OrdersController(_mediatorMock.Object, _queriesMock.Object, _identityMock.Object);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var badRequestResult = await controller.AddOrder(OrderFakeNotExpired());
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.IsType<BadRequestResult>(badRequestResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task AddOrder_ReturnsOK_WhenPersistenceOperationSucceed()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
_mediatorMock.Setup(mediator => mediator.SendAsync(OrderFakeNotExpired()))
|
||||||
|
.Returns(Task.FromResult(true));
|
||||||
|
|
||||||
|
_identityMock.Setup(identity => identity.GetUserIdentity())
|
||||||
|
.Returns(Guid.NewGuid().ToString());
|
||||||
|
|
||||||
|
var controller = new OrdersController(_mediatorMock.Object, _queriesMock.Object, _identityMock.Object);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var badRequestResult = await controller.AddOrder(OrderFakeNotExpired());
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.IsType<BadRequestResult>(badRequestResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetOrder_ReturnsNotFound_WhenItemNotFound()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
_queriesMock.Setup(queries => queries.GetOrder(1))
|
||||||
|
.Throws(new KeyNotFoundException());
|
||||||
|
|
||||||
|
var controller = new OrdersController(_mediatorMock.Object, _queriesMock.Object, _identityMock.Object);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var notFoundResult = await controller.GetOrder(1);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.IsType<NotFoundResult>(notFoundResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetOrder_ReturnsOkObjecResult_WheItemFound()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
_queriesMock.Setup(queries => queries.GetOrder(1))
|
||||||
|
.Returns(Task.FromResult(new object()));
|
||||||
|
|
||||||
|
var controller = new OrdersController(_mediatorMock.Object, _queriesMock.Object, _identityMock.Object);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var OkObjectResult = await controller.GetOrder(1);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.IsType<OkObjectResult>(OkObjectResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetOrders_ReturnsOkObjectResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
_queriesMock.Setup(queries => queries.GetOrders())
|
||||||
|
.Returns(Task.FromResult(new object()));
|
||||||
|
|
||||||
|
var controller = new OrdersController(_mediatorMock.Object, _queriesMock.Object, _identityMock.Object);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var OkObjectResult = await controller.GetOrders();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.IsType<OkObjectResult>(OkObjectResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetCardTypes()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
_queriesMock.Setup(queries => queries.GetCardTypes())
|
||||||
|
.Returns(Task.FromResult(new object()));
|
||||||
|
|
||||||
|
var controller = new OrdersController(_mediatorMock.Object, _queriesMock.Object, _identityMock.Object);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var OkObjectResult = await controller.GetCardTypes();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.IsType<OkObjectResult>(OkObjectResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Fakes
|
||||||
|
private NewOrderRequest OrderFakeNotExpired()
|
||||||
|
{
|
||||||
|
return new NewOrderRequest()
|
||||||
|
{
|
||||||
|
CardTypeId = 1,
|
||||||
|
CardExpiration = DateTime.Now.AddYears(1)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private NewOrderRequest OrderFakeExpired()
|
||||||
|
{
|
||||||
|
return new NewOrderRequest()
|
||||||
|
{
|
||||||
|
CardTypeId = 1,
|
||||||
|
CardExpiration = DateTime.Now.AddYears(-1)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
test/Services/UnitTest/Properties/AssemblyInfo.cs
Normal file
19
test/Services/UnitTest/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// General Information about an assembly is controlled through the following
|
||||||
|
// set of attributes. Change these attribute values to modify the information
|
||||||
|
// associated with an assembly.
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("UnitTest")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
|
||||||
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
|
// to COM components. If you need to access a type in this assembly from
|
||||||
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
|
[assembly: Guid("7796f5d8-31fc-45a4-b673-19de5ba194cf")]
|
22
test/Services/UnitTest/UnitTest.xproj
Normal file
22
test/Services/UnitTest/UnitTest.xproj
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||||
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<ProjectGuid>7796f5d8-31fc-45a4-b673-19de5ba194cf</ProjectGuid>
|
||||||
|
<RootNamespace>UnitTest</RootNamespace>
|
||||||
|
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
|
||||||
|
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
|
||||||
|
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||||
|
</Project>
|
24
test/Services/UnitTest/project.json
Normal file
24
test/Services/UnitTest/project.json
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0-*",
|
||||||
|
|
||||||
|
"dependencies": {
|
||||||
|
"MediatR": "2.1.0",
|
||||||
|
"Moq": "4.6.38-alpha",
|
||||||
|
"Microsoft.NETCore.App": "1.1.0",
|
||||||
|
"xunit": "2.2.0-beta4-build3444",
|
||||||
|
"Ordering.API": "1.0.0-*",
|
||||||
|
"Catalog.API": "1.0.0-*",
|
||||||
|
"Microsoft.AspNetCore.TestHost": "1.1.0",
|
||||||
|
"dotnet-test-xunit": "2.2.0-preview2-build1029"
|
||||||
|
},
|
||||||
|
"testRunner": "xunit",
|
||||||
|
"runtimes": {
|
||||||
|
"win10-x64": {}
|
||||||
|
},
|
||||||
|
"frameworks": {
|
||||||
|
"netcoreapp1.0": {
|
||||||
|
"dependencies": {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using Xunit;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Moq;
|
||||||
|
using MediatR;
|
||||||
|
|
||||||
|
namespace UnitTests
|
||||||
|
{
|
||||||
|
public class OrderControllerTest
|
||||||
|
{
|
||||||
|
private readonly Mock<IMediator> _mock;
|
||||||
|
|
||||||
|
public OrderControllerTest()
|
||||||
|
{
|
||||||
|
//config mock;
|
||||||
|
_mock = new Mock<IMediator>();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task AddOrder_ReturnsBadRequestResult_WhenPersitenceOperationFails()
|
||||||
|
{
|
||||||
|
//Add order:
|
||||||
|
var orderRequest = new object() as IAsyncRequest<bool>;
|
||||||
|
_mock.Setup(mediator => mediator.SendAsync(orderRequest))
|
||||||
|
.Returns(Task.FromResult(false));
|
||||||
|
|
||||||
|
// Arrange
|
||||||
|
var controller = new OrdersController(mockRepo.Object);
|
||||||
|
controller.ModelState.AddModelError("SessionName", "Required");
|
||||||
|
var newSession = new HomeController.NewSessionModel();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await controller.Index(newSession);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var badRequestResult = Assert.IsType<BadRequestObjectResult>(result);
|
||||||
|
Assert.IsType<SerializableError>(badRequestResult.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Implement Fake method for mock.
|
||||||
|
private MediatorMockForAddOrder()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// General Information about an assembly is controlled through the following
|
||||||
|
// set of attributes. Change these attribute values to modify the information
|
||||||
|
// associated with an assembly.
|
||||||
|
[assembly: AssemblyTitle("UnitTests")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("UnitTests")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
|
// to COM components. If you need to access a type in this assembly from
|
||||||
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
|
[assembly: Guid("ecbb8dc1-22ea-42d2-a45a-4ae800c73356")]
|
||||||
|
|
||||||
|
// Version information for an assembly consists of the following four values:
|
||||||
|
//
|
||||||
|
// Major Version
|
||||||
|
// Minor Version
|
||||||
|
// Build Number
|
||||||
|
// Revision
|
||||||
|
//
|
||||||
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
|
// by using the '*' as shown below:
|
||||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
117
test/Services/UnitTests__/UnitTests/UnitTests.csproj
Normal file
117
test/Services/UnitTests__/UnitTests/UnitTests.csproj
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{ECBB8DC1-22EA-42D2-A45A-4AE800C73356}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>UnitTests</RootNamespace>
|
||||||
|
<AssemblyName>UnitTests</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||||
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||||
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||||
|
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
|
||||||
|
<IsCodedUITest>False</IsCodedUITest>
|
||||||
|
<TestProjectType>UnitTest</TestProjectType>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="Castle.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\..\..\..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="MediatR, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\..\..\..\packages\MediatR.2.1.0\lib\net45\MediatR.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Moq, Version=4.6.38.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\..\..\..\packages\Moq.4.6.38-alpha\lib\net45\Moq.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\..\..\..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="xunit.assert, Version=2.2.0.3444, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\..\..\..\packages\xunit.assert.2.2.0-beta4-build3444\lib\netstandard1.0\xunit.assert.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="xunit.core, Version=2.2.0.3444, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\..\..\..\packages\xunit.extensibility.core.2.2.0-beta4-build3444\lib\net45\xunit.core.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="xunit.execution.desktop, Version=2.2.0.3444, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\..\..\..\packages\xunit.extensibility.execution.2.2.0-beta4-build3444\lib\net45\xunit.execution.desktop.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
<Choose>
|
||||||
|
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
||||||
|
</ItemGroup>
|
||||||
|
</When>
|
||||||
|
<Otherwise>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Otherwise>
|
||||||
|
</Choose>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Ordering\OrderControllerTest.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Catalog\" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="packages.config" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Choose>
|
||||||
|
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
|
<Private>False</Private>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
|
<Private>False</Private>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
|
<Private>False</Private>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
|
<Private>False</Private>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
</When>
|
||||||
|
</Choose>
|
||||||
|
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
12
test/Services/UnitTests__/UnitTests/packages.config
Normal file
12
test/Services/UnitTests__/UnitTests/packages.config
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<packages>
|
||||||
|
<package id="Castle.Core" version="3.3.3" targetFramework="net452" />
|
||||||
|
<package id="MediatR" version="2.1.0" targetFramework="net452" />
|
||||||
|
<package id="Moq" version="4.6.38-alpha" targetFramework="net452" />
|
||||||
|
<package id="xunit" version="2.2.0-beta4-build3444" targetFramework="net452" />
|
||||||
|
<package id="xunit.abstractions" version="2.0.1" targetFramework="net452" />
|
||||||
|
<package id="xunit.assert" version="2.2.0-beta4-build3444" targetFramework="net452" />
|
||||||
|
<package id="xunit.core" version="2.2.0-beta4-build3444" targetFramework="net452" />
|
||||||
|
<package id="xunit.extensibility.core" version="2.2.0-beta4-build3444" targetFramework="net452" />
|
||||||
|
<package id="xunit.extensibility.execution" version="2.2.0-beta4-build3444" targetFramework="net452" />
|
||||||
|
</packages>
|
Loading…
x
Reference in New Issue
Block a user