Skip to content

Commit a7f9d2c

Browse files
David BritchDavid Britch
authored andcommitted
Merge branch 'master' into xamarin
2 parents 8b3bd3b + 74ab90c commit a7f9d2c

9 files changed

Lines changed: 258 additions & 13 deletions

File tree

eShopOnContainers-ServicesAndWebApps.sln

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebSPA", "src\Web\WebSPA\We
4848
EndProject
4949
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntegrationTests", "test\Services\IntegrationTests\IntegrationTests.csproj", "{5B810E3D-112E-4857-B197-F09D2FD41E27}"
5050
EndProject
51+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunctionalTests", "test\Services\FunctionalTests\FunctionalTests.csproj", "{CFE2FACB-4538-4B99-8A10-306F3882952D}"
52+
EndProject
5153
Global
5254
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5355
Ad-Hoc|Any CPU = Ad-Hoc|Any CPU
@@ -494,6 +496,54 @@ Global
494496
{5B810E3D-112E-4857-B197-F09D2FD41E27}.Release|x64.Build.0 = Release|Any CPU
495497
{5B810E3D-112E-4857-B197-F09D2FD41E27}.Release|x86.ActiveCfg = Release|Any CPU
496498
{5B810E3D-112E-4857-B197-F09D2FD41E27}.Release|x86.Build.0 = Release|Any CPU
499+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
500+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
501+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU
502+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU
503+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
504+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
505+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
506+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
507+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU
508+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|x64.Build.0 = Debug|Any CPU
509+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU
510+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Ad-Hoc|x86.Build.0 = Debug|Any CPU
511+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
512+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|Any CPU.Build.0 = Debug|Any CPU
513+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|ARM.ActiveCfg = Debug|Any CPU
514+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|ARM.Build.0 = Debug|Any CPU
515+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
516+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|iPhone.Build.0 = Debug|Any CPU
517+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
518+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
519+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|x64.ActiveCfg = Debug|Any CPU
520+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|x64.Build.0 = Debug|Any CPU
521+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|x86.ActiveCfg = Debug|Any CPU
522+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.AppStore|x86.Build.0 = Debug|Any CPU
523+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
524+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|Any CPU.Build.0 = Debug|Any CPU
525+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|ARM.ActiveCfg = Debug|Any CPU
526+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|ARM.Build.0 = Debug|Any CPU
527+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|iPhone.ActiveCfg = Debug|Any CPU
528+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|iPhone.Build.0 = Debug|Any CPU
529+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
530+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
531+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|x64.ActiveCfg = Debug|Any CPU
532+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|x64.Build.0 = Debug|Any CPU
533+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|x86.ActiveCfg = Debug|Any CPU
534+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Debug|x86.Build.0 = Debug|Any CPU
535+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|Any CPU.ActiveCfg = Release|Any CPU
536+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|Any CPU.Build.0 = Release|Any CPU
537+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|ARM.ActiveCfg = Release|Any CPU
538+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|ARM.Build.0 = Release|Any CPU
539+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|iPhone.ActiveCfg = Release|Any CPU
540+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|iPhone.Build.0 = Release|Any CPU
541+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
542+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
543+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|x64.ActiveCfg = Release|Any CPU
544+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|x64.Build.0 = Release|Any CPU
545+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|x86.ActiveCfg = Release|Any CPU
546+
{CFE2FACB-4538-4B99-8A10-306F3882952D}.Release|x86.Build.0 = Release|Any CPU
497547
EndGlobalSection
498548
GlobalSection(SolutionProperties) = preSolution
499549
HideSolutionNode = FALSE
@@ -516,5 +566,6 @@ Global
516566
{A579E108-5445-403D-A407-339AC4D1611B} = {24CD3B53-141E-4A07-9B0D-796641E1CF78}
517567
{F16E3C6A-1C94-4EAB-BE91-099618060B68} = {E279BF0F-7F66-4F3A-A3AB-2CDA66C1CD04}
518568
{5B810E3D-112E-4857-B197-F09D2FD41E27} = {EF0337F2-ED00-4643-89FD-EE10863F1870}
569+
{CFE2FACB-4538-4B99-8A10-306F3882952D} = {EF0337F2-ED00-4643-89FD-EE10863F1870}
519570
EndGlobalSection
520571
EndGlobal

test/Services/FunctionalTests/Class1.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp1.1</TargetFramework>
55
</PropertyGroup>
66

7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" />
9+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170106-08" />
10+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="1.1.0" />
11+
<PackageReference Include="xunit" Version="2.2.0-beta5-build3474" />
12+
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta5-build1225" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\..\..\src\Services\Ordering\Ordering.API\Ordering.API.csproj" />
17+
<ProjectReference Include="..\..\..\src\Web\WebMVC\WebMVC.csproj" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<None Update="settings.json">
22+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
23+
</None>
24+
</ItemGroup>
25+
726
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Microsoft.AspNetCore.Http;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Security.Claims;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace FunctionalTests.Middleware
9+
{
10+
class AutoAuthorizeMiddleware
11+
{
12+
private readonly RequestDelegate _next;
13+
public AutoAuthorizeMiddleware(RequestDelegate rd)
14+
{
15+
_next = rd;
16+
}
17+
18+
public async Task Invoke(HttpContext httpContext)
19+
{
20+
var identity = new ClaimsIdentity();
21+
identity.AddClaim(new Claim("sub", "1234"));
22+
httpContext.User.AddIdentity(identity);
23+
await _next.Invoke(httpContext);
24+
}
25+
}
26+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using Microsoft.AspNetCore.TestHost;
2+
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
3+
using Microsoft.eShopOnContainers.WebMVC.ViewModels;
4+
using Newtonsoft.Json;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Data.SqlClient;
8+
using System.Net.Http;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
using Xunit;
12+
using static Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands.CreateOrderCommand;
13+
14+
namespace FunctionalTests.Services.Ordering
15+
{
16+
public class OrderingScenarios : OrderingScenariosBase
17+
{
18+
[Fact]
19+
public async Task Create_order_and_return_the_order_by_id()
20+
{
21+
using (var server = CreateServer())
22+
{
23+
var client = server.CreateClient();
24+
25+
//Arrange
26+
await client.PostAsync(Post.AddNewOrder, new StringContent(BuildOrder(), UTF8Encoding.UTF8, "application/json"));
27+
28+
var ordersResponse = await client.GetAsync(Get.Orders);
29+
var responseBody = await ordersResponse.Content.ReadAsStringAsync();
30+
dynamic orders = JsonConvert.DeserializeObject(responseBody);
31+
string orderId = orders[0].ordernumber;
32+
33+
//Act
34+
var order= await client.GetAsync(Get.OrderBy(int.Parse(orderId)));
35+
var orderBody = await order.Content.ReadAsStringAsync();
36+
var result = JsonConvert.DeserializeObject<Order>(orderBody);
37+
38+
//Assert
39+
Assert.Equal(orderId, result.OrderNumber);
40+
Assert.Equal("inprocess", result.Status);
41+
Assert.Equal(1, result.OrderItems.Count);
42+
Assert.Equal(10, result.OrderItems[0].UnitPrice);
43+
}
44+
}
45+
46+
string BuildOrder()
47+
{
48+
var order = new CreateOrderCommand(
49+
cardExpiration: DateTime.UtcNow.AddYears(1),
50+
cardNumber: "5145-555-5555",
51+
cardHolderName: "Jhon Senna",
52+
cardSecurityNumber: "232",
53+
cardTypeId: 1,
54+
city: "Redmon",
55+
country: "USA",
56+
state: "WA",
57+
street: "One way",
58+
zipcode: "zipcode"
59+
);
60+
61+
order.AddOrderItem(new OrderItemDTO()
62+
{
63+
ProductId = 1,
64+
Discount = 10M,
65+
UnitPrice = 10,
66+
Units = 1,
67+
ProductName = "Some name"
68+
});
69+
70+
return JsonConvert.SerializeObject(order);
71+
}
72+
}
73+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.AspNetCore.TestHost;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
using System.Text;
7+
8+
namespace FunctionalTests.Services.Ordering
9+
{
10+
public class OrderingScenariosBase
11+
{
12+
public TestServer CreateServer()
13+
{
14+
var webHostBuilder = new WebHostBuilder();
15+
webHostBuilder.UseContentRoot(Directory.GetCurrentDirectory());
16+
webHostBuilder.UseStartup<OrderingTestsStartup>();
17+
18+
return new TestServer(webHostBuilder);
19+
}
20+
21+
public static class Get
22+
{
23+
public static string Orders = "api/v1/orders";
24+
25+
public static string OrderBy(int id)
26+
{
27+
return $"api/v1/orders/{id}";
28+
}
29+
}
30+
31+
public static class Post
32+
{
33+
public static string AddNewOrder = "api/v1/orders/new";
34+
}
35+
}
36+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using FunctionalTests.Middleware;
2+
using Microsoft.AspNetCore.Builder;
3+
using Microsoft.AspNetCore.Hosting;
4+
using Microsoft.eShopOnContainers.Services.Ordering.API;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Text;
8+
9+
namespace FunctionalTests.Services.Ordering
10+
{
11+
public class OrderingTestsStartup : Startup
12+
{
13+
public OrderingTestsStartup(IHostingEnvironment env) : base(env)
14+
{
15+
}
16+
17+
protected override void ConfigureAuth(IApplicationBuilder app)
18+
{
19+
if (Configuration["isTest"] == bool.TrueString.ToLowerInvariant())
20+
{
21+
app.UseMiddleware<AutoAuthorizeMiddleware>();
22+
}
23+
else
24+
{
25+
base.ConfigureAuth(app);
26+
}
27+
}
28+
}
29+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;",
3+
"IdentityUrl": "http://localhost:5105",
4+
"isTest": "true"
5+
}

test/Services/IntegrationTests/Services/Basket/RedisBasketRepositoryTests.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,24 @@ public async Task UpdateBasket_return_and_add_basket()
3535
Assert.Equal(1, basket.Items.Count);
3636
}
3737

38-
//[Fact]
39-
//public async Task GetBasket_return_existing_basket()
40-
//{
41-
//}
38+
[Fact]
39+
public async Task Delete_Basket_return_null()
40+
{
41+
var redisBasketRepository = BuildBasketRepository();
42+
43+
var basket = await redisBasketRepository.UpdateBasket(new CustomerBasket("customerId")
44+
{
45+
BuyerId = "buyerId",
46+
Items = BuildBasketItems()
47+
});
48+
49+
var deleteResult = await redisBasketRepository.DeleteBasket("buyerId");
50+
51+
var result = await redisBasketRepository.GetBasket(basket.BuyerId);
52+
53+
Assert.True(deleteResult);
54+
Assert.Null(result);
55+
}
4256

4357
RedisBasketRepository BuildBasketRepository()
4458
{

0 commit comments

Comments
 (0)