|
| 1 | +namespace IntegrationTests.Services.Marketing |
| 2 | +{ |
| 3 | + using System.Net.Http; |
| 4 | + using System.Text; |
| 5 | + using System.Threading.Tasks; |
| 6 | + using Xunit; |
| 7 | + using System; |
| 8 | + using Newtonsoft.Json; |
| 9 | + using Microsoft.eShopOnContainers.Services.Marketing.API.Model; |
| 10 | + using System.Collections.Generic; |
| 11 | + using System.Net; |
| 12 | + using Microsoft.eShopOnContainers.Services.Marketing.API.Dto; |
| 13 | + |
| 14 | + public class MarketingScenarios |
| 15 | + : MarketingScenarioBase |
| 16 | + { |
| 17 | + [Fact] |
| 18 | + public async Task Get_get_all_campaigns_and_response_ok_status_code() |
| 19 | + { |
| 20 | + using (var server = CreateServer()) |
| 21 | + { |
| 22 | + var response = await server.CreateClient() |
| 23 | + .GetAsync(Get.Campaigns); |
| 24 | + |
| 25 | + response.EnsureSuccessStatusCode(); |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + [Fact] |
| 30 | + public async Task Get_get_campaign_by_id_and_response_ok_status_code() |
| 31 | + { |
| 32 | + using (var server = CreateServer()) |
| 33 | + { |
| 34 | + var response = await server.CreateClient() |
| 35 | + .GetAsync(Get.CampaignBy(1)); |
| 36 | + |
| 37 | + response.EnsureSuccessStatusCode(); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + [Fact] |
| 42 | + public async Task Get_get_campaign_by_id_and_response_not_found_status_code() |
| 43 | + { |
| 44 | + using (var server = CreateServer()) |
| 45 | + { |
| 46 | + var response = await server.CreateClient() |
| 47 | + .GetAsync(Get.CampaignBy(9999999)); |
| 48 | + |
| 49 | + Assert.True(response.StatusCode == HttpStatusCode.NotFound); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + [Fact] |
| 54 | + public async Task Post_add_new_campaign_and_response_ok_status_code() |
| 55 | + { |
| 56 | + using (var server = CreateServer()) |
| 57 | + { |
| 58 | + var content = new StringContent(JsonConvert.SerializeObject(FakeCampaignDto), Encoding.UTF8, "application/json"); |
| 59 | + var response = await server.CreateClient() |
| 60 | + .PostAsync(Post.AddNewCampaign, content); |
| 61 | + |
| 62 | + response.EnsureSuccessStatusCode(); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + [Fact] |
| 67 | + public async Task Delete_delete_campaign_and_response_not_content_status_code() |
| 68 | + { |
| 69 | + using (var server = CreateServer()) |
| 70 | + { |
| 71 | + var content = new StringContent(JsonConvert.SerializeObject(FakeCampaignDto), Encoding.UTF8, "application/json"); |
| 72 | + |
| 73 | + //add campaign |
| 74 | + var campaignResponse = await server.CreateClient() |
| 75 | + .PostAsync(Post.AddNewCampaign, content); |
| 76 | + |
| 77 | + if (int.TryParse(campaignResponse.Headers.Location.Segments[4], out int id)) |
| 78 | + { |
| 79 | + var response = await server.CreateClient() |
| 80 | + .DeleteAsync(Delete.CampaignBy(id)); |
| 81 | + |
| 82 | + Assert.True(response.StatusCode == HttpStatusCode.NoContent); |
| 83 | + } |
| 84 | + |
| 85 | + campaignResponse.EnsureSuccessStatusCode(); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + [Fact] |
| 90 | + public async Task Put_update_campaign_and_response_not_content_status_code() |
| 91 | + { |
| 92 | + using (var server = CreateServer()) |
| 93 | + { |
| 94 | + var content = new StringContent(JsonConvert.SerializeObject(FakeCampaignDto), Encoding.UTF8, "application/json"); |
| 95 | + |
| 96 | + //add campaign |
| 97 | + var campaignResponse = await server.CreateClient() |
| 98 | + .PostAsync(Post.AddNewCampaign, content); |
| 99 | + |
| 100 | + if (int.TryParse(campaignResponse.Headers.Location.Segments[4], out int id)) |
| 101 | + { |
| 102 | + FakeCampaignDto.Description = "FakeCampaignUpdatedDescription"; |
| 103 | + content = new StringContent(JsonConvert.SerializeObject(FakeCampaignDto), Encoding.UTF8, "application/json"); |
| 104 | + var response = await server.CreateClient() |
| 105 | + .PutAsync(Put.CampaignBy(id), content); |
| 106 | + |
| 107 | + Assert.True(response.StatusCode == HttpStatusCode.Created); |
| 108 | + } |
| 109 | + |
| 110 | + campaignResponse.EnsureSuccessStatusCode(); |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + |
| 115 | + private static CampaignDTO FakeCampaignDto = new CampaignDTO |
| 116 | + { |
| 117 | + Description = "FakeCampaignDescription", |
| 118 | + From = DateTime.Now, |
| 119 | + To = DateTime.Now.AddDays(7), |
| 120 | + Url = "http://CampaignUrl.test/fdaf91ad0cef5419719f50198", |
| 121 | + Rules = new List<RuleDTO> |
| 122 | + { |
| 123 | + new RuleDTO |
| 124 | + { |
| 125 | + LocationId = 1, |
| 126 | + Description = "testDescription", |
| 127 | + RuleTypeId = 3, |
| 128 | + } |
| 129 | + } |
| 130 | + }; |
| 131 | + } |
| 132 | +} |
0 commit comments