Browse Source

Add catalog test.

pull/126/head
DESKTOP-V1VLQ15\dsanz 8 years ago
parent
commit
8a9492e573
5 changed files with 111 additions and 1 deletions
  1. +1
    -0
      test/Services/FunctionalTests/FunctionalTests.csproj
  2. +55
    -0
      test/Services/FunctionalTests/Services/Catalog/CatalogScenarios.cs
  3. +38
    -0
      test/Services/FunctionalTests/Services/Catalog/CatalogScenariosBase.cs
  4. +15
    -0
      test/Services/FunctionalTests/Services/Catalog/CatalogTestsStartup.cs
  5. +2
    -1
      test/Services/FunctionalTests/settings.json

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

@ -13,6 +13,7 @@
</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\Web\WebMVC\WebMVC.csproj" />
</ItemGroup>


+ 55
- 0
test/Services/FunctionalTests/Services/Catalog/CatalogScenarios.cs View File

@ -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"
};
}
}
}

+ 38
- 0
test/Services/FunctionalTests/Services/Catalog/CatalogScenariosBase.cs View File

@ -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";
}
}
}

+ 15
- 0
test/Services/FunctionalTests/Services/Catalog/CatalogTestsStartup.cs View File

@ -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)
{
}
}
}

+ 2
- 1
test/Services/FunctionalTests/settings.json View File

@ -1,5 +1,6 @@
{
"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"
"isTest": "true",
"EventBusConnection": "localhost"
}

Loading…
Cancel
Save