-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #304 from DevelappersGmbH/feature/InvoiceItemType
Updated Newtonsoft.Json implemented ItemType for invoices, articles and offers
- Loading branch information
Showing
19 changed files
with
265 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
Develappers.BillomatNet.Tests/IntegrationTests/OfferServiceItemsIntegrationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
Develappers.BillomatNet.Tests/UnitTests/OfferServiceItemsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.