Browse Source

Edit the integration test

pull/223/head
Christian Arenas 7 years ago
parent
commit
1900ee2b61
6 changed files with 175 additions and 60 deletions
  1. +30
    -0
      test/Services/IntegrationTests/Services/Marketing/CampaignScenarioBase.cs
  2. +5
    -15
      test/Services/IntegrationTests/Services/Marketing/CampaignScenarios.cs
  3. +0
    -45
      test/Services/IntegrationTests/Services/Marketing/MarketingScenarioBase.cs
  4. +20
    -0
      test/Services/IntegrationTests/Services/Marketing/MarketingScenariosBase.cs
  5. +80
    -0
      test/Services/IntegrationTests/Services/Marketing/UserLocationRoleScenarios.cs
  6. +40
    -0
      test/Services/IntegrationTests/Services/Marketing/UserLocationRoleScenariosBase.cs

+ 30
- 0
test/Services/IntegrationTests/Services/Marketing/CampaignScenarioBase.cs View File

@ -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}";
}
}
}

test/Services/IntegrationTests/Services/Marketing/MarketingScenarios.cs → test/Services/IntegrationTests/Services/Marketing/CampaignScenarios.cs View File

@ -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,
}
}
};
}
}

+ 0
- 45
test/Services/IntegrationTests/Services/Marketing/MarketingScenarioBase.cs View File

@ -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}";
}
}
}

+ 20
- 0
test/Services/IntegrationTests/Services/Marketing/MarketingScenariosBase.cs View File

@ -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);
}
}
}

+ 80
- 0
test/Services/IntegrationTests/Services/Marketing/UserLocationRoleScenarios.cs View File

@ -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"
};
}
}
}

+ 40
- 0
test/Services/IntegrationTests/Services/Marketing/UserLocationRoleScenariosBase.cs View File

@ -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…
Cancel
Save