Add functional test: Check The user has an location campaign
This commit is contained in:
parent
24c8e93888
commit
4e320f813a
@ -2,16 +2,46 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<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>
|
||||
|
||||
<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>
|
||||
<None Remove="Services\Catalog\settings.json" />
|
||||
</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\Catalog\settings.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>
|
||||
@ -38,9 +68,6 @@
|
||||
<None Update="Services\Locations\appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Services\Marketing\appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Services\Ordering\settings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</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
|
||||
{
|
||||
using UserLocationDTO = Microsoft.eShopOnContainers.Services.Marketing.API.Dto.UserLocationDTO;
|
||||
using UserLocation = Microsoft.eShopOnContainers.Services.Locations.API.Model.UserLocation;
|
||||
using LocationRequest = Microsoft.eShopOnContainers.Services.Locations.API.ViewModel.LocationRequest;
|
||||
using FunctionalTests.Extensions;
|
||||
using FunctionalTests.Services.Basket;
|
||||
using FunctionalTests.Services.Locations;
|
||||
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
|
||||
using Microsoft.eShopOnContainers.WebMVC.ViewModels;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WebMVC.Models;
|
||||
using Xunit;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.eShopOnContainers.Services.Marketing.API.Dto;
|
||||
|
||||
public class MarketingScenarios : MarketingScenariosBase
|
||||
{
|
||||
@ -24,7 +18,7 @@
|
||||
public async Task Set_new_user_location_and_get_location_campaign_by_user_id()
|
||||
{
|
||||
using (var locationsServer = new LocationsScenariosBase().CreateServer())
|
||||
using (var marketingServer = CreateServer())
|
||||
using (var marketingServer = new MarketingScenariosBase().CreateServer())
|
||||
{
|
||||
var location = new LocationRequest
|
||||
{
|
||||
@ -35,7 +29,7 @@
|
||||
Encoding.UTF8, "application/json");
|
||||
|
||||
var userId = new Guid("4611ce3f-380d-4db5-8d76-87a8689058ed");
|
||||
|
||||
|
||||
|
||||
// GIVEN a new location of user is created
|
||||
var response = await locationsServer.CreateClient()
|
||||
@ -48,17 +42,16 @@
|
||||
var responseBody = await userLocationResponse.Content.ReadAsStringAsync();
|
||||
var userLocation = JsonConvert.DeserializeObject<UserLocation>(responseBody);
|
||||
|
||||
await Task.Delay(5000);
|
||||
await Task.Delay(300);
|
||||
|
||||
//Get campaing from Marketing.API given a userId
|
||||
var UserLocationCampaignResponse = await locationsServer.CreateClient()
|
||||
.GetAsync(Get.UserCampaignByUserId(userId));
|
||||
var UserLocationCampaignResponse = await marketingServer.CreateClient()
|
||||
.GetAsync(CampaignScenariosBase.Get.UserCampaignsByUserId(userId));
|
||||
|
||||
responseBody = await UserLocationCampaignResponse.Content.ReadAsStringAsync();
|
||||
var userLocationCampaign = JsonConvert.DeserializeObject<UserLocationDTO>(responseBody);
|
||||
var userLocationCampaigns = JsonConvert.DeserializeObject<List<CampaignDTO>>(responseBody);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(userLocation.LocationId, userLocationCampaign.LocationId);
|
||||
Assert.True(userLocationCampaigns.Count > 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,33 +16,5 @@
|
||||
|
||||
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;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API;
|
||||
|
||||
namespace FunctionalTests.Services.Marketing
|
||||
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 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