Skip to content

Commit 8a9492e

Browse files
committed
Add catalog test.
1 parent f6b2335 commit 8a9492e

5 files changed

Lines changed: 111 additions & 1 deletion

File tree

test/Services/FunctionalTests/FunctionalTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16+
<ProjectReference Include="..\..\..\src\Services\Catalog\Catalog.API\Catalog.API.csproj" />
1617
<ProjectReference Include="..\..\..\src\Services\Ordering\Ordering.API\Ordering.API.csproj" />
1718
<ProjectReference Include="..\..\..\src\Web\WebMVC\WebMVC.csproj" />
1819
</ItemGroup>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using Microsoft.eShopOnContainers.Services.Catalog.API.Model;
2+
using Microsoft.eShopOnContainers.Services.Catalog.API.ViewModel;
3+
using Newtonsoft.Json;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Net.Http;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using Xunit;
11+
12+
namespace FunctionalTests.Services.Catalog
13+
{
14+
public class CatalogScenarios : CatalogScenariosBase
15+
{
16+
[Fact]
17+
public async Task Post_update_a_catalogitem_price_and_catalogitem_is_returned_modified()
18+
{
19+
using (var server = CreateServer())
20+
{
21+
var client = server.CreateClient();
22+
23+
// Arrange
24+
var itemToModify = GetCatalogItem();
25+
var newPrice = new Random().Next(1, 200);
26+
itemToModify.Price = newPrice;
27+
28+
// Act
29+
var postRes = await client.PostAsync(Post.UpdateCatalogProduct,
30+
new StringContent(JsonConvert.SerializeObject(itemToModify),
31+
UTF8Encoding.UTF8, "application/json"));
32+
var response = await client.GetAsync(Get.ProductByName(itemToModify.Name));
33+
var result = JsonConvert.DeserializeObject<PaginatedItemsViewModel<CatalogItem>>(await response.Content.ReadAsStringAsync());
34+
var item = result.Data.First();
35+
36+
// Assert
37+
Assert.Equal(result.Count, 1);
38+
Assert.Equal(itemToModify.Id, item.Id);
39+
Assert.Equal(newPrice, item.Price);
40+
}
41+
42+
}
43+
44+
private CatalogItem GetCatalogItem()
45+
{
46+
return new CatalogItem()
47+
{
48+
Id = 1,
49+
Price = 12.5M,
50+
Name = ".NET Bot Black Sweatshirt"
51+
};
52+
}
53+
54+
}
55+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using FunctionalTests.Middleware;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.AspNetCore.TestHost;
4+
using Microsoft.eShopOnContainers.Services.Catalog.API;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.IO;
8+
using System.Text;
9+
10+
namespace FunctionalTests.Services.Catalog
11+
{
12+
public class CatalogScenariosBase
13+
{
14+
public TestServer CreateServer()
15+
{
16+
var webHostBuilder = new WebHostBuilder();
17+
webHostBuilder.UseContentRoot(Directory.GetCurrentDirectory());
18+
webHostBuilder.UseStartup<Startup>();
19+
20+
return new TestServer(webHostBuilder);
21+
}
22+
23+
public static class Get
24+
{
25+
public static string Orders = "api/v1/orders";
26+
27+
public static string ProductByName(string name)
28+
{
29+
return $"api/v1/catalog/items/withname/{name}";
30+
}
31+
}
32+
33+
public static class Post
34+
{
35+
public static string UpdateCatalogProduct = "api/v1/catalog";
36+
}
37+
}
38+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Microsoft.eShopOnContainers.Services.Catalog.API;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
using Microsoft.AspNetCore.Hosting;
6+
7+
namespace FunctionalTests.Services.Catalog
8+
{
9+
public class CatalogTestsStartup : Startup
10+
{
11+
public CatalogTestsStartup(IHostingEnvironment env) : base(env)
12+
{
13+
}
14+
}
15+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;",
33
"IdentityUrl": "http://localhost:5105",
4-
"isTest": "true"
4+
"isTest": "true",
5+
"EventBusConnection": "localhost"
56
}

0 commit comments

Comments
 (0)