Edit the integration test
This commit is contained in:
parent
99685b3eae
commit
1900ee2b61
@ -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}";
|
||||
}
|
||||
}
|
||||
}
|
@ -6,13 +6,11 @@
|
||||
using Xunit;
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using Microsoft.eShopOnContainers.Services.Marketing.API.Model;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using Microsoft.eShopOnContainers.Services.Marketing.API.Dto;
|
||||
|
||||
public class MarketingScenarios
|
||||
: MarketingScenarioBase
|
||||
public class CampaignScenarios
|
||||
: CampaignScenarioBase
|
||||
{
|
||||
[Fact]
|
||||
public async Task Get_get_all_campaigns_and_response_ok_status_code()
|
||||
@ -29,10 +27,11 @@
|
||||
[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(1));
|
||||
.GetAsync(Get.CampaignBy(campaignId));
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
@ -44,7 +43,7 @@
|
||||
using (var server = CreateServer())
|
||||
{
|
||||
var response = await server.CreateClient()
|
||||
.GetAsync(Get.CampaignBy(9999999));
|
||||
.GetAsync(Get.CampaignBy(int.MaxValue));
|
||||
|
||||
Assert.True(response.StatusCode == HttpStatusCode.NotFound);
|
||||
}
|
||||
@ -122,15 +121,6 @@
|
||||
From = DateTime.Now,
|
||||
To = DateTime.Now.AddDays(7),
|
||||
Url = "http://CampaignUrl.test/fdaf91ad0cef5419719f50198",
|
||||
Rules = new List<RuleDTO>
|
||||
{
|
||||
new RuleDTO
|
||||
{
|
||||
LocationId = 1,
|
||||
Description = "testDescription",
|
||||
RuleTypeId = 3,
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -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}";
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user