Add functional tests project and ordering intial tests
This commit is contained in:
parent
86104bb79e
commit
74ab90cff2
@ -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
|
||||
|
@ -1,8 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace FunctionalTests
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
}
|
||||
}
|
@ -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>
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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";
|
||||
}
|
||||
}
|
||||
}
|
@ -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
test/Services/FunctionalTests/settings.json
Normal file
5
test/Services/FunctionalTests/settings.json
Normal 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"
|
||||
}
|
@ -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…
x
Reference in New Issue
Block a user