Browse Source

Updated test Projects and codes and NuGetPackages

pull/702/head
rafsanulhasan 6 years ago
parent
commit
e6f329de48
8 changed files with 439 additions and 429 deletions
  1. +67
    -67
      test/Services/FunctionalTests/FunctionalTests.csproj
  2. +57
    -56
      test/Services/IntegrationTests/IntegrationTests.csproj
  3. +146
    -141
      test/Services/IntegrationTests/Services/Catalog/CatalogScenarios.cs
  4. +128
    -125
      test/Services/IntegrationTests/Services/Marketing/CampaignScenarios.cs
  5. +2
    -2
      test/Services/IntegrationTests/Services/Ordering/OrderingScenarios.cs
  6. +8
    -8
      test/Services/IntegrationTests/Services/Ordering/settings.json
  7. +1
    -1
      test/Services/UnitTest/Ordering/Application/OrdersWebApiTest.cs
  8. +30
    -29
      test/Services/UnitTest/UnitTest.csproj

+ 67
- 67
test/Services/FunctionalTests/FunctionalTests.csproj View File

@ -1,78 +1,78 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<!--<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>-->
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Services\Location\**" />
<Compile Remove="Services\Marketing\**" />
<EmbeddedResource Remove="Services\Location\**" />
<EmbeddedResource Remove="Services\Marketing\**" />
<None Remove="Services\Location\**" />
<None Remove="Services\Marketing\**" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Services\Location\**" />
<Compile Remove="Services\Marketing\**" />
<EmbeddedResource Remove="Services\Location\**" />
<EmbeddedResource Remove="Services\Marketing\**" />
<None Remove="Services\Location\**" />
<None Remove="Services\Marketing\**" />
</ItemGroup>
<ItemGroup>
<Compile Include="Services\Location\LocationsScenariosBase.cs" />
<Compile Include="Services\Location\LocationsTestsStartup.cs" />
<Compile Include="Services\Marketing\CampaignScenariosBase.cs" />
<Compile Include="Services\Marketing\UserLocationRoleScenariosBase.cs" />
<Compile Include="Services\Marketing\MarketingScenarios.cs" />
<Compile Include="Services\Marketing\MarketingScenariosBase.cs" />
<Compile Include="Services\Marketing\MarketingTestsStartup.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="Services\Location\LocationsScenariosBase.cs" />
<Compile Include="Services\Location\LocationsTestsStartup.cs" />
<Compile Include="Services\Marketing\CampaignScenariosBase.cs" />
<Compile Include="Services\Marketing\UserLocationRoleScenariosBase.cs" />
<Compile Include="Services\Marketing\MarketingScenarios.cs" />
<Compile Include="Services\Marketing\MarketingScenariosBase.cs" />
<Compile Include="Services\Marketing\MarketingTestsStartup.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Services\Basket\appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Services\Catalog\appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Services\Location\appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Services\Marketing\appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="Services\Basket\appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Services\Catalog\appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Services\Location\appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Services\Marketing\appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.1" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.1.1" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Services\Basket\Basket.API\Basket.API.csproj" />
<ProjectReference Include="..\..\..\src\Services\Catalog\Catalog.API\Catalog.API.csproj" />
<ProjectReference Include="..\..\..\src\Services\Location\Locations.API\Locations.API.csproj" />
<ProjectReference Include="..\..\..\src\Services\Marketing\Marketing.API\Marketing.API.csproj" />
<ProjectReference Include="..\..\..\src\Services\Ordering\Ordering.API\Ordering.API.csproj" />
<ProjectReference Include="..\..\..\src\Web\WebMVC\WebMVC.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Services\Basket\Basket.API\Basket.API.csproj" />
<ProjectReference Include="..\..\..\src\Services\Catalog\Catalog.API\Catalog.API.csproj" />
<ProjectReference Include="..\..\..\src\Services\Location\Locations.API\Locations.API.csproj" />
<ProjectReference Include="..\..\..\src\Services\Marketing\Marketing.API\Marketing.API.csproj" />
<ProjectReference Include="..\..\..\src\Services\Ordering\Ordering.API\Ordering.API.csproj" />
<ProjectReference Include="..\..\..\src\Web\WebMVC\WebMVC.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Services\Locations\appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Services\Ordering\settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Services\Locations\appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Services\Ordering\settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>

+ 57
- 56
test/Services/IntegrationTests/IntegrationTests.csproj View File

@ -1,66 +1,67 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>IntegrationTests</AssemblyName>
<PackageId>IntegrationTests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AssemblyName>IntegrationTests</AssemblyName>
<PackageId>IntegrationTests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
</PropertyGroup>
<ItemGroup>
<None Remove="Services\Locations\appsettings.json" />
</ItemGroup>
<ItemGroup>
<None Remove="Services\Locations\appsettings.json" />
</ItemGroup>
<ItemGroup>
<!--<Content Include="settings.json;web.config">-->
<Content Include="Services\Basket\appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Services\Catalog\appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Services\Marketing\appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Services\Locations\appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Services\Ordering\settings.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<!--<Content Include="settings.json;web.config">-->
<Content Include="Services\Basket\appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Services\Catalog\appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Services\Marketing\appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Services\Locations\appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Services\Ordering\settings.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Services\Basket\Basket.API\Basket.API.csproj" />
<ProjectReference Include="..\..\..\src\Services\Catalog\Catalog.API\Catalog.API.csproj" />
<ProjectReference Include="..\..\..\src\Services\Location\Locations.API\Locations.API.csproj" />
<ProjectReference Include="..\..\..\src\Services\Marketing\Marketing.API\Marketing.API.csproj" />
<ProjectReference Include="..\..\..\src\Services\Ordering\Ordering.API\Ordering.API.csproj" />
<ProjectReference Include="..\..\..\src\Web\WebMVC\WebMVC.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Services\Basket\Basket.API\Basket.API.csproj" />
<ProjectReference Include="..\..\..\src\Services\Catalog\Catalog.API\Catalog.API.csproj" />
<ProjectReference Include="..\..\..\src\Services\Location\Locations.API\Locations.API.csproj" />
<ProjectReference Include="..\..\..\src\Services\Marketing\Marketing.API\Marketing.API.csproj" />
<ProjectReference Include="..\..\..\src\Services\Ordering\Ordering.API\Ordering.API.csproj" />
<ProjectReference Include="..\..\..\src\Web\WebMVC\WebMVC.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.0" />
<PackageReference Include="Moq" Version="4.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.1" />
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="StackExchange.Redis.strongname" Version="1.2.6" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.1.1" />
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.500-preview2-1-003177" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Moq" Version="4.9.0" />
<PackageReference Include="StackExchange.Redis.StrongName" Version="1.2.6" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
</ItemGroup>
<ItemGroup>
<Content Update="Services\Ordering\settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Content Update="Services\Ordering\settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>

+ 146
- 141
test/Services/IntegrationTests/Services/Catalog/CatalogScenarios.cs View File

@ -3,145 +3,150 @@ using System.Net;
namespace IntegrationTests.Services.Catalog
{
using System.Threading.Tasks;
using Xunit;
public class CatalogScenarios
: CatalogScenarioBase
{
[Fact]
public async Task Get_get_all_catalogitems_and_response_ok_status_code()
{
using (var server = CreateServer())
{
var response = await server.CreateClient()
.GetAsync(Get.Items());
response.EnsureSuccessStatusCode();
}
}
[Fact]
public async Task Get_get_catalogitem_by_id_and_response_ok_status_code()
{
using (var server = CreateServer())
{
var response = await server.CreateClient()
.GetAsync(Get.ItemById(1));
response.EnsureSuccessStatusCode();
}
}
[Fact]
public async Task Get_get_catalogitem_by_id_and_response_bad_request_status_code()
{
using (var server = CreateServer())
{
var response = await server.CreateClient()
.GetAsync(Get.ItemById(int.MinValue));
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
}
}
[Fact]
public async Task Get_get_catalogitem_by_id_and_response_not_found_status_code()
{
using (var server = CreateServer())
{
var response = await server.CreateClient()
.GetAsync(Get.ItemById(int.MaxValue));
Assert.Equal( HttpStatusCode.NotFound, response.StatusCode);
}
}
[Fact]
public async Task Get_get_catalogitem_by_name_and_response_ok_status_code()
{
using (var server = CreateServer())
{
var response = await server.CreateClient()
.GetAsync(Get.ItemByName(".NET"));
response.EnsureSuccessStatusCode();
}
}
[Fact]
public async Task Get_get_paginated_catalogitem_by_name_and_response_ok_status_code()
{
using (var server = CreateServer())
{
const bool paginated = true;
var response = await server.CreateClient()
.GetAsync(Get.ItemByName(".NET", paginated));
response.EnsureSuccessStatusCode();
}
}
[Fact]
public async Task Get_get_paginated_catalog_items_and_response_ok_status_code()
{
using (var server = CreateServer())
{
const bool paginated = true;
var response = await server.CreateClient()
.GetAsync(Get.Items(paginated));
response.EnsureSuccessStatusCode();
}
}
[Fact]
public async Task Get_get_filtered_catalog_items_and_response_ok_status_code()
{
using (var server = CreateServer())
{
var response = await server.CreateClient()
.GetAsync(Get.Filtered(1, 1));
response.EnsureSuccessStatusCode();
}
}
[Fact]
public async Task Get_get_paginated_filtered_catalog_items_and_response_ok_status_code()
{
using (var server = CreateServer())
{
const bool paginated = true;
var response = await server.CreateClient()
.GetAsync(Get.Filtered(1, 1, paginated));
response.EnsureSuccessStatusCode();
}
}
[Fact]
public async Task Get_catalog_types_response_ok_status_code()
{
using (var server = CreateServer())
{
var response = await server.CreateClient()
.GetAsync(Get.Types);
response.EnsureSuccessStatusCode();
}
}
[Fact]
public async Task Get_catalog_brands_response_ok_status_code()
{
using (var server = CreateServer())
{
var response = await server.CreateClient()
.GetAsync(Get.Brands);
response.EnsureSuccessStatusCode();
}
}
}
using System.Threading.Tasks;
using Xunit;
public class CatalogScenarios
: CatalogScenarioBase
{
[Fact]
public async Task Get_get_all_catalogitems_and_response_ok_status_code()
{
using (var server = CreateServer())
{
var response = await server.CreateClient()
.GetAsync(Get.Items());
response.EnsureSuccessStatusCode();
}
}
[Fact]
public async Task Get_get_catalogitem_by_id_and_response_ok_status_code()
{
using (var server = CreateServer())
{
var response = await server.CreateClient()
.GetAsync(Get.ItemById(1));
response.EnsureSuccessStatusCode();
}
}
[Fact]
public async Task Get_get_catalogitem_by_id_and_response_bad_request_status_code()
{
using (var server = CreateServer())
{
var response = await server.CreateClient()
.GetAsync(Get.ItemById(int.MinValue));
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
}
}
[Fact]
public async Task Get_get_catalogitem_by_id_and_response_not_found_status_code()
{
using (var server = CreateServer())
{
var response = await server.CreateClient()
.GetAsync(Get.ItemById(int.MaxValue));
//Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
Assert.True(HttpStatusCode.NotFound == response.StatusCode);
}
}
[Fact]
public async Task Get_get_catalogitem_by_name_and_response_ok_status_code()
{
using (var server = CreateServer())
{
var response = await server.CreateClient()
.GetAsync(Get.ItemByName(".NET"));
response.EnsureSuccessStatusCode();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
}
[Fact]
public async Task Get_get_paginated_catalogitem_by_name_and_response_ok_status_code()
{
using (var server = CreateServer())
{
const bool paginated = true;
var response = await server.CreateClient()
.GetAsync(Get.ItemByName(".NET", paginated));
response.EnsureSuccessStatusCode();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
}
[Fact]
public async Task Get_get_paginated_catalog_items_and_response_ok_status_code()
{
using (var server = CreateServer())
{
const bool paginated = true;
var response = await server.CreateClient()
.GetAsync(Get.Items(paginated));
response.EnsureSuccessStatusCode();
}
}
[Fact]
public async Task Get_get_filtered_catalog_items_and_response_ok_status_code()
{
using (var server = CreateServer())
{
var response = await server.CreateClient()
.GetAsync(Get.Filtered(1, 1));
response.EnsureSuccessStatusCode();
}
}
[Fact]
public async Task Get_get_paginated_filtered_catalog_items_and_response_ok_status_code()
{
using (var server = CreateServer())
{
const bool paginated = true;
var response = await server.CreateClient()
.GetAsync(Get.Filtered(1, 1, paginated));
response.EnsureSuccessStatusCode();
}
}
[Fact]
public async Task Get_catalog_types_response_ok_status_code()
{
using (var server = CreateServer())
{
var response = await server.CreateClient()
.GetAsync(Get.Types);
response.EnsureSuccessStatusCode();
}
}
[Fact]
public async Task Get_catalog_brands_response_ok_status_code()
{
using (var server = CreateServer())
{
var response = await server.CreateClient()
.GetAsync(Get.Brands);
response.EnsureSuccessStatusCode();
}
}
}
}

+ 128
- 125
test/Services/IntegrationTests/Services/Marketing/CampaignScenarios.cs View File

@ -1,128 +1,131 @@
namespace IntegrationTests.Services.Marketing
{
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using System;
using Newtonsoft.Json;
using System.Net;
using Microsoft.eShopOnContainers.Services.Marketing.API.Dto;
public class CampaignScenarios
: CampaignScenarioBase
{
[Fact]
public async Task Get_get_all_campaigns_and_response_ok_status_code()
{
using (var server = CreateServer())
{
var response = await server.CreateClient()
.GetAsync(Get.Campaigns);
response.EnsureSuccessStatusCode();
}
}
[Fact]
public async Task Get_get_campaign_by_id_and_response_ok_status_code()
{
var campaignId = 1;
using (var server = CreateServer())
{
var response = await server.CreateClient()
.GetAsync(Get.CampaignBy(campaignId));
response.EnsureSuccessStatusCode();
}
}
[Fact]
public async Task Get_get_campaign_by_id_and_response_not_found_status_code()
{
using (var server = CreateServer())
{
var response = await server.CreateClient()
.GetAsync(Get.CampaignBy(int.MaxValue));
Assert.True(response.StatusCode == HttpStatusCode.NotFound);
}
}
[Fact]
public async Task Post_add_new_campaign_and_response_ok_status_code()
{
using (var server = CreateServer())
{
var fakeCampaignDto = GetFakeCampaignDto();
var content = new StringContent(JsonConvert.SerializeObject(fakeCampaignDto), Encoding.UTF8, "application/json");
var response = await server.CreateClient()
.PostAsync(Post.AddNewCampaign, content);
response.EnsureSuccessStatusCode();
}
}
[Fact]
public async Task Delete_delete_campaign_and_response_not_content_status_code()
{
using (var server = CreateServer())
{
var fakeCampaignDto = GetFakeCampaignDto();
var content = new StringContent(JsonConvert.SerializeObject(fakeCampaignDto), Encoding.UTF8, "application/json");
//add campaign
var campaignResponse = await server.CreateClient()
.PostAsync(Post.AddNewCampaign, content);
if (int.TryParse(campaignResponse.Headers.Location.Segments[4], out int id))
{
var response = await server.CreateClient()
.DeleteAsync(Delete.CampaignBy(id));
Assert.True(response.StatusCode == HttpStatusCode.NoContent);
}
campaignResponse.EnsureSuccessStatusCode();
}
}
[Fact]
public async Task Put_update_campaign_and_response_not_content_status_code()
{
using (var server = CreateServer())
{
var fakeCampaignDto = GetFakeCampaignDto();
var content = new StringContent(JsonConvert.SerializeObject(fakeCampaignDto), Encoding.UTF8, "application/json");
//add campaign
var campaignResponse = await server.CreateClient()
.PostAsync(Post.AddNewCampaign, content);
if (int.TryParse(campaignResponse.Headers.Location.Segments[4], out int id))
{
fakeCampaignDto.Description = "FakeCampaignUpdatedDescription";
content = new StringContent(JsonConvert.SerializeObject(fakeCampaignDto), Encoding.UTF8, "application/json");
var response = await server.CreateClient()
.PutAsync(Put.CampaignBy(id), content);
Assert.True(response.StatusCode == HttpStatusCode.Created);
}
campaignResponse.EnsureSuccessStatusCode();
}
}
private static CampaignDTO GetFakeCampaignDto()
{
return new CampaignDTO()
{
Name = "FakeCampaignName",
Description = "FakeCampaignDescription",
From = DateTime.Now,
To = DateTime.Now.AddDays(7),
PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/campaigns/0/pic"
};
}
}
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using System;
using Newtonsoft.Json;
using System.Net;
using Microsoft.eShopOnContainers.Services.Marketing.API.Dto;
public class CampaignScenarios
: CampaignScenarioBase
{
[Fact]
public async Task Get_get_all_campaigns_and_response_ok_status_code()
{
using (var server = CreateServer())
{
var response = await server.CreateClient()
.GetAsync(Get.Campaigns);
response.EnsureSuccessStatusCode();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
}
[Fact]
public async Task Get_get_campaign_by_id_and_response_ok_status_code()
{
var campaignId = 1;
using (var server = CreateServer())
{
var response = await server.CreateClient()
.GetAsync(Get.CampaignBy(campaignId));
response.EnsureSuccessStatusCode();
}
}
[Fact]
public async Task Get_get_campaign_by_id_and_response_not_found_status_code()
{
using (var server = CreateServer())
{
var response = await server.CreateClient()
.GetAsync(Get.CampaignBy(int.MaxValue));
Assert.True(response.StatusCode == HttpStatusCode.NotFound);
}
}
[Fact]
public async Task Post_add_new_campaign_and_response_ok_status_code()
{
using (var server = CreateServer())
{
var fakeCampaignDto = GetFakeCampaignDto();
var content = new StringContent(JsonConvert.SerializeObject(fakeCampaignDto), Encoding.UTF8, "application/json");
var response = await server.CreateClient()
.PostAsync(Post.AddNewCampaign, content);
response.EnsureSuccessStatusCode();
}
}
[Fact]
public async Task Delete_delete_campaign_and_response_not_content_status_code()
{
using (var server = CreateServer())
{
var fakeCampaignDto = GetFakeCampaignDto();
var content = new StringContent(JsonConvert.SerializeObject(fakeCampaignDto), Encoding.UTF8, "application/json");
//add campaign
var campaignResponse = await server.CreateClient()
.PostAsync(Post.AddNewCampaign, content);
if (int.TryParse(campaignResponse?.Headers.Location.Segments[4], out int id))
{
var response = await server.CreateClient()
.DeleteAsync(Delete.CampaignBy(id));
Assert.True(response.StatusCode == HttpStatusCode.NoContent);
}
campaignResponse.EnsureSuccessStatusCode();
}
}
[Fact]
public async Task Put_update_campaign_and_response_not_content_status_code()
{
using (var server = CreateServer())
{
var fakeCampaignDto = GetFakeCampaignDto();
var content = new StringContent(JsonConvert.SerializeObject(fakeCampaignDto), Encoding.UTF8, "application/json");
//add campaign
var campaignResponse = await server.CreateClient()
.PostAsync(Post.AddNewCampaign, content);
campaignResponse.EnsureSuccessStatusCode();
Assert.Equal(HttpStatusCode.Created, campaignResponse.StatusCode);
if (int.TryParse(campaignResponse.Headers.Location.Segments[4], out int id))
{
fakeCampaignDto.Description = "FakeCampaignUpdatedDescription";
content = new StringContent(JsonConvert.SerializeObject(fakeCampaignDto), Encoding.UTF8, "application/json");
var response = await server.CreateClient()
.PutAsync(Put.CampaignBy(id), content);
Assert.True(response.StatusCode == HttpStatusCode.NoContent);
}
}
}
private static CampaignDTO GetFakeCampaignDto()
{
return new CampaignDTO()
{
Name = "FakeCampaignName",
Description = "FakeCampaignDescription",
From = DateTime.Now,
To = DateTime.Now.AddDays(7),
PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/campaigns/0/pic"
};
}
}
}

+ 2
- 2
test/Services/IntegrationTests/Services/Ordering/OrderingScenarios.cs View File

@ -29,7 +29,7 @@
{
using (var server = CreateServer())
{
var content = new StringContent(BuildOrder(), UTF8Encoding.UTF8, "application/json");
var content = new StringContent(BuildOrder(), Encoding.UTF8, "application/json");
var response = await server.CreateIdempotentClient()
.PutAsync(Put.CancelOrder, content);
@ -42,7 +42,7 @@
{
using (var server = CreateServer())
{
var content = new StringContent(BuildOrder(), UTF8Encoding.UTF8, "application/json");
var content = new StringContent(BuildOrder(), Encoding.UTF8, "application/json");
var response = await server.CreateIdempotentClient()
.PutAsync(Put.ShipOrder, content);


+ 8
- 8
test/Services/IntegrationTests/Services/Ordering/settings.json View File

@ -1,10 +1,10 @@
{
"ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;",
"ExternalCatalogBaseUrl": "http://localhost:5101",
"IdentityUrl": "http://localhost:5105",
"isTest": "true",
"EventBusConnection": "localhost",
"CheckUpdateTime": "30000",
"GracePeriodTime": "1",
"SubscriptionClientName": "Ordering"
"CheckUpdateTime": "30000",
"ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;",
"EventBusConnection": "localhost",
"ExternalCatalogBaseUrl": "http://localhost:5101",
"GracePeriodTime": "1",
"IdentityUrl": "http://localhost:5105",
"isTest": "true",
"SubscriptionClientName": "Ordering"
}

+ 1
- 1
test/Services/UnitTest/Ordering/Application/OrdersWebApiTest.cs View File

@ -94,7 +94,7 @@ namespace UnitTest.Ordering.Application
{
//Arrange
var fakeDynamicResult = Enumerable.Empty<OrderSummary>();
_orderQueriesMock.Setup(x => x.GetOrdersAsync())
_orderQueriesMock.Setup(x => x.GetOrdersFromUserAsync(Guid.NewGuid()))
.Returns(Task.FromResult(fakeDynamicResult));
//Act


+ 30
- 29
test/Services/UnitTest/UnitTest.csproj View File

@ -1,36 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\BuildingBlocks\EventBus\EventBus\EventBus.csproj" />
<ProjectReference Include="..\..\..\src\Services\Basket\Basket.API\Basket.API.csproj" />
<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.Infrastructure\Ordering.Infrastructure.csproj" />
<ProjectReference Include="..\..\..\src\Services\Ordering\Ordering.Domain\Ordering.Domain.csproj" />
<ProjectReference Include="..\..\..\src\Web\WebMVC\WebMVC.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\BuildingBlocks\EventBus\EventBus\EventBus.csproj" />
<ProjectReference Include="..\..\..\src\Services\Basket\Basket.API\Basket.API.csproj" />
<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.Infrastructure\Ordering.Infrastructure.csproj" />
<ProjectReference Include="..\..\..\src\Services\Ordering\Ordering.Domain\Ordering.Domain.csproj" />
<ProjectReference Include="..\..\..\src\Web\WebMVC\WebMVC.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="MediatR" Version="4.0.1" />
<PackageReference Include="Moq" Version="4.8.1" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.1" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MediatR" Version="5.1.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.1.1" />
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.500-preview2-1-003177" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.1"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Moq" Version="4.9.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>

Loading…
Cancel
Save