コード例 #1
0
        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);
                    });

            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);
                });
            }
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
        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);
            }
        }
コード例 #11
0
        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);
                }
            }
        }
コード例 #12
0
        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"));
            }
        }
コード例 #13
0
        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);
            }
        }
コード例 #14
0
        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);
                }
            }
        }
コード例 #15
0
        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);
                }
            }
        }
コード例 #16
0
        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);
            }
        }
コード例 #17
0
        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"));
            }
        }
コード例 #18
0
        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);
                }
            }
        }
コード例 #19
0
        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);
            }
        }
コード例 #20
0
        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);
            }
        }
コード例 #21
0
        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);
            }
        }
コード例 #22
0
        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);
            }
        }
コード例 #23
0
        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);
            }
        }
コード例 #24
0
        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);
            }
        }
コード例 #25
0
        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);
            }
        }