示例#1
0
        public async Task ItCanCreateAConnectionForAFile()
        {
            var fileId = await CreateFile();

            var articles = await GetArticles();

            var article = articles.FirstOrDefault() ?? await CreateArticle();

            var request = new FortnoxApiRequest(connectionSettings.AccessToken, connectionSettings.ClientSecret);

            try
            {
                var response = await ArticleFileConnectionService.CreateArticleFileConnection(
                    request,
                    article.ArticleNumber,
                    fileId
                    );

                await DeleteConnection(fileId);

                Assert.IsNotNull(response);
                Assert.AreEqual(fileId, response.FileId);
                Assert.AreEqual(article.ArticleNumber, response.ArticleNumber);
            }
            finally
            {
                await DeleteFile(fileId);

                if (!articles.Any())
                {
                    await DeleteArticle(article.ArticleNumber);
                }
            }
        }
示例#2
0
        public async Task ItCanGetConnectionsForManyFiles()
        {
            var request  = new ArticleFileConnectionListRequest(connectionSettings.AccessToken, connectionSettings.ClientSecret);
            var response = await ArticleFileConnectionService.GetArticleFileConnectionsAsync(request);

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Data);
        }
示例#3
0
        private async Task <ArticleFileConnection> CreateConnection()
        {
            var fileId = await CreateFile();

            var articles = await GetArticles();

            var article = articles.FirstOrDefault() ?? await CreateArticle();

            var request = new FortnoxApiRequest(connectionSettings.AccessToken, connectionSettings.ClientSecret);

            return(await ArticleFileConnectionService.CreateArticleFileConnection(
                       request,
                       article.ArticleNumber,
                       fileId
                       ));
        }
示例#4
0
        public async Task ItCanGetConnectionsForAFile()
        {
            var fileConnections = await GetConnections();

            if (fileConnections == null || !fileConnections.Any())
            {
                Assert.Inconclusive("No connection exist between any article to any file in the system");
                return;
            }

            var request  = new ArticleFileConnectionListRequest(connectionSettings.AccessToken, connectionSettings.ClientSecret);
            var response = await ArticleFileConnectionService.GetArticleFileConnectionAsync(
                request,
                fileConnections.First().FileId
                );

            Assert.IsNotNull(response);
            Assert.AreEqual(fileConnections.First().FileId, response.FileId);
        }
示例#5
0
        public async Task ItCanDeleteAConnectionForAFile()
        {
            var initialConnections = await GetConnections();

            var articleFileConnection = await CreateConnection();

            try
            {
                var deleteRequest = new FortnoxApiRequest(connectionSettings.AccessToken, connectionSettings.ClientSecret);
                await ArticleFileConnectionService.DeleteArticleFileConnection(deleteRequest, articleFileConnection.FileId);

                var getConnectionRequest = new ArticleFileConnectionListRequest(
                    connectionSettings.AccessToken,
                    connectionSettings.ClientSecret
                    );

                if (initialConnections.Count < 1)
                {
                    await Assert.ThrowsExceptionAsync <Exception>(async() =>
                                                                  await ArticleFileConnectionService.GetArticleFileConnectionAsync(
                                                                      getConnectionRequest,
                                                                      articleFileConnection.FileId
                                                                      )
                                                                  );
                }
                else
                {
                    var currentConnections = await GetConnections();

                    Assert.AreEqual(initialConnections.Count, currentConnections.Count);
                }
            }
            finally
            {
                await DeleteFile(articleFileConnection.FileId);
            }
        }
示例#6
0
 private async Task DeleteConnection(string fileId)
 {
     var request = new FortnoxApiRequest(connectionSettings.AccessToken, connectionSettings.ClientSecret);
     await ArticleFileConnectionService.DeleteArticleFileConnection(request, fileId);
 }
示例#7
0
        private async Task <List <ArticleFileConnections> > GetConnections()
        {
            var request = new ArticleFileConnectionListRequest(connectionSettings.AccessToken, connectionSettings.ClientSecret);

            return((await ArticleFileConnectionService.GetArticleFileConnectionsAsync(request)).Data.ToList());
        }