Browse Source

Merge branch 'master' of https://github.com/dotnet/eShopOnContainers

pull/89/head
etomas 8 years ago
parent
commit
d01a548bbb
15 changed files with 279 additions and 34 deletions
  1. +51
    -0
      eShopOnContainers-ServicesAndWebApps.sln
  2. +3
    -3
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/BasketViewModel.cs
  3. +2
    -2
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/CheckoutViewModel.cs
  4. +6
    -6
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/LoginViewModel.cs
  5. +3
    -3
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/MainViewModel.cs
  6. +5
    -5
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/ProfileViewModel.cs
  7. +2
    -2
      src/Services/Identity/Identity.API/Configuration/Config.cs
  8. +0
    -8
      test/Services/FunctionalTests/Class1.cs
  9. +20
    -1
      test/Services/FunctionalTests/FunctionalTests.csproj
  10. +26
    -0
      test/Services/FunctionalTests/Middleware/AutoAuthorizeMiddleware.cs
  11. +73
    -0
      test/Services/FunctionalTests/Services/Ordering/OrderingScenarios.cs
  12. +36
    -0
      test/Services/FunctionalTests/Services/Ordering/OrderingScenariosBase.cs
  13. +29
    -0
      test/Services/FunctionalTests/Services/Ordering/OrderingTestsStartup.cs
  14. +5
    -0
      test/Services/FunctionalTests/settings.json
  15. +18
    -4
      test/Services/IntegrationTests/Services/Basket/RedisBasketRepositoryTests.cs

+ 51
- 0
eShopOnContainers-ServicesAndWebApps.sln View File

@ -48,6 +48,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebSPA", "src\Web\WebSPA\We
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntegrationTests", "test\Services\IntegrationTests\IntegrationTests.csproj", "{5B810E3D-112E-4857-B197-F09D2FD41E27}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunctionalTests", "test\Services\FunctionalTests\FunctionalTests.csproj", "{CFE2FACB-4538-4B99-8A10-306F3882952D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Ad-Hoc|Any CPU = Ad-Hoc|Any CPU
@ -494,6 +496,54 @@ Global
{5B810E3D-112E-4857-B197-F09D2FD41E27}.Release|x64.Build.0 = Release|Any CPU
{5B810E3D-112E-4857-B197-F09D2FD41E27}.Release|x86.ActiveCfg = Release|Any CPU
{5B810E3D-112E-4857-B197-F09D2FD41E27}.Release|x86.Build.0 = Release|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|x64.Build.0 = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|x86.Build.0 = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|Any CPU.Build.0 = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|ARM.ActiveCfg = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|ARM.Build.0 = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|iPhone.Build.0 = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|x64.ActiveCfg = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|x64.Build.0 = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|x86.ActiveCfg = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|x86.Build.0 = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|ARM.ActiveCfg = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|ARM.Build.0 = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|iPhone.Build.0 = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|x64.ActiveCfg = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|x64.Build.0 = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|x86.ActiveCfg = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|x86.Build.0 = Debug|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|Any CPU.Build.0 = Release|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|ARM.ActiveCfg = Release|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|ARM.Build.0 = Release|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|iPhone.ActiveCfg = Release|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|iPhone.Build.0 = Release|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|x64.ActiveCfg = Release|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|x64.Build.0 = Release|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|x86.ActiveCfg = Release|Any CPU
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -516,5 +566,6 @@ Global
{A579E108-5445-403D-A407-339AC4D1611B} = {24CD3B53-141E-4A07-9B0D-796641E1CF78}
{F16E3C6A-1C94-4EAB-BE91-099618060B68} = {E279BF0F-7F66-4F3A-A3AB-2CDA66C1CD04}
{5B810E3D-112E-4857-B197-F09D2FD41E27} = {EF0337F2-ED00-4643-89FD-EE10863F1870}
{CFE2FACB-4538-4B99-8A10-306F3882952D} = {EF0337F2-ED00-4643-89FD-EE10863F1870}
EndGlobalSection
EndGlobal

+ 3
- 3
src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/BasketViewModel.cs View File

@ -63,7 +63,7 @@ namespace eShopOnContainers.Core.ViewModels
public ICommand AddCommand => new Command<BasketItem>(AddItem);
public ICommand CheckoutCommand => new Command(Checkout);
public ICommand CheckoutCommand => new Command(async () => await CheckoutAsync());
public override async Task InitializeAsync(object navigationData)
{
@ -151,11 +151,11 @@ namespace eShopOnContainers.Core.ViewModels
}, authToken);
}
private void Checkout()
private async Task CheckoutAsync()
{
if (BasketItems.Any())
{
NavigationService.NavigateToAsync<CheckoutViewModel>(BasketItems);
await NavigationService.NavigateToAsync<CheckoutViewModel>(BasketItems);
}
}
}

+ 2
- 2
src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/CheckoutViewModel.cs View File

@ -66,7 +66,7 @@ namespace eShopOnContainers.Core.ViewModels
}
}
public ICommand CheckoutCommand => new Command(Checkout);
public ICommand CheckoutCommand => new Command(async () => await CheckoutAsync());
public override async Task InitializeAsync(object navigationData)
{
@ -125,7 +125,7 @@ namespace eShopOnContainers.Core.ViewModels
}
}
private async void Checkout()
private async Task CheckoutAsync()
{
try
{


+ 6
- 6
src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/LoginViewModel.cs View File

@ -121,15 +121,15 @@ namespace eShopOnContainers.Core.ViewModels
}
}
public ICommand MockSignInCommand => new Command(MockSignInAsync);
public ICommand MockSignInCommand => new Command(async () => await MockSignInAsync());
public ICommand SignInCommand => new Command(async () => await SignInAsync());
public ICommand RegisterCommand => new Command(Register);
public ICommand NavigateCommand => new Command<string>(NavigateAsync);
public ICommand NavigateCommand => new Command<string>(async (url) => await NavigateAsync(url));
public ICommand SettingsCommand => new Command(SettingsAsync);
public ICommand SettingsCommand => new Command(async () => await SettingsAsync());
public override Task InitializeAsync(object navigationData)
{
@ -146,7 +146,7 @@ namespace eShopOnContainers.Core.ViewModels
return base.InitializeAsync(navigationData);
}
private async void MockSignInAsync()
private async Task MockSignInAsync()
{
IsBusy = true;
IsValid = true;
@ -219,7 +219,7 @@ namespace eShopOnContainers.Core.ViewModels
}
}
private async void NavigateAsync(string url)
private async Task NavigateAsync(string url)
{
if (url.Equals(GlobalSetting.Instance.LogoutCallback))
{
@ -246,7 +246,7 @@ namespace eShopOnContainers.Core.ViewModels
}
}
private async void SettingsAsync()
private async Task SettingsAsync()
{
await NavigationService.NavigateToAsync<SettingsViewModel>();
}


+ 3
- 3
src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/MainViewModel.cs View File

@ -9,7 +9,7 @@ namespace eShopOnContainers.Core.ViewModels
{
public class MainViewModel : ViewModelBase
{
public ICommand SettingsCommand => new Command(Settings);
public ICommand SettingsCommand => new Command(async () => await SettingsAsync());
public override Task InitializeAsync(object navigationData)
{
@ -25,9 +25,9 @@ namespace eShopOnContainers.Core.ViewModels
return base.InitializeAsync(navigationData);
}
private void Settings()
private async Task SettingsAsync()
{
NavigationService.NavigateToAsync<SettingsViewModel>();
await NavigationService.NavigateToAsync<SettingsViewModel>();
}
}
}

+ 5
- 5
src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/ProfileViewModel.cs View File

@ -32,9 +32,9 @@ namespace eShopOnContainers.Core.ViewModels
}
}
public ICommand LogoutCommand => new Command(LogoutAsync);
public ICommand LogoutCommand => new Command(async () => await LogoutAsync());
public ICommand OrderDetailCommand => new Command<Order>(OrderDetail);
public ICommand OrderDetailCommand => new Command<Order>(async (order) => await OrderDetailAsync(order));
public override async Task InitializeAsync(object navigationData)
{
@ -48,7 +48,7 @@ namespace eShopOnContainers.Core.ViewModels
IsBusy = false;
}
private async void LogoutAsync()
private async Task LogoutAsync()
{
IsBusy = true;
@ -59,9 +59,9 @@ namespace eShopOnContainers.Core.ViewModels
IsBusy = false;
}
private void OrderDetail(Order order)
private async Task OrderDetailAsync(Order order)
{
NavigationService.NavigateToAsync<OrderDetailViewModel>(order);
await NavigationService.NavigateToAsync<OrderDetailViewModel>(order);
}
}
}

+ 2
- 2
src/Services/Identity/Identity.API/Configuration/Config.cs View File

@ -91,8 +91,8 @@ namespace Identity.API.Configuration
},
PostLogoutRedirectUris = new List<string>
{
$"{clientsUrl["Mvc"]}/",
"http://localhost:5100/"
$"{clientsUrl["Mvc"]}/signout-callback-oidc",
"http://localhost:5100/signout-callback-oidc"
},
AllowedScopes = new List<string>
{


+ 0
- 8
test/Services/FunctionalTests/Class1.cs View File

@ -1,8 +0,0 @@
using System;
namespace FunctionalTests
{
public class Class1
{
}
}

+ 20
- 1
test/Services/FunctionalTests/FunctionalTests.csproj View File

@ -1,7 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170106-08" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="1.1.0" />
<PackageReference Include="xunit" Version="2.2.0-beta5-build3474" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta5-build1225" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Services\Ordering\Ordering.API\Ordering.API.csproj" />
<ProjectReference Include="..\..\..\src\Web\WebMVC\WebMVC.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

+ 26
- 0
test/Services/FunctionalTests/Middleware/AutoAuthorizeMiddleware.cs View File

@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
namespace FunctionalTests.Middleware
{
class AutoAuthorizeMiddleware
{
private readonly RequestDelegate _next;
public AutoAuthorizeMiddleware(RequestDelegate rd)
{
_next = rd;
}
public async Task Invoke(HttpContext httpContext)
{
var identity = new ClaimsIdentity();
identity.AddClaim(new Claim("sub", "1234"));
httpContext.User.AddIdentity(identity);
await _next.Invoke(httpContext);
}
}
}

+ 73
- 0
test/Services/FunctionalTests/Services/Ordering/OrderingScenarios.cs View File

@ -0,0 +1,73 @@
using Microsoft.AspNetCore.TestHost;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.eShopOnContainers.WebMVC.ViewModels;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using static Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands.CreateOrderCommand;
namespace FunctionalTests.Services.Ordering
{
public class OrderingScenarios : OrderingScenariosBase
{
[Fact]
public async Task Create_order_and_return_the_order_by_id()
{
using (var server = CreateServer())
{
var client = server.CreateClient();
//Arrange
await client.PostAsync(Post.AddNewOrder, new StringContent(BuildOrder(), UTF8Encoding.UTF8, "application/json"));
var ordersResponse = await client.GetAsync(Get.Orders);
var responseBody = await ordersResponse.Content.ReadAsStringAsync();
dynamic orders = JsonConvert.DeserializeObject(responseBody);
string orderId = orders[0].ordernumber;
//Act
var order= await client.GetAsync(Get.OrderBy(int.Parse(orderId)));
var orderBody = await order.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<Order>(orderBody);
//Assert
Assert.Equal(orderId, result.OrderNumber);
Assert.Equal("inprocess", result.Status);
Assert.Equal(1, result.OrderItems.Count);
Assert.Equal(10, result.OrderItems[0].UnitPrice);
}
}
string BuildOrder()
{
var order = new CreateOrderCommand(
cardExpiration: DateTime.UtcNow.AddYears(1),
cardNumber: "5145-555-5555",
cardHolderName: "Jhon Senna",
cardSecurityNumber: "232",
cardTypeId: 1,
city: "Redmon",
country: "USA",
state: "WA",
street: "One way",
zipcode: "zipcode"
);
order.AddOrderItem(new OrderItemDTO()
{
ProductId = 1,
Discount = 10M,
UnitPrice = 10,
Units = 1,
ProductName = "Some name"
});
return JsonConvert.SerializeObject(order);
}
}
}

+ 36
- 0
test/Services/FunctionalTests/Services/Ordering/OrderingScenariosBase.cs View File

@ -0,0 +1,36 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace FunctionalTests.Services.Ordering
{
public class OrderingScenariosBase
{
public TestServer CreateServer()
{
var webHostBuilder = new WebHostBuilder();
webHostBuilder.UseContentRoot(Directory.GetCurrentDirectory());
webHostBuilder.UseStartup<OrderingTestsStartup>();
return new TestServer(webHostBuilder);
}
public static class Get
{
public static string Orders = "api/v1/orders";
public static string OrderBy(int id)
{
return $"api/v1/orders/{id}";
}
}
public static class Post
{
public static string AddNewOrder = "api/v1/orders/new";
}
}
}

+ 29
- 0
test/Services/FunctionalTests/Services/Ordering/OrderingTestsStartup.cs View File

@ -0,0 +1,29 @@
using FunctionalTests.Middleware;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.eShopOnContainers.Services.Ordering.API;
using System;
using System.Collections.Generic;
using System.Text;
namespace FunctionalTests.Services.Ordering
{
public class OrderingTestsStartup : Startup
{
public OrderingTestsStartup(IHostingEnvironment env) : base(env)
{
}
protected override void ConfigureAuth(IApplicationBuilder app)
{
if (Configuration["isTest"] == bool.TrueString.ToLowerInvariant())
{
app.UseMiddleware<AutoAuthorizeMiddleware>();
}
else
{
base.ConfigureAuth(app);
}
}
}
}

+ 5
- 0
test/Services/FunctionalTests/settings.json View File

@ -0,0 +1,5 @@
{
"ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;",
"IdentityUrl": "http://localhost:5105",
"isTest": "true"
}

+ 18
- 4
test/Services/IntegrationTests/Services/Basket/RedisBasketRepositoryTests.cs View File

@ -35,10 +35,24 @@ namespace IntegrationTests.Services.Basket
Assert.Equal(1, basket.Items.Count);
}
//[Fact]
//public async Task GetBasket_return_existing_basket()
//{
//}
[Fact]
public async Task Delete_Basket_return_null()
{
var redisBasketRepository = BuildBasketRepository();
var basket = await redisBasketRepository.UpdateBasket(new CustomerBasket("customerId")
{
BuyerId = "buyerId",
Items = BuildBasketItems()
});
var deleteResult = await redisBasketRepository.DeleteBasket("buyerId");
var result = await redisBasketRepository.GetBasket(basket.BuyerId);
Assert.True(deleteResult);
Assert.Null(result);
}
RedisBasketRepository BuildBasketRepository()
{


Loading…
Cancel
Save