Skip to content

Commit

Permalink
Merge pull request #304 from DevelappersGmbH/feature/InvoiceItemType
Browse files Browse the repository at this point in the history
Updated Newtonsoft.Json
implemented ItemType for invoices, articles and offers
  • Loading branch information
martinhey committed Dec 15, 2023
2 parents d0a628e + 8d2f3d5 commit d38245c
Show file tree
Hide file tree
Showing 19 changed files with 265 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-core-build-and-test-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
dotnet-version: 6.0.x
- name: Install dependencies
run: dotnet restore
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-core-build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
dotnet-version: 6.0.x
- name: Install dependencies
run: dotnet restore
- name: Build
Expand Down
4 changes: 2 additions & 2 deletions BillomatNet.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30225.117
# Visual Studio Version 17
VisualStudioVersion = 17.8.34330.188
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Develappers.BillomatNet", "Develappers.BillomatNet\Develappers.BillomatNet.csproj", "{A016C0C2-E31A-4DE1-B02D-9AE752FDFE54}"
EndProject
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand All @@ -14,7 +14,7 @@
<PackageReference Include="FakeItEasy" Version="6.2.1" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Threading.Tasks;
using Develappers.BillomatNet.Types;
using FluentAssertions;
using Xunit;

namespace Develappers.BillomatNet.Tests.IntegrationTests
{
public class OfferServiceItemsIntegrationTests : IntegrationTestBase<OfferService>
{
private static BillomatClient _client;

public OfferServiceItemsIntegrationTests() : base(c =>
{
_client = new BillomatClient(c);
return _client.Offers;
})
{
}

[Fact]
public async Task GetOfferItemById()
{
var result = await SystemUnderTest.GetItemByIdAsync(6809664);
Assert.NotNull(result);
}

[Fact]
public async Task GetItemListOfOffer()
{
var result = await SystemUnderTest.GetItemsAsync(1376503);

var expectedResults = new List<OfferItem>
{
new()
{
Id = 6809664,
ArticleId = null,
OfferId = 1376503,
Position = 1,
Unit = "apfel",
Quantity = 1,
Type = ItemType.Product,
UnitPrice = 100,
TaxName = "MwSt",
TaxRate = 19,
Title = "test1",
Description = "test2",
TotalNet = 100,
TotalGross = 119,
Reduction = null,
TotalNetUnreduced = 100,
TotalGrossUnreduced = 119
},
new()
{
Id = 6809666,
ArticleId = 154124,
OfferId = 1376503,
Position = 2,
Unit = "Beutel",
Quantity = 1,
Type = ItemType.Service,
UnitPrice = 2,
TaxName = "MwSt",
TaxRate = 19,
Title = "Net Purchase",
Description = "Uhb",
TotalNet = 2,
TotalGross = 2.38f,
Reduction = null,
TotalNetUnreduced = 2,
TotalGrossUnreduced = 2.38f
}
};

result.TotalItems.Should().Be(2);
result.List.Should().SatisfyRespectively(
first => first.Should().BeEquivalentTo(expectedResults[0]),
second => second.Should().BeEquivalentTo(expectedResults[1]));
}
}
}
11 changes: 8 additions & 3 deletions Develappers.BillomatNet.Tests/UnitTests/ArticleServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public async Task CreateArticle_WithValidInputValue_ShouldCreateArticleAndReturn

const string expectedUri = "/api/articles";
const string expectedHttpRequest =
"{\"article\":{\"id\":\"0\",\"created\":\"0001-01-01\",\"number\":\"\",\"number_length\":\"0\",\"title\":\"xUnit test\",\"sales_price\":\"3.5\",\"unit_id\":\"20573\",\"tax_id\":\"21281\",\"purchase_price\":\"3.4\",\"purchase_price_net_gross\":\"NET\",\"supplier_id\":\"\"}}";
"{\"article\":{\"id\":\"0\",\"created\":\"0001-01-01\",\"number\":\"\",\"number_length\":\"0\",\"title\":\"xUnit test\",\"sales_price\":\"3.5\",\"unit_id\":\"20573\",\"tax_id\":\"21281\",\"purchase_price\":\"3.4\",\"purchase_price_net_gross\":\"NET\",\"supplier_id\":\"\",\"type\":\"\",\"cost_center\":\"Ib34\"}}";
const string httpResult =
"{\"article\":{\"id\":\"842769\",\"created\":\"2020-07-28T18:32:05+02:00\",\"updated\":\"2020-07-28T18:32:05+02:00\",\"archived\":\"0\",\"unit_id\":\"20573\",\"article_number\":\"5\",\"number\":\"5\",\"number_pre\":\"\",\"number_length\":\"0\",\"type\":\"SERVICE\",\"title\":\"xUnit test\",\"description\":\"\",\"sales_price\":\"3.5\",\"sales_price2\":\"\",\"sales_price3\":\"\",\"sales_price4\":\"\",\"sales_price5\":\"\",\"currency_code\":\"EUR\",\"tax_id\":\"21281\",\"revenue_account_number\":\"\",\"cost_center\":\"\",\"purchase_price\":\"3.4\",\"purchase_price_net_gross\":\"NET\",\"supplier_id\":\"\",\"customfield\":\"\",\"article-property-values\":{\"article-property-value\":[{\"id\":\"1423686\",\"created\":\"2020-07-28T18:32:05+02:00\",\"updated\":\"2020-07-28T18:32:05+02:00\",\"article_id\":\"842769\",\"article_property_id\":\"2442\",\"type\":\"TEXTFIELD\",\"name\":\"Farbe\",\"value\":\"farblos\",\"customfield\":\"\"},{\"id\":\"1423687\",\"created\":\"2020-07-28T18:32:05+02:00\",\"updated\":\"2020-07-28T18:32:05+02:00\",\"article_id\":\"842769\",\"article_property_id\":\"2490\",\"type\":\"CHECKBOX\",\"name\":\"ist defekt?\",\"value\":\"1\",\"customfield\":\"\"},{\"id\":\"1423688\",\"created\":\"2020-07-28T18:32:05+02:00\",\"updated\":\"2020-07-28T18:32:05+02:00\",\"article_id\":\"842769\",\"article_property_id\":\"4499\",\"type\":\"CHECKBOX\",\"name\":\"Sch\\u00f6n\",\"value\":\"0\",\"customfield\":\"\"}]}}}";
"{\"article\":{\"id\":\"842769\",\"created\":\"2020-07-28T18:32:05+02:00\",\"updated\":\"2020-07-28T18:32:05+02:00\",\"archived\":\"0\",\"unit_id\":\"20573\",\"article_number\":\"5\",\"number\":\"5\",\"number_pre\":\"\",\"number_length\":\"0\",\"type\":\"SERVICE\",\"title\":\"xUnit test\",\"description\":\"\",\"sales_price\":\"3.5\",\"sales_price2\":\"\",\"sales_price3\":\"\",\"sales_price4\":\"\",\"sales_price5\":\"\",\"currency_code\":\"EUR\",\"tax_id\":\"21281\",\"revenue_account_number\":\"\",\"cost_center\":\"Ib34\",\"purchase_price\":\"3.4\",\"purchase_price_net_gross\":\"NET\",\"supplier_id\":\"\",\"customfield\":\"\",\"article-property-values\":{\"article-property-value\":[{\"id\":\"1423686\",\"created\":\"2020-07-28T18:32:05+02:00\",\"updated\":\"2020-07-28T18:32:05+02:00\",\"article_id\":\"842769\",\"article_property_id\":\"2442\",\"type\":\"TEXTFIELD\",\"name\":\"Farbe\",\"value\":\"farblos\",\"customfield\":\"\"},{\"id\":\"1423687\",\"created\":\"2020-07-28T18:32:05+02:00\",\"updated\":\"2020-07-28T18:32:05+02:00\",\"article_id\":\"842769\",\"article_property_id\":\"2490\",\"type\":\"CHECKBOX\",\"name\":\"ist defekt?\",\"value\":\"1\",\"customfield\":\"\"},{\"id\":\"1423688\",\"created\":\"2020-07-28T18:32:05+02:00\",\"updated\":\"2020-07-28T18:32:05+02:00\",\"article_id\":\"842769\",\"article_property_id\":\"4499\",\"type\":\"CHECKBOX\",\"name\":\"Sch\\u00f6n\",\"value\":\"0\",\"customfield\":\"\"}]}}}";

A.CallTo(() => http.PostAsync(new Uri(expectedUri, UriKind.Relative), expectedHttpRequest,
A<CancellationToken>.Ignored))
Expand All @@ -82,7 +82,8 @@ public async Task CreateArticle_WithValidInputValue_ShouldCreateArticleAndReturn
SalesPrice = 3.5f,
UnitId = 20573,
TaxId = 21281,
PurchasePrice = 3.4f
PurchasePrice = 3.4f,
CostCenter = "Ib34"
};

// act
Expand Down Expand Up @@ -257,6 +258,7 @@ public async Task GetArticleById_WithValidData_ShouldReturnCorrectValues()
Updated = DateTime.Parse("2020-07-10T12:20:36+02:00", CultureInfo.InvariantCulture),
UnitId = 20574,
ArticleNumber = "ART3",
CostCenter = "",
Number = 3,
NumberPrefix = "ART",
NumberLength = 0,
Expand Down Expand Up @@ -304,6 +306,7 @@ public async Task GetList_ShouldReturnCorrectValues()
Updated = DateTime.Parse("2017-07-22T13:57:37+02:00", CultureInfo.InvariantCulture),
UnitId = null,
ArticleNumber = "ART62",
CostCenter = "",
Number = 62,
NumberPrefix = "ART",
NumberLength = 0,
Expand All @@ -326,6 +329,7 @@ public async Task GetList_ShouldReturnCorrectValues()
Updated = DateTime.Parse("2020-07-10T12:20:36+02:00", CultureInfo.InvariantCulture),
UnitId = null,
ArticleNumber = "ART63",
CostCenter = "",
Number = 63,
NumberPrefix = "ART",
NumberLength = 0,
Expand All @@ -348,6 +352,7 @@ public async Task GetList_ShouldReturnCorrectValues()
Updated = DateTime.Parse("2020-07-10T12:20:36+02:00", CultureInfo.InvariantCulture),
UnitId = null,
ArticleNumber = "ART64",
CostCenter = "",
Number = 64,
NumberPrefix = "ART",
NumberLength = 0,
Expand Down
98 changes: 98 additions & 0 deletions Develappers.BillomatNet.Tests/UnitTests/OfferServiceItemsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Threading;
using System.Threading.Tasks;
using Develappers.BillomatNet.Api.Net;
using Develappers.BillomatNet.Types;
using FakeItEasy;
using FluentAssertions;
using Xunit;

namespace Develappers.BillomatNet.Tests.UnitTests
{
public class OfferServiceItemsTests : UnitTestBase<OfferService>
{
[Fact]
public async Task GetByIdWithValidData_ShouldReturnWithCorrectValues()
{
const string httpResult = "{\"offer-item\":{\"id\":\"6809664\",\"article_id\":\"\",\"offer_id\":\"1376503\",\"position\":\"1\",\"unit\":\"apfel\",\"quantity\":\"1\",\"type\":\"PRODUCT\",\"unit_price\":\"100\",\"tax_name\":\"MwSt\",\"tax_rate\":\"19\",\"title\":\"test1\",\"description\":\"test2\",\"total_net\":\"100\",\"total_gross\":\"119\",\"reduction\":\"\",\"total_net_unreduced\":\"100\",\"total_gross_unreduced\":\"119\",\"optional\":\"0\",\"tax_changed_manually\":\"0\",\"customfield\":\"\"}}";
const int id = 6809664;
const string expectedUri = "/api/offer-items/6809664";
var expectedResult = new OfferItem
{
Id = 6809664,
ArticleId = null,
OfferId = 1376503,
Position = 1,
Unit = "apfel",
Quantity = 1,
Type = ItemType.Product,
UnitPrice = 100,
TaxName = "MwSt",
TaxRate = 19,
Title = "test1",
Description = "test2",
TotalNet = 100,
TotalGross = 119,
Reduction = null,
TotalNetUnreduced = 100,
TotalGrossUnreduced = 119
};

var http = A.Fake<IHttpClient>();
A.CallTo(() => http.GetAsync(new Uri(expectedUri, UriKind.Relative), A<CancellationToken>.Ignored))
.Returns(Task.FromResult(httpResult));

var sut = GetSystemUnderTest(http);
var result = await sut.GetItemByIdAsync(id);

A.CallTo(() => http.GetAsync(new Uri(expectedUri, UriKind.Relative), A<CancellationToken>.Ignored))
.MustHaveHappenedOnceExactly();

result.Should().BeEquivalentTo(expectedResult);
}

[Fact]
public async Task GetByIdWithWrongType_ShouldReturnDeviatingItem()
{
const string httpResult = "{\"offer-item\":{\"id\":\"6809664\",\"article_id\":\"\",\"offer_id\":\"1376503\",\"position\":\"1\",\"unit\":\"apfel\",\"quantity\":\"1\",\"type\":\"SERVICE\",\"unit_price\":\"100\",\"tax_name\":\"MwSt\",\"tax_rate\":\"19\",\"title\":\"test1\",\"description\":\"test2\",\"total_net\":\"100\",\"total_gross\":\"119\",\"reduction\":\"\",\"total_net_unreduced\":\"100\",\"total_gross_unreduced\":\"119\",\"optional\":\"0\",\"tax_changed_manually\":\"0\",\"customfield\":\"\"}}";
const int id = 6809664;
const string expectedUri = "/api/offer-items/6809664";
var expectedResult = new OfferItem
{
Id = 6809664,
ArticleId = null,
OfferId = 1376503,
Position = 1,
Unit = "apfel",
Quantity = 1,
Type = ItemType.Product,
UnitPrice = 100,
TaxName = "MwSt",
TaxRate = 19,
Title = "test1",
Description = "test2",
TotalNet = 100,
TotalGross = 119,
Reduction = null,
TotalNetUnreduced = 100,
TotalGrossUnreduced = 119
};

var http = A.Fake<IHttpClient>();
A.CallTo(() => http.GetAsync(new Uri(expectedUri, UriKind.Relative), A<CancellationToken>.Ignored))
.Returns(Task.FromResult(httpResult));

var sut = GetSystemUnderTest(http);
var result = await sut.GetItemByIdAsync(id);

A.CallTo(() => http.GetAsync(new Uri(expectedUri, UriKind.Relative), A<CancellationToken>.Ignored))
.MustHaveHappenedOnceExactly();

result.Should().NotBeEquivalentTo(expectedResult);
}
}
}
4 changes: 4 additions & 0 deletions Develappers.BillomatNet/Api/Article.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,9 @@ internal class Article

[JsonProperty("supplier_id")]
public string SupplierId { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
[JsonProperty("cost_center")]
public string CostCenter { get; set; }
}
}
2 changes: 2 additions & 0 deletions Develappers.BillomatNet/Api/InvoiceItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,7 @@ internal class InvoiceItem

[JsonProperty("total_net_unreduced")]
public string TotalNetUnreduced { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
}
}
2 changes: 2 additions & 0 deletions Develappers.BillomatNet/Api/OfferItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@ internal class OfferItem

[JsonProperty("total_net_unreduced")]
public string TotalNetUnreduced { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
}
}
2 changes: 1 addition & 1 deletion Develappers.BillomatNet/Develappers.BillomatNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions Develappers.BillomatNet/Mapping/ArticleMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public Article ApiToDomain(Api.Article value)
Created = DateTime.Parse(value.Created, CultureInfo.InvariantCulture),
Updated = DateTime.Parse(value.Updated, CultureInfo.InvariantCulture),
ArticleNumber = value.ArticleNumber,
CostCenter = value.CostCenter,
CurrencyCode = value.CurrencyCode,
Description = value.Description,
Number = int.Parse(value.Number),
Expand All @@ -61,6 +62,7 @@ public Article ApiToDomain(Api.Article value)
SupplierId = value.SupplierId.ToOptionalInt(),
TaxId = value.TaxId.ToOptionalInt(),
Title = value.Title,
Type = value.Type.ToOptionalItemType(),
UnitId = value.UnitId.ToOptionalInt()

};
Expand All @@ -77,6 +79,7 @@ public Api.Article DomainToApi(Article value)
Id = value.Id.ToString(),
Created = value.Created.ToApiDate(),
ArticleNumber = value.ArticleNumber,
CostCenter = value.CostCenter,
CurrencyCode = value.CurrencyCode,
Description = value.Description,
Number = value.Number.ToString(),
Expand All @@ -92,6 +95,7 @@ public Api.Article DomainToApi(Article value)
SupplierId = value.SupplierId.ToString(),
TaxId = value.TaxId.ToString(),
Title = value.Title,
Type = value.Type.ToApiValue(),
UnitId = value.UnitId.ToString()
};
}
Expand Down
6 changes: 4 additions & 2 deletions Develappers.BillomatNet/Mapping/InvoiceItemMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public InvoiceItem ApiToDomain(Api.InvoiceItem value)
TotalGross = float.Parse(value.TotalGross, CultureInfo.InvariantCulture),
TotalGrossUnreduced = float.Parse(value.TotalGrossUnreduced, CultureInfo.InvariantCulture),
UnitPrice = float.Parse(value.UnitPrice, CultureInfo.InvariantCulture),
TaxRate = value.TaxRate.ToOptionalFloat()
TaxRate = value.TaxRate.ToOptionalFloat(),
Type = value.Type.ToOptionalItemType()
};
}

Expand Down Expand Up @@ -97,7 +98,8 @@ public Api.InvoiceItem DomainToApi(InvoiceItem value)
TotalNet = value.TotalNet.ToString(CultureInfo.InvariantCulture),
Reduction = reduction,
TotalGrossUnreduced = value.TotalGrossUnreduced.ToString(CultureInfo.InvariantCulture),
TotalNetUnreduced = value.TotalNetUnreduced.ToString(CultureInfo.InvariantCulture)
TotalNetUnreduced = value.TotalNetUnreduced.ToString(CultureInfo.InvariantCulture),
Type = value.Type.ToApiValue()
};
}

Expand Down
Loading

0 comments on commit d38245c

Please sign in to comment.