private Account getValidAccount() { MockHttpMessageHandler mockHttp = MockTools.GetNewMockHandler(); mockHttp.When(HttpMethod.Post, "*/purge*").Respond(HttpStatusCode.OK); AccountKey accKey = new AccountKey(); accKey.SetToken("17989543-2154-6867-3566-71474693165007735103-0594-4591-2132-259238857481", mockHttp); return(new Account(accKey)); }
public async void BadFormattedJsonContent(string jsonString) { // Arrange MockHttpMessageHandler mockHttp = MockTools.GetNewMockHandler(); mockHttp.When(HttpMethod.Get, "*/test").Respond(HttpStatusCode.OK, "application/failed", jsonString); HttpClient httpClient = mockHttp.ToHttpClient(); // Act HttpResponseMessage httpResponse = await httpClient.GetAsync("http://test.com/test"); // Assert BunnyInvalidResponseException exception = await Assert.ThrowsAsync <BunnyInvalidResponseException>(async() => { await JsonWrapper.Deserialize <object>(httpResponse); }); }
public async void validJsonContent() { // Arrange MockHttpMessageHandler mockHttp = MockTools.GetNewMockHandler(); mockHttp.When(HttpMethod.Get, "*/test").Respond(HttpStatusCode.OK, "application/json", "{\"Value\":\"Test\"}"); HttpClient httpClient = mockHttp.ToHttpClient(); // Act HttpResponseMessage httpResponse = await httpClient.GetAsync("http://test.com/test"); // Assert Assert.NotNull(await JsonWrapper.Deserialize <Hostname>(httpResponse)); }
public async void Account_GetStorageZones_invalid(string jsonString) { // Arrange MockHttpMessageHandler mockHttp = MockTools.GetNewMockHandler(); mockHttp.When(HttpMethod.Get, "*/storagezone").Respond(HttpStatusCode.OK, "application/json", jsonString); AccountKey accKey = new AccountKey(); accKey.SetToken("17989543-2154-6867-3566-71474693165007735103-0594-4591-2132-259238857481", mockHttp); Account account = new Account(accKey); // Act & Arrange await Assert.ThrowsAsync <BunnyInvalidResponseException>(async() => { await account.GetStorageZones(); }); }
public async void Account_CreateStorageZone_valid() { // Arrange MockHttpMessageHandler mockHttp = MockTools.GetNewMockHandler(); mockHttp.When(HttpMethod.Post, "*/storagezone").Respond(HttpStatusCode.Created, "application/json", JsonConvert.SerializeObject(CorrectStorageZones[0])); AccountKey accKey = new AccountKey(); accKey.SetToken("17989543-2154-6867-3566-71474693165007735103-0594-4591-2132-259238857481", mockHttp); Account account = new Account(accKey); // Act & Assert Assert.NotNull(await account.CreateStorageZone("storageName1")); }
public async void Account_DeleteStorageZone_valid() { // Arrange MockHttpMessageHandler mockHttp = MockTools.GetNewMockHandler(); mockHttp.When(HttpMethod.Delete, "*/storagezone/123").Respond(HttpStatusCode.OK); AccountKey accKey = new AccountKey(); accKey.SetToken("17989543-2154-6867-3566-71474693165007735103-0594-4591-2132-259238857481", mockHttp); Account account = new Account(accKey); // Act & Assert Assert.True(await account.DeleteStorageZone(123)); }
public async void Account_DeleteStorageZone_unauthorized() { // Arrange MockHttpMessageHandler mockHttp = MockTools.GetNewMockHandler(); mockHttp.When(HttpMethod.Delete, "*/storagezone/123").Respond(HttpStatusCode.Unauthorized); AccountKey accKey = new AccountKey(); accKey.SetToken("17989543-2154-6867-3566-71474693165007735103-0594-4591-2132-259238857481", mockHttp); Account account = new Account(accKey); // Act & Assert await Assert.ThrowsAsync <BunnyUnauthorizedException>(async() => { await account.DeleteStorageZone(123); }); }
public async void Account_ApplyCoupon_valid() { // Arrange MockHttpMessageHandler mockHttp = MockTools.GetNewMockHandler(); mockHttp.When(HttpMethod.Get, "*/billing/applycode").Respond(HttpStatusCode.OK); AccountKey accKey = new AccountKey(); accKey.SetToken("17989543-2154-6867-3566-71474693165007735103-0594-4591-2132-259238857481", mockHttp); Account account = new Account(accKey); // Act & Assert Assert.True(await account.ApplyCoupon("validcoupon")); }
public async void Account_ApplyCoupon_unauthorized() { // Arrange MockHttpMessageHandler mockHttp = MockTools.GetNewMockHandler(); mockHttp.When(HttpMethod.Get, "*/billing/applycode").Respond(HttpStatusCode.Unauthorized); AccountKey accKey = new AccountKey(); accKey.SetToken("17989543-2154-6867-3566-71474693165007735103-0594-4591-2132-259238857481", mockHttp); Account account = new Account(accKey); // Act & Arrange await Assert.ThrowsAsync <BunnyUnauthorizedException>(async() => { await account.ApplyCoupon("testing"); }); }
public Storage_requests() { MockHttpMessageHandler mockHttp = MockTools.GetNewMockHandler(); mockHttp.When(HttpMethod.Get, "*/testing/testfile").Respond("application/octet-stream", "Yep, this is the testfile"); mockHttp.When(HttpMethod.Put, "*/testing/testfile").Respond(HttpStatusCode.Created); mockHttp.When(HttpMethod.Delete, "*/testing/testfile").Respond(HttpStatusCode.OK); mockHttp.When(HttpMethod.Get, "*/testing/testfolder/").Respond("application/json", JsonConvert.SerializeObject(FolderStorageEntries)); StorageKey sKey = new StorageKey(); sKey.SetToken("12345678-1234-1234-123456789012-1234-1234", mockHttp); storage = new Storage(sKey, "testing"); }
public async void Account_CreateStorageZone_invalid(string zoneName) { // Arrange MockHttpMessageHandler mockHttp = MockTools.GetNewMockHandler(); mockHttp.When(HttpMethod.Post, "*/storagezone").Respond(HttpStatusCode.OK); AccountKey accKey = new AccountKey(); accKey.SetToken("17989543-2154-6867-3566-71474693165007735103-0594-4591-2132-259238857481", mockHttp); Account account = new Account(accKey); // Act & Assert BunnyBadRequestException exception = await Assert.ThrowsAsync <BunnyBadRequestException>(async() => { await account.CreateStorageZone(zoneName); }); Assert.Equal("Name may only contain alphabetical letters, numbers and dashes with a length of 3-20 characters.", exception.Message); }
public async void Account_DeleteStorageZone_invalid(long zoneId) { // Arrange MockHttpMessageHandler mockHttp = MockTools.GetNewMockHandler(); mockHttp.When(HttpMethod.Delete, "*/storagezone/*").Respond(HttpStatusCode.OK); AccountKey accKey = new AccountKey(); accKey.SetToken("17989543-2154-6867-3566-71474693165007735103-0594-4591-2132-259238857481", mockHttp); Account account = new Account(accKey); // Act & Assert BunnyBadRequestException exception = await Assert.ThrowsAsync <BunnyBadRequestException>(async() => { await account.DeleteStorageZone(zoneId); }); Assert.Equal("Zone Id must be higher than 0.", exception.Message); }
public async void Account_ApplyCoupon_invalidInput(string couponCode) { // Arrange MockHttpMessageHandler mockHttp = MockTools.GetNewMockHandler(); mockHttp.When(HttpMethod.Get, "*/billing/applycode").Respond(HttpStatusCode.OK); AccountKey accKey = new AccountKey(); accKey.SetToken("17989543-2154-6867-3566-71474693165007735103-0594-4591-2132-259238857481", mockHttp); Account account = new Account(accKey); // Act & Assert BunnyBadRequestException exception = await Assert.ThrowsAsync <BunnyBadRequestException>(async() => { await account.ApplyCoupon(couponCode); }); Assert.Equal("The presented coupon cannot be empty/null", exception.Message); }
public async void Account_GetStatisticSummary_badrequest_date_one_invalid(DateTime dtFrom, DateTime dtTo) { // Arrange MockHttpMessageHandler mockHttp = MockTools.GetNewMockHandler(); mockHttp.When(HttpMethod.Get, "*/statistics").Respond(HttpStatusCode.OK, "application/json", JsonConvert.SerializeObject(CorrectStatisticSummary)); AccountKey accKey = new AccountKey(); accKey.SetToken("17989543-2154-6867-3566-71474693165007735103-0594-4591-2132-259238857481", mockHttp); Account account = new Account(accKey); // Act & Assert BunnyBadRequestException exception = await Assert.ThrowsAsync <BunnyBadRequestException>(async() => { await account.GetStatisticSummary(dtFrom, dtTo); }); Assert.Equal("Both 'from' and 'to' dates must be provided", exception.Message); }
public async void Account_GetStorageZones_valid() { // Arrange MockHttpMessageHandler mockHttp = MockTools.GetNewMockHandler(); mockHttp.When(HttpMethod.Get, "*/storagezone").Respond(HttpStatusCode.OK, "application/json", JsonConvert.SerializeObject(CorrectStorageZones)); AccountKey accKey = new AccountKey(); accKey.SetToken("17989543-2154-6867-3566-71474693165007735103-0594-4591-2132-259238857481", mockHttp); Account account = new Account(accKey); // Act StorageZone[] zones = await account.GetStorageZones(); // Assert Assert.Equal(CorrectStorageZones.Length, zones.Length); Assert.Equal(CorrectStorageZones[0].Id, zones[0].Id); }
public async void Account_GetStatisticSummary_valid() { // Arrange MockHttpMessageHandler mockHttp = MockTools.GetNewMockHandler(); mockHttp.When(HttpMethod.Get, "*/statistics").Respond(HttpStatusCode.OK, "application/json", JsonConvert.SerializeObject(CorrectStatisticSummary)); AccountKey accKey = new AccountKey(); accKey.SetToken("17989543-2154-6867-3566-71474693165007735103-0594-4591-2132-259238857481", mockHttp); Account account = new Account(accKey); // Act StatisticSummary summary = await account.GetStatisticSummary(); // Assert Assert.Equal(CorrectStatisticSummary.TotalBandwidthUsed, summary.TotalBandwidthUsed); Assert.Equal(CorrectStatisticSummary.BandwidthUsedChart.Count, summary.BandwidthUsedChart.Count); }
public async void Account_GetBillingSummary_valid() { // Arrange MockHttpMessageHandler mockHttp = MockTools.GetNewMockHandler(); mockHttp.When(HttpMethod.Get, "*/billing").Respond(HttpStatusCode.OK, "application/json", JsonConvert.SerializeObject(CorrectBillingSummary)); AccountKey accKey = new AccountKey(); accKey.SetToken("17989543-2154-6867-3566-71474693165007735103-0594-4591-2132-259238857481", mockHttp); Account account = new Account(accKey); // Act BillingSummary summary = await account.GetBillingSummary(); // Assert Assert.Equal(CorrectBillingSummary.Balance, summary.Balance); Assert.Equal(CorrectBillingSummary.BillingRecords.Length, summary.BillingRecords.Length); Assert.Equal(CorrectBillingSummary.BillingRecords[0].Timestamp, summary.BillingRecords[0].Timestamp); }