public void WhenSendingRequest__ThenMustTimeout() { using (SimpleServer.Create(TestHelpers.BaseUrl, c => { Task.Delay(2000).Wait(); c.Response.Close(); })) { YouScribeClient.DefaultTimeout = TimeSpan.FromMilliseconds(200); var client = new YouScribeClient(TestHelpers.BaseUrl); var ex = Assert.Throws<AggregateException>(() => { client.AuthorizeAsync("test", "password").Wait(); var request = client.CreateProductRequest(); // Act var response = request.GetRightAsync(42).Result; // Assert Assert.Equal(110, response); }); } }
public void WhenUpdateDocumentFromFile_ThenCheckResponse() { // Arrange using (SimpleServer.Create(TestHelpers.BaseUrl, ProductRequestHandler)) { var client = new YouScribeClient(TestHelpers.BaseUrl); client.AuthorizeAsync("test", "password").Wait(); var request = client.CreateProductRequest(); // Act bool ok = request.UpdateDocumentAsync(42, new Models.Products.ProductUpdateModel { Description = "ok" }, new[] { new YouScribe.Rest.Models.FileModel { Content = new MemoryStream(), FileName = "test2.pdf", ContentType = "application/pdf" } }).Result; // Assert Assert.True(ok); } }
public void WhenSendingRequest__ThenMustTimeout() { using (SimpleServer.Create(TestHelpers.BaseUrl, c => { Task.Delay(2000).Wait(); c.Response.Close(); })) { YouScribeClient.DefaultTimeout = TimeSpan.FromMilliseconds(200); var client = new YouScribeClient(TestHelpers.BaseUrl); var ex = Assert.Throws <AggregateException>(() => { client.AuthorizeAsync("test", "password").Wait(); var request = client.CreateProductRequest(); // Act var response = request.GetRightAsync(42).Result; // Assert Assert.Equal(110, response); }); } }
public void WhenPublishDocumentFromUrl_ThenCheckResponse() { // Arrange using (SimpleServer.Create(TestHelpers.BaseUrl, ProductRequestHandler)) { var client = new YouScribeClient(TestHelpers.BaseUrl); client.AuthorizeAsync("test", "password").Wait(); var request = client.CreateProductRequest(); // Act var product = request.PublishDocumentAsync(new Models.Products.ProductModel { Title = "my document title" }, new[] { new Uri("http://exemple.com/test.pdf") }).Result; // Assert Assert.NotNull(product); Assert.Equal(42, product.Id); Assert.Equal("my document title", product.Title); Assert.Equal("{\"Id\":0,\"Title\":\"my document title\",\"Description\":null,\"Collection\":null,\"PublishDate\":null,\"EAN13\":null,\"Public\":true,\"IsFree\":true,\"Price\":null,\"People\":null,\"Languages\":null,\"Tags\":null,\"CategoryId\":0,\"ThemeId\":0,\"AllowPasteAndCut\":false,\"AllowPrint\":false,\"AllowPrintOnDemand\":false,\"AllowDownload\":true,\"AllowStreaming\":true,\"IsAdultContent\":false,\"PreviewNbPage\":null,\"PreviewPercentPage\":null,\"PreviewRange\":null,\"CopyrightInformation\":0,\"LicenceName\":null}", requestContent); } }
public void WhenDownloadProductFromExtension2_ThenCheckResponse() { // Arrange using (SimpleServer.Create(TestHelpers.BaseUrl, ProductRequestHandler)) { var client = new YouScribeClient(TestHelpers.BaseUrl); var request = client.CreateProductRequest(); // Act var response = request.PostEncryptedKeyByExtension(1, "pdf", "toto").Result; // Assert Assert.NotNull(response); } }
public void WhenGettingProduct_ThenCheckResponse() { using (SimpleServer.Create(TestHelpers.BaseUrl, ProductRequestHandler)) { var client = new YouScribeClient(TestHelpers.BaseUrl); var request = client.CreateProductRequest(); // Act var response = request.GetAsync(410710).Result; Assert.NotNull(response); Assert.Equal("bouh", response.Title); } }
public void WhenGettingProducts_ThenCheckResponse() { using (SimpleServer.Create(TestHelpers.BaseUrl, ProductRequestHandler)) { var client = new YouScribeClient(TestHelpers.BaseUrl); var request = client.CreateProductRequest(); // Act var response = request.GetAsync(new List <int>() { 410710, 410711 }).Result; Assert.Equal("[410710,410711]", requestContent); } }
public void WhenCheckForProductRight_ThenCheckResponse() { // Arrange using (SimpleServer.Create(TestHelpers.BaseUrl, ProductRequestHandler)) { var client = new YouScribeClient(TestHelpers.BaseUrl); client.AuthorizeAsync("test", "password").Wait(); var request = client.CreateProductRequest(); // Act var response = request.GetRightAsync(42).Result; // Assert Assert.Equal(110, response); } }
public void WhenUpdateDocumentThumbnailFromPage_ThenCheckResponse() { // Arrange using (SimpleServer.Create(TestHelpers.BaseUrl, ProductRequestHandler)) { var client = new YouScribeClient(TestHelpers.BaseUrl); client.AuthorizeAsync("test", "password").Wait(); var request = client.CreateProductRequest(); // Act bool ok = request.UpdateDocumentThumbnailAsync(42, 2).Result; // Assert Assert.True(ok); } }
public void WhenDownloadProductExtractToStreamFromExtension_ThenCheckResponse() { // Arrange using (SimpleServer.Create(TestHelpers.BaseUrl, ProductRequestHandler)) { var client = new YouScribeClient(TestHelpers.BaseUrl); client.AuthorizeAsync("test", "password").Wait(); var request = client.CreateProductRequest(); // Act // Assert using (var stream = new MemoryStream()) { request.DownloadExtractToStreamAsync(43, 1, stream, new Progress <DownloadBytesProgress>()).Wait(); Assert.Equal(57210, stream.Length); } } }
public void WhenGettingProductsUrls_ThenCheckResponse() { using (SimpleServer.Create(TestHelpers.BaseUrl, ProductRequestHandler)) { var client = new YouScribeClient(TestHelpers.BaseUrl); var request = client.CreateProductRequest(); // Act var response = request.GetProductUrlsAsync(new List <int>() { 410820, 410821 }).Result; Assert.Equal(410820, response.First().Id); Assert.Equal(true, response.First().Url.Contains("410820")); Assert.Equal(410821, response.Last().Id); Assert.Equal(true, response.Last().Url.Contains("410821")); } }
public void WhenUpdateDocumentThumbnailFromFile_ThenCheckResponse() { // Arrange using (SimpleServer.Create(TestHelpers.BaseUrl, ProductRequestHandler)) { var client = new YouScribeClient(TestHelpers.BaseUrl); client.AuthorizeAsync("test", "password").Wait(); var request = client.CreateProductRequest(); // Act bool ok = request.UpdateDocumentThumbnailAsync(42, new YouScribe.Rest.Models.FileModel { Content = new MemoryStream(), FileName = "image.jpg", ContentType = "image/jpg" }).Result; // Assert Assert.True(ok); } }
public void WhenDownloadProductExtractFromFormatTypeId_ThenCheckResponse() { // Arrange using (SimpleServer.Create(TestHelpers.BaseUrl, ProductRequestHandler)) { var client = new YouScribeClient(TestHelpers.BaseUrl); client.AuthorizeAsync("test", "password").Wait(); var request = client.CreateProductRequest(); // Act var response = request.DownloadExtractAsync(43, 1).Result; // Assert Assert.NotNull(response); using (var stream = new MemoryStream()) { response.CopyTo(stream); Assert.Equal(57210, stream.Length); } } }
public void WhenDownloadProductExtractFromExtension_ThenCheckResponse() { // Arrange using (SimpleServer.Create(TestHelpers.BaseUrl, ProductRequestHandler)) { var client = new YouScribeClient(TestHelpers.BaseUrl); client.AuthorizeAsync("test", "password").Wait(); var request = client.CreateProductRequest(); // Act var response = request.DownloadExtractAsync(43, "pdf").Result; // Assert Assert.NotNull(response); using (var stream = new MemoryStream()) { response.CopyTo(stream); Assert.Equal(57210, stream.Length); } } }
public void WhenUpdateDocumentFromUrl_ThenCheckResponse() { // Arrange using (SimpleServer.Create(TestHelpers.BaseUrl, ProductRequestHandler)) { var client = new YouScribeClient(TestHelpers.BaseUrl); client.AuthorizeAsync("test", "password").Wait(); var request = client.CreateProductRequest(); // Act bool ok = request.UpdateDocumentAsync(42, new Models.Products.ProductUpdateModel { Description = "ok" }, new[] { new Uri("http://exemple.com/test2.pdf") }).Result; // Assert Assert.True(ok); } }
public void WhenGettingProductsUrls_ThenCheckResponse() { using (SimpleServer.Create(TestHelpers.BaseUrl, ProductRequestHandler)) { var client = new YouScribeClient(TestHelpers.BaseUrl); var request = client.CreateProductRequest(); // Act var response = request.GetProductUrlsAsync(new List<int>() { 410820, 410821 }).Result; Assert.Equal(410820, response.First().Id); Assert.Equal(true, response.First().Url.Contains("410820")); Assert.Equal(410821, response.Last().Id); Assert.Equal(true, response.Last().Url.Contains("410821")); } }
public void WhenDownloadProductToStreamFromFormatTypeId_ThenCheckResponse() { // Arrange using (SimpleServer.Create(TestHelpers.BaseUrl, ProductRequestHandler)) { var client = new YouScribeClient(TestHelpers.BaseUrl); client.AuthorizeAsync("test", "password").Wait(); var request = client.CreateProductRequest(); // Act // Assert using (var stream = new MemoryStream()) { request.DownloadFileToStreamAsync(42, "pdf", stream, new Progress<DownloadBytesProgress>()).Wait(); Assert.Equal(57210, stream.Length); } } }
public void WhenUpdateDocumentThumbnailFromUrl_ThenCheckResponse() { // Arrange using (SimpleServer.Create(TestHelpers.BaseUrl, ProductRequestHandler)) { var client = new YouScribeClient(TestHelpers.BaseUrl); client.AuthorizeAsync("test", "password").Wait(); var request = client.CreateProductRequest(); // Act bool ok = request.UpdateDocumentThumbnailAsync(42, new Uri("http://exemple.com/thumbnail.png")).Result; // Assert Assert.True(ok); } }
public void WhenGettingProducts_ThenCheckResponse() { using (SimpleServer.Create(TestHelpers.BaseUrl, ProductRequestHandler)) { var client = new YouScribeClient(TestHelpers.BaseUrl); var request = client.CreateProductRequest(); // Act var response = request.GetAsync(new List<int>(){ 410710, 410711 }).Result; Assert.Equal("[410710,410711]", requestContent); } }
public void WhenUpdateDocumentFromFile_ThenCheckResponse() { // Arrange using (SimpleServer.Create(TestHelpers.BaseUrl, ProductRequestHandler)) { var client = new YouScribeClient(TestHelpers.BaseUrl); client.AuthorizeAsync("test", "password").Wait(); var request = client.CreateProductRequest(); // Act bool ok = request.UpdateDocumentAsync(42, new Models.Products.ProductUpdateModel { Description = "ok" }, new[] { new YouScribe.Rest.Models.FileModel { Content = new MemoryStream(), FileName ="test2.pdf", ContentType = "application/pdf" } }).Result; // Assert Assert.True(ok); } }