diff --git a/test/Services/IntegrationTests/Services/Marketing/CampaignScenarioBase.cs b/test/Services/IntegrationTests/Services/Marketing/CampaignScenarioBase.cs new file mode 100644 index 000000000..a23fd1677 --- /dev/null +++ b/test/Services/IntegrationTests/Services/Marketing/CampaignScenarioBase.cs @@ -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}"; + } + } +} \ No newline at end of file diff --git a/test/Services/IntegrationTests/Services/Marketing/MarketingScenarios.cs b/test/Services/IntegrationTests/Services/Marketing/CampaignScenarios.cs similarity index 88% rename from test/Services/IntegrationTests/Services/Marketing/MarketingScenarios.cs rename to test/Services/IntegrationTests/Services/Marketing/CampaignScenarios.cs index 29dcbebda..8e27958b9 100644 --- a/test/Services/IntegrationTests/Services/Marketing/MarketingScenarios.cs +++ b/test/Services/IntegrationTests/Services/Marketing/CampaignScenarios.cs @@ -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 - { - new RuleDTO - { - LocationId = 1, - Description = "testDescription", - RuleTypeId = 3, - } - } }; } } diff --git a/test/Services/IntegrationTests/Services/Marketing/MarketingScenarioBase.cs b/test/Services/IntegrationTests/Services/Marketing/MarketingScenarioBase.cs deleted file mode 100644 index 01383410b..000000000 --- a/test/Services/IntegrationTests/Services/Marketing/MarketingScenarioBase.cs +++ /dev/null @@ -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(); - - 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}"; - } - } -} \ No newline at end of file diff --git a/test/Services/IntegrationTests/Services/Marketing/MarketingScenariosBase.cs b/test/Services/IntegrationTests/Services/Marketing/MarketingScenariosBase.cs new file mode 100644 index 000000000..832fb1b82 --- /dev/null +++ b/test/Services/IntegrationTests/Services/Marketing/MarketingScenariosBase.cs @@ -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(); + + return new TestServer(webHostBuilder); + } + } +} \ No newline at end of file diff --git a/test/Services/IntegrationTests/Services/Marketing/UserLocationRoleScenarios.cs b/test/Services/IntegrationTests/Services/Marketing/UserLocationRoleScenarios.cs new file mode 100644 index 000000000..f7fbd6cee --- /dev/null +++ b/test/Services/IntegrationTests/Services/Marketing/UserLocationRoleScenarios.cs @@ -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" + }; + } + } +} diff --git a/test/Services/IntegrationTests/Services/Marketing/UserLocationRoleScenariosBase.cs b/test/Services/IntegrationTests/Services/Marketing/UserLocationRoleScenariosBase.cs new file mode 100644 index 000000000..cd6fcc9f3 --- /dev/null +++ b/test/Services/IntegrationTests/Services/Marketing/UserLocationRoleScenariosBase.cs @@ -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}"; + } +} \ No newline at end of file