コード例 #1
0
        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));
        }
コード例 #2
0
        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); });
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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(); });
        }
コード例 #5
0
        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"));
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        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); });
        }
コード例 #8
0
        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"));
        }
コード例 #9
0
        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"); });
        }
コード例 #10
0
        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");
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        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);
        }