Add functional test: Check The user has an location campaign
This commit is contained in:
parent
9ae6fa8c64
commit
0024a23801
@ -2,16 +2,46 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp1.1</TargetFramework>
|
<TargetFramework>netcoreapp1.1</TargetFramework>
|
||||||
|
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
|
||||||
|
<PackageTargetFallback>$(PackageTargetFallback);netstandard1.6.1;dnxcore50;portable-net451+win8</PackageTargetFallback>
|
||||||
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
|
||||||
|
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
|
||||||
|
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
|
||||||
</PropertyGroup>
|
</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>
|
<ItemGroup>
|
||||||
<None Remove="Services\Catalog\settings.json" />
|
<None Remove="Services\Catalog\settings.json" />
|
||||||
</ItemGroup>
|
</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>
|
<ItemGroup>
|
||||||
<Content Include="Services\Catalog\settings.json">
|
<Content Include="Services\Catalog\settings.json">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
<Content Include="Services\Location\appsettings.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
<Content Include="Services\Marketing\appsettings.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -38,9 +68,6 @@
|
|||||||
<None Update="Services\Locations\appsettings.json">
|
<None Update="Services\Locations\appsettings.json">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<None Update="Services\Marketing\appsettings.json">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Update="Services\Ordering\settings.json">
|
<None Update="Services\Ordering\settings.json">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"ConnectionString": "mongodb://localhost:27017",
|
||||||
|
"Database": "LocationsDb",
|
||||||
|
"ExternalCatalogBaseUrl": "http://localhost:5101",
|
||||||
|
"IdentityUrl": "http://localhost:5105",
|
||||||
|
"isTest": "true",
|
||||||
|
"EventBusConnection": "localhost"
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
namespace FunctionalTests.Services.Marketing
|
||||||
|
{
|
||||||
|
using System;
|
||||||
|
|
||||||
|
public class CampaignScenariosBase : MarketingScenariosBase
|
||||||
|
{
|
||||||
|
public static class Get
|
||||||
|
{
|
||||||
|
public static string Campaigns = CampaignsUrlBase;
|
||||||
|
|
||||||
|
public static string CampaignBy(int id)
|
||||||
|
=> $"{CampaignsUrlBase}/{id}";
|
||||||
|
|
||||||
|
public static string UserCampaignsByUserId(Guid userId)
|
||||||
|
=> $"{CampaignsUrlBase}/user/{userId}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Post
|
||||||
|
{
|
||||||
|
public static string AddNewCampaign = CampaignsUrlBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Put
|
||||||
|
{
|
||||||
|
public static string CampaignBy(int id)
|
||||||
|
=> $"{CampaignsUrlBase}/{id}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Delete
|
||||||
|
{
|
||||||
|
public static string CampaignBy(int id)
|
||||||
|
=> $"{CampaignsUrlBase}/{id}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,22 +1,16 @@
|
|||||||
namespace FunctionalTests.Services.Marketing
|
namespace FunctionalTests.Services.Marketing
|
||||||
{
|
{
|
||||||
using UserLocationDTO = Microsoft.eShopOnContainers.Services.Marketing.API.Dto.UserLocationDTO;
|
|
||||||
using UserLocation = Microsoft.eShopOnContainers.Services.Locations.API.Model.UserLocation;
|
using UserLocation = Microsoft.eShopOnContainers.Services.Locations.API.Model.UserLocation;
|
||||||
using LocationRequest = Microsoft.eShopOnContainers.Services.Locations.API.ViewModel.LocationRequest;
|
using LocationRequest = Microsoft.eShopOnContainers.Services.Locations.API.ViewModel.LocationRequest;
|
||||||
using FunctionalTests.Extensions;
|
|
||||||
using FunctionalTests.Services.Basket;
|
|
||||||
using FunctionalTests.Services.Locations;
|
using FunctionalTests.Services.Locations;
|
||||||
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
|
|
||||||
using Microsoft.eShopOnContainers.WebMVC.ViewModels;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using WebMVC.Models;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.eShopOnContainers.Services.Marketing.API.Dto;
|
||||||
|
|
||||||
public class MarketingScenarios : MarketingScenariosBase
|
public class MarketingScenarios : MarketingScenariosBase
|
||||||
{
|
{
|
||||||
@ -24,7 +18,7 @@
|
|||||||
public async Task Set_new_user_location_and_get_location_campaign_by_user_id()
|
public async Task Set_new_user_location_and_get_location_campaign_by_user_id()
|
||||||
{
|
{
|
||||||
using (var locationsServer = new LocationsScenariosBase().CreateServer())
|
using (var locationsServer = new LocationsScenariosBase().CreateServer())
|
||||||
using (var marketingServer = CreateServer())
|
using (var marketingServer = new MarketingScenariosBase().CreateServer())
|
||||||
{
|
{
|
||||||
var location = new LocationRequest
|
var location = new LocationRequest
|
||||||
{
|
{
|
||||||
@ -35,7 +29,7 @@
|
|||||||
Encoding.UTF8, "application/json");
|
Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
var userId = new Guid("4611ce3f-380d-4db5-8d76-87a8689058ed");
|
var userId = new Guid("4611ce3f-380d-4db5-8d76-87a8689058ed");
|
||||||
|
|
||||||
|
|
||||||
// GIVEN a new location of user is created
|
// GIVEN a new location of user is created
|
||||||
var response = await locationsServer.CreateClient()
|
var response = await locationsServer.CreateClient()
|
||||||
@ -48,17 +42,16 @@
|
|||||||
var responseBody = await userLocationResponse.Content.ReadAsStringAsync();
|
var responseBody = await userLocationResponse.Content.ReadAsStringAsync();
|
||||||
var userLocation = JsonConvert.DeserializeObject<UserLocation>(responseBody);
|
var userLocation = JsonConvert.DeserializeObject<UserLocation>(responseBody);
|
||||||
|
|
||||||
await Task.Delay(5000);
|
await Task.Delay(300);
|
||||||
|
|
||||||
//Get campaing from Marketing.API given a userId
|
//Get campaing from Marketing.API given a userId
|
||||||
var UserLocationCampaignResponse = await locationsServer.CreateClient()
|
var UserLocationCampaignResponse = await marketingServer.CreateClient()
|
||||||
.GetAsync(Get.UserCampaignByUserId(userId));
|
.GetAsync(CampaignScenariosBase.Get.UserCampaignsByUserId(userId));
|
||||||
|
|
||||||
responseBody = await UserLocationCampaignResponse.Content.ReadAsStringAsync();
|
responseBody = await UserLocationCampaignResponse.Content.ReadAsStringAsync();
|
||||||
var userLocationCampaign = JsonConvert.DeserializeObject<UserLocationDTO>(responseBody);
|
var userLocationCampaigns = JsonConvert.DeserializeObject<List<CampaignDTO>>(responseBody);
|
||||||
|
|
||||||
// Assert
|
Assert.True(userLocationCampaigns.Count > 0);
|
||||||
Assert.Equal(userLocation.LocationId, userLocationCampaign.LocationId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,33 +16,5 @@
|
|||||||
|
|
||||||
return new TestServer(webHostBuilder);
|
return new TestServer(webHostBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Get
|
|
||||||
{
|
|
||||||
public static string Campaigns = CampaignsUrlBase;
|
|
||||||
|
|
||||||
public static string CampaignBy(int id)
|
|
||||||
=> $"{CampaignsUrlBase}/{id}";
|
|
||||||
|
|
||||||
public static string UserCampaignByUserId(System.Guid userId)
|
|
||||||
=> $"{CampaignsUrlBase}/user/{userId}";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Post
|
|
||||||
{
|
|
||||||
public static string AddNewCampaign = CampaignsUrlBase;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Put
|
|
||||||
{
|
|
||||||
public static string CampaignBy(int id)
|
|
||||||
=> $"{CampaignsUrlBase}/{id}";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Delete
|
|
||||||
{
|
|
||||||
public static string CampaignBy(int id)
|
|
||||||
=> $"{CampaignsUrlBase}/{id}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,10 +1,10 @@
|
|||||||
using FunctionalTests.Middleware;
|
namespace FunctionalTests.Services.Marketing
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.eShopOnContainers.Services.Ordering.API;
|
|
||||||
|
|
||||||
namespace FunctionalTests.Services.Marketing
|
|
||||||
{
|
{
|
||||||
|
using Microsoft.eShopOnContainers.Services.Marketing.API;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using FunctionalTests.Middleware;
|
||||||
|
|
||||||
public class MarketingTestsStartup : Startup
|
public class MarketingTestsStartup : Startup
|
||||||
{
|
{
|
||||||
public MarketingTestsStartup(IHostingEnvironment env) : base(env)
|
public MarketingTestsStartup(IHostingEnvironment env) : base(env)
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
namespace FunctionalTests.Services.Marketing
|
||||||
|
{
|
||||||
|
public class UserLocationRoleScenariosBase : MarketingScenariosBase
|
||||||
|
{
|
||||||
|
private const string EndpointLocationName = "locations";
|
||||||
|
public static class Get
|
||||||
|
{
|
||||||
|
public static string UserLocationRulesByCampaignId(int campaignId)
|
||||||
|
=> GetUserLocationRolesUrlBase(campaignId);
|
||||||
|
|
||||||
|
public static string UserLocationRuleByCampaignAndUserLocationRuleId(int campaignId,
|
||||||
|
int userLocationRuleId)
|
||||||
|
=> $"{GetUserLocationRolesUrlBase(campaignId)}/{userLocationRuleId}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Post
|
||||||
|
{
|
||||||
|
public static string AddNewuserLocationRule(int campaignId)
|
||||||
|
=> GetUserLocationRolesUrlBase(campaignId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Put
|
||||||
|
{
|
||||||
|
public static string UserLocationRoleBy(int campaignId,
|
||||||
|
int userLocationRuleId)
|
||||||
|
=> $"{GetUserLocationRolesUrlBase(campaignId)}/{userLocationRuleId}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Delete
|
||||||
|
{
|
||||||
|
public static string UserLocationRoleBy(int campaignId,
|
||||||
|
int userLocationRuleId)
|
||||||
|
=> $"{GetUserLocationRolesUrlBase(campaignId)}/{userLocationRuleId}";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static string GetUserLocationRolesUrlBase(int campaignId)
|
||||||
|
=> $"{CampaignsUrlBase}/{campaignId}/{EndpointLocationName}";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"ConnectionString": "Server=tcp:127.0.0.1,5433;Initial Catalog=Microsoft.eShopOnContainers.Services.MarketingDb;User Id=sa;Password=Pass@word",
|
||||||
|
"MongoConnectionString": "mongodb://localhost:27017",
|
||||||
|
"MongoDatabase": "MarketingDb",
|
||||||
|
"IdentityUrl": "http://localhost:5105",
|
||||||
|
"isTest": "true",
|
||||||
|
"EventBusConnection": "localhost"
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user