Example #1
0
        public async Task ItCanWriteUpAndDownAnAsset()
        {
            var currentDate = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 1);
            var request     = new FortnoxApiRequest(this.connectionSettings.AccessToken, this.connectionSettings.ClientSecret);
            var result      = await AssetsService.GetAssetAsync(request, "4");

            Assert.AreEqual("2", result.Number);

            var writeUp = new WriteUpOrDownAsset {
                Amount = 300, Comment = "WriteUp, Possible comment", Date = currentDate.AddMonths(1)
            };
            var writeUpAsset = await AssetsService.WriteUpAssetAsync(request, $"{result.Id}", writeUp);

            var latestWriteUp = writeUpAsset.History.Where(e => e.Date.Equals(writeUp.Date)).First();

            Assert.IsTrue(latestWriteUp.Notes.Contains(writeUp.Comment));

            var writeDown = new WriteUpOrDownAsset {
                Amount = 200, Comment = "WriteDown, Possible comment", Date = currentDate.AddMonths(1)
            };
            var writeDownAsset = await AssetsService.WriteDownAssetAsync(request, $"{result.Id}", writeDown);

            var latestWriteDown = writeDownAsset.History.Where(e => e.Date.Equals(writeDown.Date)).Last();

            Assert.IsTrue(latestWriteDown.Notes.Contains(writeDown.Comment));
        }
Example #2
0
        public static async Task <Asset> WriteUpAssetAsync(FortnoxApiRequest request, string identifier, WriteUpOrDownAsset asset)
        {
            var apiRequest = new FortnoxApiClientRequest <SingleResource <WriteUpOrDownAsset> >(
                HttpMethod.Put,
                request.AccessToken,
                request.ClientSecret,
                $"{ApiEndpoints.Assets}/writeup/{identifier}"
                )
            {
                Data = new SingleResource <WriteUpOrDownAsset> {
                    Data = asset
                }
            };

            return((await FortnoxAPIClient.CallAsync <SingleResource <WriteUpOrDownAsset>, SingleResource <Asset> >(apiRequest)).Data);
        }