@ -0,0 +1,30 @@ | |||
namespace IntegrationTests.Services.Marketing | |||
{ | |||
public class CampaignScenarioBase : MarketingScenarioBase | |||
{ | |||
public static class Get | |||
{ | |||
public static string Campaigns = CampaignsUrlBase; | |||
public static string CampaignBy(int id) | |||
=> $"{CampaignsUrlBase}/{id}"; | |||
} | |||
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,45 +0,0 @@ | |||
namespace IntegrationTests.Services.Marketing | |||
{ | |||
using Microsoft.AspNetCore.Hosting; | |||
using Microsoft.AspNetCore.TestHost; | |||
using System.IO; | |||
public class MarketingScenarioBase | |||
{ | |||
private const string _campaignsUrlBase = "api/v1/campaigns"; | |||
public TestServer CreateServer() | |||
{ | |||
var webHostBuilder = new WebHostBuilder(); | |||
webHostBuilder.UseContentRoot(Directory.GetCurrentDirectory() + "\\Services\\Marketing"); | |||
webHostBuilder.UseStartup<MarketingTestsStartup>(); | |||
return new TestServer(webHostBuilder); | |||
} | |||
public static class Get | |||
{ | |||
public static string Campaigns = _campaignsUrlBase; | |||
public static string CampaignBy(int id) | |||
=> $"{_campaignsUrlBase}/{id}"; | |||
} | |||
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}"; | |||
} | |||
} | |||
} |
@ -0,0 +1,20 @@ | |||
namespace IntegrationTests.Services.Marketing | |||
{ | |||
using Microsoft.AspNetCore.Hosting; | |||
using Microsoft.AspNetCore.TestHost; | |||
using System.IO; | |||
public class MarketingScenarioBase | |||
{ | |||
public static string CampaignsUrlBase => "api/v1/campaigns"; | |||
public TestServer CreateServer() | |||
{ | |||
var webHostBuilder = new WebHostBuilder(); | |||
webHostBuilder.UseContentRoot(Directory.GetCurrentDirectory() + "\\Services\\Marketing"); | |||
webHostBuilder.UseStartup<MarketingTestsStartup>(); | |||
return new TestServer(webHostBuilder); | |||
} | |||
} | |||
} |
@ -0,0 +1,80 @@ | |||
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 UserLocationRoleScenarios | |||
: UserLocationRoleScenariosBase | |||
{ | |||
[Fact] | |||
public async Task Get_get_all_user_location_rules_by_campaignId_and_response_ok_status_code() | |||
{ | |||
var campaignId = 1; | |||
using (var server = CreateServer()) | |||
{ | |||
var response = await server.CreateClient() | |||
.GetAsync(Get.UserLocationRulesByCampaignId(campaignId)); | |||
response.EnsureSuccessStatusCode(); | |||
} | |||
} | |||
[Fact] | |||
public async Task Post_add_new_user_location_rule_and_response_ok_status_code() | |||
{ | |||
var campaignId = 1; | |||
using (var server = CreateServer()) | |||
{ | |||
var fakeCampaignDto = GetFakeUserLocationRuleDto(); | |||
var content = new StringContent(JsonConvert.SerializeObject(fakeCampaignDto), Encoding.UTF8, "application/json"); | |||
var response = await server.CreateClient() | |||
.PostAsync(Post.AddNewuserLocationRule(campaignId), content); | |||
response.EnsureSuccessStatusCode(); | |||
} | |||
} | |||
[Fact] | |||
public async Task Delete_delete_user_location_role_and_response_not_content_status_code() | |||
{ | |||
var campaignId = 1; | |||
using (var server = CreateServer()) | |||
{ | |||
var fakeCampaignDto = GetFakeUserLocationRuleDto(); | |||
var content = new StringContent(JsonConvert.SerializeObject(fakeCampaignDto), Encoding.UTF8, "application/json"); | |||
//add user location role | |||
var campaignResponse = await server.CreateClient() | |||
.PostAsync(Post.AddNewuserLocationRule(campaignId), content); | |||
if (int.TryParse(campaignResponse.Headers.Location.Segments[6], out int userLocationRuleId)) | |||
{ | |||
var response = await server.CreateClient() | |||
.DeleteAsync(Delete.UserLocationRoleBy(campaignId, userLocationRuleId)); | |||
Assert.True(response.StatusCode == HttpStatusCode.NoContent); | |||
} | |||
campaignResponse.EnsureSuccessStatusCode(); | |||
} | |||
} | |||
private static UserLocationRuleDTO GetFakeUserLocationRuleDto() | |||
{ | |||
return new UserLocationRuleDTO | |||
{ | |||
LocationId = 20, | |||
Description = "FakeUserLocationRuleDescription" | |||
}; | |||
} | |||
} | |||
} |
@ -0,0 +1,40 @@ | |||
namespace IntegrationTests.Services.Marketing | |||
{ | |||
public class UserLocationRoleScenariosBase : MarketingScenarioBase | |||
{ | |||
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}"; | |||
} | |||
} |