public void Url_Signed_Without_priavteKey() { ClientImagekit imagekit1 = new ClientImagekit(GOOD_PUBLICKEY, URLENDPOINT) .Path(SAMPLE_PATH).Signed(true).ExpireSeconds(300); var ex = Assert.Throws <ArgumentNullException>(() => imagekit1.Url(new Transformation()).Path(SAMPLE_PATH).Signed(true).ExpireSeconds(300).Generate()); Assert.Equal(errorMessages.PRIVATE_KEY_MISSING, ex.ParamName); }
public void Upload_Exception() { var fileName = Guid.NewGuid().ToString(); var auth = TestHelpers.AuthParamResponseFaker.Generate(); var imagekit = new ClientImagekit(GOOD_PUBLICKEY, GOOD_URLENDPOINT); var ex = Assert.ThrowsAsync <ArgumentException>(async() => await imagekit.UploadAsync("", auth)); Assert.Equal(Util.errorMessages.MISSING_UPLOAD_FILE_PARAMETER, ex.Result.Message); }
public void Constructor_TransformationPosition(string transformationPosition, bool expectException) { if (expectException) { var ex = Assert.Throws <ArgumentException>(() => new ClientImagekit(GOOD_PUBLICKEY, GOOD_URLENDPOINT, transformationPosition)); Assert.Equal("transformationPosition", ex.ParamName); } else { var imagekit = new ClientImagekit(GOOD_PUBLICKEY, GOOD_URLENDPOINT, transformationPosition); Assert.NotNull(imagekit); } }
public void Constructor_Required( string paramUnderTest, string publicKey, string urlEndpoint, string transformationPosition, bool expectException ) { if (expectException) { var ex = Assert.Throws <ArgumentNullException>(() => new ClientImagekit(publicKey, urlEndpoint, transformationPosition)); Assert.Equal(paramUnderTest, ex.ParamName); } else { var imagekit = new ClientImagekit(publicKey, urlEndpoint, transformationPosition); Assert.NotNull(imagekit); } }
public void Upload() { var fileName = Guid.NewGuid().ToString(); var fileUrl = "https://test.com/test.png"; var auth = TestHelpers.AuthParamResponseFaker.Generate(); var responseObj = TestHelpers.ImagekitResponseFaker.Generate(); var httpResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(responseObj)) }; var httpClient = TestHelpers.GetTestHttpClient(httpResponse, TestHelpers.GetUploadRequestMessageValidator(fileUrl, fileName, publicKey: GOOD_PUBLICKEY, clientAuth: auth)); Util.Utils.SetHttpClient(httpClient); var imagekit = new ClientImagekit(GOOD_PUBLICKEY, GOOD_URLENDPOINT) .FileName(fileName); var response = imagekit.Upload(fileUrl, auth); Assert.Equal(JsonConvert.SerializeObject(responseObj), JsonConvert.SerializeObject(response)); }
public void UploadBytes() { var fileName = Guid.NewGuid().ToString(); string base64 = "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="; byte[] bytes = Convert.FromBase64String(base64); var auth = TestHelpers.AuthParamResponseFaker.Generate(); var responseObj = TestHelpers.ImagekitResponseFaker.Generate(); var httpResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(responseObj)) }; var httpClient = TestHelpers.GetTestHttpClient(httpResponse, TestHelpers.GetUploadRequestMessageValidator(base64, fileName, publicKey: GOOD_PUBLICKEY, clientAuth: auth)); Util.Utils.SetHttpClient(httpClient); var imagekit = new ClientImagekit(GOOD_PUBLICKEY, GOOD_URLENDPOINT) .FileName(fileName); var response = imagekit.Upload(bytes, auth); Assert.Equal(JsonConvert.SerializeObject(responseObj), JsonConvert.SerializeObject(response)); }
public void Constructor_TransformationPosition_Default() { var imagekit = new ClientImagekit(GOOD_PUBLICKEY, GOOD_URLENDPOINT); Assert.NotNull(imagekit); }