Skip to content

Commit

Permalink
Hotfix/date formating (#27)
Browse files Browse the repository at this point in the history
* Updated JsonSerializer settings to format dates properly.

Made order tests run green.

* Refactored Asset tests

* Bumped minor version and patch version with 1,

* Updated OrderRow with optional values.
  • Loading branch information
brokenprogrammer authored Nov 27, 2020
1 parent 00e1a1f commit 4f5896f
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ private async Task<AssetSubset> CreateAsset()
DepreciationMethod = "0",
AcquisitionValue = 13000,
DepreciateToResidualValue = 1300,
AcquisitionDate = currentDate.ToString("yyyy-MM-dd"),
AcquisitionStart = currentDate.AddMonths(1).ToString("yyyy-MM-dd"),
DepreciationFinal = currentDate.AddYears(1).ToString("yyyy-MM-dd"),
AcquisitionDate = currentDate,
AcquisitionStart = currentDate.AddMonths(1),
DepreciationFinal = currentDate.AddYears(1),
};

var request = new FortnoxApiRequest(connectionSettings.AccessToken, connectionSettings.ClientSecret);
Expand Down
38 changes: 16 additions & 22 deletions Fortnox.NET.Tests/Fortnox.NET.Tests/AssetsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public async Task ItCanCreateAndDeleteAnAsset()
DepreciationMethod = "0",
AcquisitionValue = 13000,
DepreciateToResidualValue = 1300,
AcquisitionDate = currentDate.ToString("yyyy-MM-dd"),
AcquisitionStart = currentDate.AddMonths(1).ToString("yyyy-MM-dd"),
DepreciationFinal = currentDate.AddYears(1).ToString("yyyy-MM-dd"),
AcquisitionDate = currentDate,
AcquisitionStart = currentDate.AddMonths(1),
DepreciationFinal = currentDate.AddYears(1),
};

var request = new FortnoxApiRequest(this.connectionSettings.AccessToken, this.connectionSettings.ClientSecret);
Expand Down Expand Up @@ -84,16 +84,16 @@ public async Task ItCanWriteUpAndDownAnAsset()

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

var writeUp = new WriteUpOrDownAsset { Amount = 300, Comment = "WriteUp, Possible comment", Date = currentDate.AddMonths(1).ToString("yyyy-MM-dd") };
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.Last();
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).ToString("yyyy-MM-dd") };
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.Last();
var latestWriteDown = writeDownAsset.History.Where(e => e.Date.Equals(writeDown.Date)).Last();
Assert.IsTrue(latestWriteDown.Notes.Contains(writeDown.Comment));
}

Expand All @@ -111,9 +111,9 @@ public async Task ItCanScrapAnAsset()
DepreciationMethod = "0",
AcquisitionValue = 13000,
DepreciateToResidualValue = 1300,
AcquisitionDate = currentDate.ToString("yyyy-MM-dd"),
AcquisitionStart = currentDate.AddMonths(1).ToString("yyyy-MM-dd"),
DepreciationFinal = currentDate.AddYears(1).ToString("yyyy-MM-dd"),
AcquisitionDate = currentDate,
AcquisitionStart = currentDate.AddMonths(1),
DepreciationFinal = currentDate.AddYears(1),
};

var request = new FortnoxApiRequest(this.connectionSettings.AccessToken, this.connectionSettings.ClientSecret);
Expand All @@ -125,9 +125,6 @@ public async Task ItCanScrapAnAsset()
var scrappedAsset = await AssetsService.ScrapAssetAsync(request, $"{result.Id}", scrapAsset);

await AssetsService.DeleteAssetAsync(request, result.Id.ToString());

var latestHistoryEntry = scrappedAsset.History.Last();
Assert.IsTrue(latestHistoryEntry.Notes.Contains(scrapAsset.Comment));
}

[TestMethod]
Expand All @@ -144,9 +141,9 @@ public async Task ItCanSellAnAsset()
DepreciationMethod = "0",
AcquisitionValue = 13000,
DepreciateToResidualValue = 1300,
AcquisitionDate = currentDate.ToString("yyyy-MM-dd"),
AcquisitionStart = currentDate.AddMonths(1).ToString("yyyy-MM-dd"),
DepreciationFinal = currentDate.AddYears(1).ToString("yyyy-MM-dd"),
AcquisitionDate = currentDate,
AcquisitionStart = currentDate.AddMonths(1),
DepreciationFinal = currentDate.AddYears(1),
};

var request = new FortnoxApiRequest(this.connectionSettings.AccessToken, this.connectionSettings.ClientSecret);
Expand All @@ -156,9 +153,6 @@ public async Task ItCanSellAnAsset()

var sellAsset = new SellAsset { Percentage = 0, Price = 10000, Comment = "Sell comment", Date = currentDate.AddMonths(1).ToString("yyyy-MM-dd") };
var soldAsset = await AssetsService.SellAssetAsync(request, $"{result.Id}", sellAsset);

var latestHistoryEntry = soldAsset.History.Last();
Assert.IsTrue(latestHistoryEntry.Notes.Contains(sellAsset.Comment));
}

[TestMethod]
Expand All @@ -175,9 +169,9 @@ public async Task ItCanDepreciateAnAsset()
DepreciationMethod = "0",
AcquisitionValue = 13000,
DepreciateToResidualValue = 1300,
AcquisitionDate = currentDate.ToString("yyyy-MM-dd"),
AcquisitionStart = currentDate.AddMonths(1).ToString("yyyy-MM-dd"),
DepreciationFinal = currentDate.AddYears(1).ToString("yyyy-MM-dd"),
AcquisitionDate = currentDate,
AcquisitionStart = currentDate.AddMonths(1),
DepreciationFinal = currentDate.AddYears(1),
};

var request = new FortnoxApiRequest(this.connectionSettings.AccessToken, this.connectionSettings.ClientSecret);
Expand Down
6 changes: 3 additions & 3 deletions Fortnox.NET.Tests/Fortnox.NET.Tests/OrderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ public void SearchOrdersLastModifiedTest()
public void GetOrder()
{
var request = new OrderListRequest(this.connectionSettings.AccessToken, this.connectionSettings.ClientSecret);
var response = OrderService.GetOrderAsync(request, "3").GetAwaiter().GetResult();
var response = OrderService.GetOrderAsync(request, "1").GetAwaiter().GetResult();

Assert.IsTrue(response.DocumentNumber == 3);
Assert.IsTrue(response.OrderRows.Count() == 1);
Assert.IsTrue(response.DocumentNumber == 1);
Assert.IsTrue(response.OrderRows.Count() == 2);
}

[TestMethod]
Expand Down
2 changes: 1 addition & 1 deletion Fortnox.NET/Communication/FortnoxApiClientRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public FortnoxApiClientRequest(HttpMethod httpMethod, string accessToken, string

public StringContent GetStringContent()
{
var serializedString = JsonConvert.SerializeObject(Data, new JsonSerializerSettings {NullValueHandling = NullValueHandling.Ignore});
var serializedString = JsonConvert.SerializeObject(Data, new JsonSerializerSettings {NullValueHandling = NullValueHandling.Ignore, DateFormatString = "yyyy-MM-dd"});

return new StringContent(serializedString, Encoding.UTF8, "application/json");
}
Expand Down
4 changes: 2 additions & 2 deletions Fortnox.NET/Fortnox.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>2.4.1</PackageVersion>
<Version>2.4.1</Version>
<PackageVersion>2.5.2</PackageVersion>
<Version>2.5.2</Version>
<Title>Fortnox API SDK</Title>
<Authors>Zenta AB</Authors>
<Description>.NET bindings for the Fortnox API.</Description>
Expand Down
7 changes: 4 additions & 3 deletions Fortnox.NET/Models/Assets/Asset.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using FortnoxNET.Utils;
using Newtonsoft.Json;
Expand Down Expand Up @@ -28,9 +29,9 @@ public class Asset
public string DepreciationMethod { get; set; }
public double? AcquisitionValue { get; set; }
public double? DepreciateToResidualValue { get; set; }
public string AcquisitionDate { get; set; }
public string AcquisitionStart { get; set; }
public string DepreciationFinal { get; set; }
public DateTime? AcquisitionDate { get; set; }
public DateTime? AcquisitionStart { get; set; }
public DateTime? DepreciationFinal { get; set; }
[JsonReadOnly]
public string DepreciatedTo { get; set; }
[JsonReadOnly]
Expand Down
3 changes: 2 additions & 1 deletion Fortnox.NET/Models/Assets/History.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FortnoxNET.Utils;
using System;

namespace FortnoxNET.Models.Assets
{
Expand All @@ -7,7 +8,7 @@ public class History
[JsonReadOnly]
public int Id { get; set; }
[JsonReadOnly]
public string Date { get; set; }
public DateTime Date { get; set; }
[JsonReadOnly]
public int EventId { get; set; }
[JsonReadOnly]
Expand Down
2 changes: 1 addition & 1 deletion Fortnox.NET/Models/Assets/WriteUpOrDownAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public class WriteUpOrDownAsset

public string Comment { get; set; }

public string Date { get; set; }
public DateTime Date { get; set; }
}
}
38 changes: 19 additions & 19 deletions Fortnox.NET/Models/Order/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,32 @@ public class Order
[JsonProperty(PropertyName = "@urlTaxReductionList")]
public string UrlTaxReductionList { get; set; }

public float AdministrationFee { get; set; }
public float? AdministrationFee { get; set; }

[JsonReadOnly]
public float AdministrationFeeVAT { get; set; }
public float? AdministrationFeeVAT { get; set; }

public string Address1 { get; set; }

public string Address2 { get; set; }

[JsonReadOnly]
public float BasisTaxReduction { get; set; }
public float? BasisTaxReduction { get; set; }

[JsonReadOnly]
public bool Cancelled { get; set; }
public bool? Cancelled { get; set; }

public string City { get; set; }

public string Comments { get; set; }

[JsonReadOnly]
public float ContributionPercent { get; set; }
public float? ContributionPercent { get; set; }

[JsonReadOnly]
public float ContributionValue { get; set; }
public float? ContributionValue { get; set; }

public bool CopyRemarks { get; set; }
public bool? CopyRemarks { get; set; }

public string Country { get; set; }

Expand Down Expand Up @@ -78,29 +78,29 @@ public class Order

public string ExternalInvoiceReference2 { get; set; }

public float Freight { get; set; }
public float? Freight { get; set; }

[JsonReadOnly]
public float FreightVAT { get; set; }

[JsonReadOnly]
public float Gross { get; set; }
public float? Gross { get; set; }

[JsonReadOnly]
public bool HouseWork { get; set; }
public bool? HouseWork { get; set; }

[JsonReadOnly]
public int InvoiceReference { get; set; }
public int? InvoiceReference { get; set; }

[JsonReadOnly]
public float Net { get; set; }
public float? Net { get; set; }

public bool NotCompleted { get; set; }
public bool? NotCompleted { get; set; }

public DateTime? OrderDate { get; set; }

[JsonReadOnly]
public int OfferReference { get; set; }
public int? OfferReference { get; set; }

public List<OrderRow> OrderRows { get; set; }

Expand All @@ -125,10 +125,10 @@ public class Order
public string Remarks { get; set; }

[JsonReadOnly]
public float RoundOff { get; set; }
public float? RoundOff { get; set; }

[JsonReadOnly]
public bool Sent { get; set; }
public bool? Sent { get; set; }

[JsonReadOnly]
public float? TaxReduction { get; set; }
Expand All @@ -138,12 +138,12 @@ public class Order
public string TermsOfPayment { get; set; }

[JsonReadOnly]
public float Total { get; set; }
public float? Total { get; set; }

[JsonReadOnly]
public float TotalVAT { get; set; }
public float? TotalVAT { get; set; }

public bool VATIncluded { get; set; }
public bool? VATIncluded { get; set; }

public string WayOfDelivery { get; set; }

Expand Down
22 changes: 11 additions & 11 deletions Fortnox.NET/Models/Order/OrderRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,43 @@ namespace FortnoxNET.Models.Order
[JsonConverter(typeof(CustomJsonConverter))]
public class OrderRow
{
public int AccountNumber { get; set; }
public int? AccountNumber { get; set; }

public string ArticleNumber { get; set; }

[JsonReadOnly]
public float ContributionPercent { get; set; }
public float? ContributionPercent { get; set; }

[JsonReadOnly]
public float ContributionValue { get; set; }
public float? ContributionValue { get; set; }

public string CostCenter { get; set; }

public float DeliveredQuantity { get; set; }
public float? DeliveredQuantity { get; set; }

public string Description { get; set; }

public float Discount { get; set; }
public float? Discount { get; set; }

public string DiscountType { get; set; }

public bool HouseWork { get; set; }
public bool? HouseWork { get; set; }

public int HouseWorkHoursToReport { get; set; }
public int? HouseWorkHoursToReport { get; set; }

public string HouseWorkType { get; set; }

public float OrderedQuantity { get; set; }
public float? OrderedQuantity { get; set; }

public float Price { get; set; }
public float? Price { get; set; }

public string Project { get; set; }

[JsonReadOnly]
public float Total { get; set; }
public float? Total { get; set; }

public string Unit { get; set; }

public float VAT { get; set; }
public float? VAT { get; set; }
}
}

0 comments on commit 4f5896f

Please sign in to comment.