Add catalog test.
This commit is contained in:
parent
f6b2335518
commit
8a9492e573
@ -13,6 +13,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\..\src\Services\Catalog\Catalog.API\Catalog.API.csproj" />
|
||||||
<ProjectReference Include="..\..\..\src\Services\Ordering\Ordering.API\Ordering.API.csproj" />
|
<ProjectReference Include="..\..\..\src\Services\Ordering\Ordering.API\Ordering.API.csproj" />
|
||||||
<ProjectReference Include="..\..\..\src\Web\WebMVC\WebMVC.csproj" />
|
<ProjectReference Include="..\..\..\src\Web\WebMVC\WebMVC.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -0,0 +1,55 @@
|
|||||||
|
using Microsoft.eShopOnContainers.Services.Catalog.API.Model;
|
||||||
|
using Microsoft.eShopOnContainers.Services.Catalog.API.ViewModel;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace FunctionalTests.Services.Catalog
|
||||||
|
{
|
||||||
|
public class CatalogScenarios : CatalogScenariosBase
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public async Task Post_update_a_catalogitem_price_and_catalogitem_is_returned_modified()
|
||||||
|
{
|
||||||
|
using (var server = CreateServer())
|
||||||
|
{
|
||||||
|
var client = server.CreateClient();
|
||||||
|
|
||||||
|
// Arrange
|
||||||
|
var itemToModify = GetCatalogItem();
|
||||||
|
var newPrice = new Random().Next(1, 200);
|
||||||
|
itemToModify.Price = newPrice;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var postRes = await client.PostAsync(Post.UpdateCatalogProduct,
|
||||||
|
new StringContent(JsonConvert.SerializeObject(itemToModify),
|
||||||
|
UTF8Encoding.UTF8, "application/json"));
|
||||||
|
var response = await client.GetAsync(Get.ProductByName(itemToModify.Name));
|
||||||
|
var result = JsonConvert.DeserializeObject<PaginatedItemsViewModel<CatalogItem>>(await response.Content.ReadAsStringAsync());
|
||||||
|
var item = result.Data.First();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(result.Count, 1);
|
||||||
|
Assert.Equal(itemToModify.Id, item.Id);
|
||||||
|
Assert.Equal(newPrice, item.Price);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private CatalogItem GetCatalogItem()
|
||||||
|
{
|
||||||
|
return new CatalogItem()
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
Price = 12.5M,
|
||||||
|
Name = ".NET Bot Black Sweatshirt"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
using FunctionalTests.Middleware;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.TestHost;
|
||||||
|
using Microsoft.eShopOnContainers.Services.Catalog.API;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace FunctionalTests.Services.Catalog
|
||||||
|
{
|
||||||
|
public class CatalogScenariosBase
|
||||||
|
{
|
||||||
|
public TestServer CreateServer()
|
||||||
|
{
|
||||||
|
var webHostBuilder = new WebHostBuilder();
|
||||||
|
webHostBuilder.UseContentRoot(Directory.GetCurrentDirectory());
|
||||||
|
webHostBuilder.UseStartup<Startup>();
|
||||||
|
|
||||||
|
return new TestServer(webHostBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Get
|
||||||
|
{
|
||||||
|
public static string Orders = "api/v1/orders";
|
||||||
|
|
||||||
|
public static string ProductByName(string name)
|
||||||
|
{
|
||||||
|
return $"api/v1/catalog/items/withname/{name}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Post
|
||||||
|
{
|
||||||
|
public static string UpdateCatalogProduct = "api/v1/catalog";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
using Microsoft.eShopOnContainers.Services.Catalog.API;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
|
||||||
|
namespace FunctionalTests.Services.Catalog
|
||||||
|
{
|
||||||
|
public class CatalogTestsStartup : Startup
|
||||||
|
{
|
||||||
|
public CatalogTestsStartup(IHostingEnvironment env) : base(env)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;",
|
"ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;",
|
||||||
"IdentityUrl": "http://localhost:5105",
|
"IdentityUrl": "http://localhost:5105",
|
||||||
"isTest": "true"
|
"isTest": "true",
|
||||||
|
"EventBusConnection": "localhost"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user