├── .gitignore
├── .vs
└── config
│ └── applicationhost.config
├── BillBeeApiSDK.sln
├── Billbee.Api.Client.Demo
├── Billbee.Api.Client.Demo.csproj
├── Config.json.dummy
├── Logger.cs
└── Program.cs
├── Billbee.Api.Client.Test
├── .gitignore
├── ApiClientTest.cs
├── ApiSyncTest.cs
├── Billbee.Api.Client.Test.csproj
├── Config.test.json
├── EndPointIntegrationTests
│ ├── AutomaticProvisionEndPointIntegrationTest.cs
│ ├── CloudStoragesEndPointIntegrationTest.cs
│ ├── CustomerAddressesEndPointIntegrationTest.cs
│ ├── CustomerEndPointIntegrationTest.cs
│ ├── EnumEndPointIntegrationTest.cs
│ ├── EventEndPointIntegrationTest.cs
│ ├── Helpers
│ │ ├── CrudHelpers.cs
│ │ ├── IntegrationTestHelpers.cs
│ │ ├── IntegrationTestSettings.cs
│ │ └── RequiresApiAccessAttribute.cs
│ ├── OrderEndPointIntegrationTest.cs
│ ├── ProductEndPointIntegrationTest.cs
│ ├── SearchEndPointIntegrationTest.cs
│ ├── ShipmentEndPointIntegrationTest.cs
│ └── WebhookEndPointIntegrationTest.cs
├── EndPointTests
│ ├── AutomaticProvisionEndPointTest.cs
│ ├── CloudStoragesEndPointTest.cs
│ ├── CustomerAddressesEndPointTest.cs
│ ├── CustomerEndPointTest.cs
│ ├── EnumEndPointTest.cs
│ ├── EventEndPointTest.cs
│ ├── OrderEndPointTest.cs
│ ├── ProductEndPointTest.cs
│ ├── SearchEndPointTest.cs
│ ├── ShipmentEndPointTest.cs
│ └── WebhookEndPointTest.cs
├── TestCategories.cs
├── TestHelpers.cs
├── Usings.cs
├── config.test.json
└── readme.txt
├── Billbee.Api.Client
├── ApiClient.cs
├── ApiConfiguration.cs
├── ApiMappingAttribute.cs
├── Billbee.Api.Client.csproj
├── Billbee.Api.Client.csproj.user
├── BillbeeRestClient.cs
├── Endpoint
│ ├── AutomaticProvisionEndPoint.cs
│ ├── CloudStoragesEndPoint.cs
│ ├── CustomerAddressesEndPoint.cs
│ ├── CustomerEndPoint.cs
│ ├── EnumEndPoint.cs
│ ├── EventEndPoint.cs
│ ├── Interfaces
│ │ ├── IAutomaticProvisionEndPoint.cs
│ │ ├── ICloudStoragesEndPoint.cs
│ │ ├── ICustomerAddressesEndPoint.cs
│ │ ├── ICustomerEndPoint.cs
│ │ ├── IEnumEndPoint.cs
│ │ ├── IEventEndPoint.cs
│ │ ├── IOrderEndPoint.cs
│ │ ├── IProductEndPoint.cs
│ │ ├── ISearchEndPoint.cs
│ │ ├── IShipmentEndPoint.cs
│ │ └── IWebhookEndPoint.cs
│ ├── OrderEndPoint.cs
│ ├── ProductEndPoint.cs
│ ├── SearchEndPoint.cs
│ ├── ShipmentEndPoint.cs
│ └── WebhookEndPoint.cs
├── Enums
│ ├── ErrorHandlingEnum.cs
│ ├── EventTypeEnum.cs
│ ├── OrderStateEnum.cs
│ ├── PaymentTypeEnum.cs
│ ├── ProductIdType.cs
│ ├── ReportTemplates.cs
│ ├── ShipmentTypeEnum.cs
│ ├── ShippingCarrierEnum.cs
│ └── VatModeEnum.cs
├── IApiClient.cs
├── IBillbeeRestClient.cs
├── ILogger.cs
├── InvalidValueException.cs
├── Model
│ ├── Account.cs
│ ├── Address.cs
│ ├── ApiResult.cs
│ ├── ArticleCategory.cs
│ ├── ArticleCustomFieldDefinition.cs
│ ├── ArticleImage.cs
│ ├── ArticleSource.cs
│ ├── AtticleCustomFieldValue.cs
│ ├── CloudStorage.cs
│ ├── Comment.cs
│ ├── CreateUserResult.cs
│ ├── CurrentStock.cs
│ ├── Customer.cs
│ ├── CustomerAddress.cs
│ ├── CustomerForCreation.cs
│ ├── CustomerSearchResult.cs
│ ├── DeletedImages.cs
│ ├── DeliveryNote.cs
│ ├── EnumEntry.cs
│ ├── Event.cs
│ ├── GetReservedAmountResult.cs
│ ├── Invoice.cs
│ ├── InvoiceDetail.cs
│ ├── InvoicePosition.cs
│ ├── LayoutTemplate.cs
│ ├── MultiLanguageString.cs
│ ├── Order.cs
│ ├── OrderItem.cs
│ ├── OrderItemAttribute.cs
│ ├── OrderItemProduct.cs
│ ├── OrderPayment.cs
│ ├── OrderProductImage.cs
│ ├── OrderResult.cs
│ ├── OrderSearchResult.cs
│ ├── OrderShipment.cs
│ ├── OrderShippingId.cs
│ ├── OrderUser.cs
│ ├── ParsePlaceholdersQuery.cs
│ ├── ParsePlaceholdersResult.cs
│ ├── Product.cs
│ ├── ProductSearchResult.cs
│ ├── Search.cs
│ ├── SearchResult.cs
│ ├── SendMessage.cs
│ ├── Shipment.cs
│ ├── ShipmentAddress.cs
│ ├── ShipmentDimensions.cs
│ ├── ShipmentPost.cs
│ ├── ShipmentResult.cs
│ ├── ShipmentWithLabel.cs
│ ├── ShipmentWithLabelResult.cs
│ ├── ShippingCarrier.cs
│ ├── ShippingProduct.cs
│ ├── ShippingProvider.cs
│ ├── Stock.cs
│ ├── StockArticle.cs
│ ├── TermsResult.cs
│ ├── TriggerEventContainer.cs
│ ├── UpdateStock.cs
│ ├── UpdateStockCode.cs
│ ├── Webhook.cs
│ └── WebhookFilter.cs
├── favicon_32.ico
└── forUnitTests.cs
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # This .gitignore file was automatically created by Microsoft(R) Visual Studio.
3 | ################################################################################
4 |
5 | /packages
6 | /.vs/BillBeeApiSDK/v15
7 | /Billbee.Api.Client/bin/Debug
8 | /Billbee.Api.Client/obj/Debug
9 | /Billbee.Api.Client.Demo/bin/Debug
10 | /Billbee.Api.Client.Demo/obj/Debug
11 | /Billbee.Api.Client.Demo/Config.json
12 | /Billbee.Api.Client/obj/Release
13 | /Billbee.Api.Client.Demo/obj/Release
14 | /.vs
15 |
--------------------------------------------------------------------------------
/BillBeeApiSDK.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27004.2006
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Billbee.Api.Client", "Billbee.Api.Client\Billbee.Api.Client.csproj", "{814BD848-4AED-411F-B585-4519A6E0E44D}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Billbee.Api.Client.Demo", "Billbee.Api.Client.Demo\Billbee.Api.Client.Demo.csproj", "{37E147A5-6B5B-4012-A38E-0828D8E229EA}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Billbee.Api.Client.Test", "Billbee.Api.Client.Test\Billbee.Api.Client.Test.csproj", "{3ADDE5CD-C642-476E-8ABA-6EC3031AE247}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Release|Any CPU = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {814BD848-4AED-411F-B585-4519A6E0E44D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {814BD848-4AED-411F-B585-4519A6E0E44D}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {814BD848-4AED-411F-B585-4519A6E0E44D}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {814BD848-4AED-411F-B585-4519A6E0E44D}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {37E147A5-6B5B-4012-A38E-0828D8E229EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {37E147A5-6B5B-4012-A38E-0828D8E229EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {37E147A5-6B5B-4012-A38E-0828D8E229EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {37E147A5-6B5B-4012-A38E-0828D8E229EA}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {3ADDE5CD-C642-476E-8ABA-6EC3031AE247}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {3ADDE5CD-C642-476E-8ABA-6EC3031AE247}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {3ADDE5CD-C642-476E-8ABA-6EC3031AE247}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {3ADDE5CD-C642-476E-8ABA-6EC3031AE247}.Release|Any CPU.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | GlobalSection(ExtensibilityGlobals) = postSolution
35 | SolutionGuid = {5BA9C842-6A9F-4A2A-A89C-2A06EC820EAB}
36 | EndGlobalSection
37 | EndGlobal
38 |
--------------------------------------------------------------------------------
/Billbee.Api.Client.Demo/Billbee.Api.Client.Demo.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net6.0
6 | 2.4.2.0
7 | Billbee.Api.Client.Demo
8 | Billbee GmbH
9 | Copyright©, 2023 by Billbee GmbH
10 | Billbee GmbH
11 | 2.4.2.0
12 | 2.4.2.0
13 | The Billbee API SDK for .Net
14 | https://github.com/billbeeio/billbee-csharp-sdk
15 | git
16 | true
17 | enable
18 | enable
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Billbee.Api.Client.Demo/Config.json.dummy:
--------------------------------------------------------------------------------
1 | {
2 | "Username": "",
3 | "Password": "",
4 | "ApiKey": "",
5 | "BaseUrl": "https: //app.billbee.io/api/v1",
6 | "errorHandlingBehaviour": 0
7 | }
--------------------------------------------------------------------------------
/Billbee.Api.Client.Demo/Logger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Billbee.Api.Client.Demo
4 | {
5 | ///
6 | /// Very simple logger, for writing data from the api to the console.
7 | ///
8 | public class Logger : ILogger
9 | {
10 | ///
11 | /// Generates a log message to the console.
12 | ///
13 | /// The message, that describes the content of the log entry
14 | /// The severy, in which context the log message was created
15 | public void LogMsg(string message, LogSeverity severity)
16 | {
17 | Console.WriteLine($"{DateTime.Now} {severity}: {message}");
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Billbee.Api.Client.Test/.gitignore:
--------------------------------------------------------------------------------
1 | config.integration-tests.json
--------------------------------------------------------------------------------
/Billbee.Api.Client.Test/ApiClientTest.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Text;
3 | using Billbee.Api.Client.EndPoint;
4 | using Billbee.Api.Client.Enums;
5 |
6 | namespace Billbee.Api.Client.Test;
7 |
8 | [TestClass]
9 | public class ApiClientTest
10 | {
11 | [TestMethod]
12 | public void ApiClient_Init_Test()
13 | {
14 | var uut = new ApiClient();
15 |
16 | Assert.IsNotNull(uut);
17 | Assert.IsNotNull(uut.Configuration);
18 | Assert.IsNull(uut.Configuration.Username);
19 | Assert.IsNull(uut.Configuration.Password);
20 | Assert.IsNull(uut.Configuration.ApiKey);
21 | Assert.AreEqual("https://app.billbee.io/api/v1", uut.Configuration.BaseUrl);
22 | Assert.AreEqual(ErrorHandlingEnum.ThrowException, uut.Configuration.ErrorHandlingBehaviour);
23 |
24 | Assert.IsNotNull(uut.AutomaticProvision);
25 | Assert.IsNotNull(uut.CloudStorages);
26 | Assert.IsNotNull(uut.Customer);
27 | Assert.IsNotNull(uut.Events);
28 | Assert.IsNotNull(uut.Orders);
29 | Assert.IsNotNull(uut.Products);
30 | Assert.IsNotNull(uut.Search);
31 | Assert.IsNotNull(uut.Shipment);
32 | Assert.IsNotNull(uut.Webhooks);
33 | }
34 |
35 | [TestMethod]
36 | public void ApiClient_InitWithConfig_Test()
37 | {
38 | var config = new ApiConfiguration
39 | {
40 | Username = "myUser",
41 | Password = "myPwd",
42 | ApiKey = "myApiKey",
43 | BaseUrl = "myBaseUrl",
44 | ErrorHandlingBehaviour = ErrorHandlingEnum.ReturnErrorContent
45 | };
46 |
47 | var uut = new ApiClient(config);
48 |
49 | Assert.IsNotNull(uut);
50 | Assert.IsNotNull(uut.Configuration);
51 | Assert.AreEqual("myUser", uut.Configuration.Username);
52 | Assert.AreEqual("myPwd", uut.Configuration.Password);
53 | Assert.AreEqual("myApiKey", uut.Configuration.ApiKey);
54 | Assert.AreEqual("myBaseUrl", uut.Configuration.BaseUrl);
55 | Assert.AreEqual(ErrorHandlingEnum.ReturnErrorContent, uut.Configuration.ErrorHandlingBehaviour);
56 | }
57 |
58 | [TestMethod]
59 | public void ApiClient_InitWithConfigFile_Test()
60 | {
61 | var fiDll = new FileInfo(Assembly.GetExecutingAssembly().Location);
62 | Assert.IsNotNull(fiDll);
63 | Assert.IsNotNull(fiDll.Directory);
64 | var path = Path.Combine(fiDll.Directory.FullName, "../../../config.test");
65 | var uut = new ApiClient(path);
66 |
67 | Assert.IsNotNull(uut);
68 | Assert.IsNotNull(uut.Configuration);
69 | Assert.AreEqual("myUserFromFile", uut.Configuration.Username);
70 | Assert.AreEqual("myPwdFromFile", uut.Configuration.Password);
71 | Assert.AreEqual("myApiKeyFromFile", uut.Configuration.ApiKey);
72 | Assert.AreEqual("myBaseUrlFromFile", uut.Configuration.BaseUrl);
73 | Assert.AreEqual(ErrorHandlingEnum.ReturnErrorContent, uut.Configuration.ErrorHandlingBehaviour);
74 | }
75 |
76 | private class TypeMapping
77 | {
78 | public TypeMapping(string uutClass, string uutTypeName, string testTypeName, bool foundMapping)
79 | {
80 | UutClass = uutClass;
81 | UutTypeName = uutTypeName;
82 | TestTypeName = testTypeName;
83 | FoundMapping = foundMapping;
84 | }
85 |
86 | public string UutClass { get; }
87 | public string UutTypeName { get; }
88 | public string TestTypeName { get; }
89 | public bool FoundMapping { get; }
90 | }
91 |
92 | [TestMethod]
93 | public void CheckAllTests_UnitTestsForAllEndpointsTest()
94 | {
95 | _checkTestMethods("Test", "_Test");
96 | }
97 |
98 | [TestMethod]
99 | public void CheckAllTests_IntegrationTestsForAllEndpointsTest()
100 | {
101 | _checkTestMethods( "IntegrationTest", "_IntegrationTest");
102 | }
103 |
104 | private void _checkTestMethods(string testClassPostfix, string testMethodPostfix)
105 | {
106 | var clientAssembly = Assembly.Load("Billbee.Api.Client");
107 | var clientTypes = clientAssembly.GetTypes();
108 | var testAssembly = Assembly.GetExecutingAssembly();
109 | var testTypes = testAssembly.GetTypes();
110 |
111 | var typeMappingsTestMethods = new List();
112 | foreach (var clientType in clientTypes)
113 | {
114 | var clientTypeName = clientType.Name;
115 | if (clientType.Namespace == null || !clientType.Namespace.StartsWith("Billbee.Api.Client.EndPoint"))
116 | {
117 | continue;
118 | }
119 |
120 | var entityNamePrefix = clientTypeName.Substring(0, clientTypeName.IndexOf("EndPoint")) + "_";
121 |
122 | var testTypeName = clientType.Name + testClassPostfix;
123 | var testType = testTypes.FirstOrDefault(t => t.IsClass && t.IsPublic && t.Name == testTypeName && t.GetCustomAttributes().Any(a => a is TestClassAttribute));
124 | Assert.IsNotNull(testType);
125 |
126 | var bindingFlags = BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance;
127 | var clientMethods = clientType.GetMethods(bindingFlags);
128 | var testMethods = testType.GetMethods(bindingFlags).Where(m => m.GetCustomAttributes().Any(a => a is TestMethodAttribute)).ToList();
129 | foreach (var clientMethod in clientMethods)
130 | {
131 | var clientMethodName = clientMethod.Name;
132 |
133 | var testMethodName = entityNamePrefix + clientMethodName + testMethodPostfix;
134 | var foundMapping = testMethods.Any(t => t.Name == testMethodName);
135 | if (clientTypeName != nameof(EnumEndPoint))
136 | {
137 | typeMappingsTestMethods.Add(new TypeMapping(clientTypeName, clientMethodName, testMethodName, foundMapping));
138 | }
139 | }
140 | }
141 |
142 | Console.WriteLine($"#SdkMethods={typeMappingsTestMethods.Count}, #{testMethodPostfix}Methods={typeMappingsTestMethods.Count(t => t.FoundMapping)}");
143 | Console.WriteLine();
144 | Console.WriteLine($"Test implemented,ClassName,UutTypeName,TestTypeName");
145 | foreach (var typeMapping in typeMappingsTestMethods)
146 | {
147 | Console.WriteLine($"{typeMapping.FoundMapping},{typeMapping.UutClass},{typeMapping.UutTypeName},{typeMapping.TestTypeName}");
148 | }
149 |
150 | Assert.IsTrue(typeMappingsTestMethods.All(t => t.FoundMapping));
151 | }
152 | }
--------------------------------------------------------------------------------
/Billbee.Api.Client.Test/ApiSyncTest.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics;
2 | using System.Reflection;
3 | using Microsoft.OpenApi;
4 | using Microsoft.OpenApi.Extensions;
5 | using Microsoft.OpenApi.Models;
6 | using Microsoft.OpenApi.Readers;
7 |
8 | namespace Billbee.Api.Client.Test;
9 |
10 | [TestClass]
11 | public class ApiSyncTest
12 | {
13 | [DebuggerDisplay("{Path}:{HttpOperation}")]
14 | public class ApiOperation
15 | {
16 | public string Path { get; set; } = null!;
17 | public HttpOperation HttpOperation { get; set; }
18 |
19 | public override string ToString() => $"{Path}:{HttpOperation}";
20 | }
21 |
22 | [TestMethod]
23 | public async Task Api_SyncCheck_Test()
24 | {
25 | var sdkOps = GetSdkOperations();
26 | var apiOps = await GetApiOperations();
27 |
28 | var missingSdkOps = new List();
29 | foreach (var apiOp in apiOps)
30 | {
31 | if (!sdkOps.Any(sdkOp => sdkOp.Path == apiOp.Path && sdkOp.HttpOperation == apiOp.HttpOperation))
32 | {
33 | missingSdkOps.Add(apiOp);
34 | }
35 | }
36 |
37 | Console.WriteLine($"#ApiOps={apiOps.Count}, #SdkOps={sdkOps.Count}, #MissingSdkOps={missingSdkOps.Count}");
38 |
39 | if (missingSdkOps.Count > 0)
40 | {
41 | Console.WriteLine("Missing Sdk Operations:");
42 | foreach (var missingSdkOp in missingSdkOps)
43 | {
44 | Console.WriteLine(missingSdkOp.ToString());
45 | }
46 | }
47 |
48 | Assert.AreEqual(0, missingSdkOps.Count);
49 | }
50 |
51 | private async Task> GetApiOperations()
52 | {
53 | var apiOps = new List();
54 | var openApiDoc = await GetOpenApiDoc();
55 | foreach (var path in openApiDoc.Paths)
56 | {
57 | foreach (var op in path.Value.Operations)
58 | {
59 | if (Enum.TryParse(op.Key.ToString(), out HttpOperation httpOperation))
60 | {
61 | var apiOp = new ApiOperation
62 | {
63 | Path = path.Key,
64 | HttpOperation = httpOperation
65 | };
66 | apiOps.Add(apiOp);
67 | }
68 | else
69 | {
70 | Assert.Fail("unknown Path.OperationType");
71 | }
72 | }
73 | }
74 |
75 | return apiOps;
76 | }
77 |
78 | private static List GetSdkOperations()
79 | {
80 | var sdkOps = new List();
81 | var endpointTypes = Assembly.GetAssembly(typeof(ApiClient))?.GetTypes()
82 | .Where(t => t.Namespace == "Billbee.Api.Client.EndPoint");
83 | Assert.IsNotNull(endpointTypes);
84 | foreach (var endpoint in endpointTypes)
85 | {
86 | foreach (var methodInfo in endpoint.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic |
87 | BindingFlags.Public))
88 | {
89 | if (methodInfo.GetCustomAttributes(true).FirstOrDefault(x => x is ApiMappingAttribute) is
90 | ApiMappingAttribute apiMappingAttr)
91 | {
92 | var op = new ApiOperation
93 | {
94 | Path = apiMappingAttr.ApiPath,
95 | HttpOperation = apiMappingAttr.HttpOperation
96 | };
97 | sdkOps.Add(op);
98 | }
99 | }
100 | }
101 |
102 | return sdkOps;
103 | }
104 |
105 | private async Task GetOpenApiDoc()
106 | {
107 | var httpClient = new HttpClient
108 | {
109 | BaseAddress = new Uri("https://app.billbee.io/")
110 | };
111 |
112 | var stream = await httpClient.GetStreamAsync("/swagger/docs/v1");
113 |
114 | return new OpenApiStreamReader().Read(stream, out var diagnostic);
115 | }
116 | }
--------------------------------------------------------------------------------
/Billbee.Api.Client.Test/Billbee.Api.Client.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 | enable
6 | enable
7 | Billbee.Api.Client.Test
8 | Billbee GmbH
9 | Copyright©, 2023 by Billbee GmbH
10 | Billbee GmbH
11 | 2.4.2.0
12 | 2.4.2.0
13 |
14 | false
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | all
25 | runtime; build; native; contentfiles; analyzers; buildtransitive
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/Billbee.Api.Client.Test/Config.test.json:
--------------------------------------------------------------------------------
1 | {
2 | "Username": "myUserFromFile",
3 | "Password": "myPwdFromFile",
4 | "ApiKey": "myApiKeyFromFile",
5 | "BaseUrl": "myBaseUrlFromFile",
6 | "errorHandlingBehaviour": 1
7 | }
--------------------------------------------------------------------------------
/Billbee.Api.Client.Test/EndPointIntegrationTests/AutomaticProvisionEndPointIntegrationTest.cs:
--------------------------------------------------------------------------------
1 | using System.Net;
2 | using Billbee.Api.Client.Model;
3 | using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers;
4 |
5 | namespace Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers
6 | {
7 | public static partial class TestData
8 | {
9 | public static Account Account(string name) => new Account
10 | {
11 | EMail = "john+" + name + "@test.com",
12 | Password = "1Ufuyk2s",
13 | AcceptTerms = true,
14 | Address = new Account.UserAddress
15 | {
16 | Company = "Test Company GmbH",
17 | Name = name,
18 | Address1 = "Paulinenstr. 4",
19 | Address2 = "address 2",
20 | Zip = "12345",
21 | City = "Flipstadt",
22 | Country = "DE",
23 | VatId = name + "-VatId"
24 | },
25 | AffiliateCouponCode = "affiliateCouponCode",
26 | Vat1Rate = 19,
27 | Vat2Rate = 7,
28 | DefaultVatMode = 0,
29 | DefaultCurrrency = "EUR",
30 | DefaultVatIndex = 0
31 | };
32 | }
33 | }
34 |
35 | namespace Billbee.Api.Client.Test.EndPointIntegrationTests
36 | {
37 | [TestClass]
38 | [TestCategory(TestCategories.IntegrationTests)]
39 | public class AutomaticProvisionEndPointIntegrationTest
40 | {
41 | #pragma warning disable CS8618
42 | public TestContext TestContext { get; set; }
43 | #pragma warning restore CS8618
44 |
45 | [TestInitialize]
46 | public void TestInitialize()
47 | {
48 | IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod);
49 | }
50 |
51 | [TestMethod]
52 | [RequiresApiAccess]
53 | public void AutomaticProvision_CreateAccount_IntegrationTest()
54 | {
55 | Assert.Inconclusive();
56 | return;
57 |
58 | // var account = TestData.Account(Guid.NewGuid().ToString());
59 | // var result =
60 | // CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.AutomaticProvision.CreateAccount(x),
61 | // account, false);
62 | // var createUserResult = result.Data;
63 | // Assert.IsNotNull(createUserResult.Password);
64 | // Assert.IsNotNull(createUserResult.UserId);
65 | }
66 |
67 | [TestMethod]
68 | [RequiresApiAccess]
69 | public async Task AutomaticProvision_TermsInfo_IntegrationTest()
70 | {
71 | var result = IntegrationTestHelpers.ApiClient.AutomaticProvision.TermsInfo();
72 | Assert.IsNotNull(result);
73 |
74 | var termsResult = result.Data;
75 |
76 | Assert.IsNotNull(termsResult);
77 | Assert.IsNotNull(termsResult.LinkToTermsWebPage);
78 | await _checkLink(termsResult.LinkToTermsWebPage);
79 | Assert.IsNotNull(termsResult.LinkToPrivacyWebPage);
80 | await _checkLink(termsResult.LinkToPrivacyWebPage);
81 |
82 | Assert.AreEqual(string.Empty, termsResult.LinkToTermsHtmlContent);
83 | Assert.AreEqual(string.Empty, termsResult.LinkToPrivacyHtmlContent);
84 | }
85 |
86 | private async Task _checkLink(string url)
87 | {
88 | var httpClient = new HttpClient();
89 | var response = await httpClient.GetAsync(url);
90 | response.EnsureSuccessStatusCode();
91 |
92 | Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
93 | }
94 | }
95 | }
--------------------------------------------------------------------------------
/Billbee.Api.Client.Test/EndPointIntegrationTests/CloudStoragesEndPointIntegrationTest.cs:
--------------------------------------------------------------------------------
1 | using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers;
2 |
3 | namespace Billbee.Api.Client.Test.EndPointIntegrationTests;
4 |
5 | [TestClass]
6 | [TestCategory(TestCategories.IntegrationTests)]
7 | public class CloudStoragesEndPointIntegrationTest
8 | {
9 | #pragma warning disable CS8618
10 | public TestContext TestContext { get; set; }
11 | #pragma warning restore CS8618
12 |
13 | [TestInitialize]
14 | public void TestInitialize()
15 | {
16 | IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod);
17 | }
18 |
19 | [TestMethod]
20 | [RequiresApiAccess]
21 | public void CloudStorages_GetCloudStorageList_IntegrationTest()
22 | {
23 | CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.CloudStorages.GetCloudStorageList());
24 | }
25 | }
--------------------------------------------------------------------------------
/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerAddressesEndPointIntegrationTest.cs:
--------------------------------------------------------------------------------
1 | using Billbee.Api.Client.Model;
2 | using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers;
3 |
4 | namespace Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers
5 | {
6 | public static partial class TestData
7 | {
8 | public static CustomerAddress CustomerAddress =>
9 | new CustomerAddress
10 | {
11 | FirstName = "John",
12 | LastName = "Doe",
13 | Street = "Mustergasse",
14 | Housenumber = "1",
15 | Zip = "12345",
16 | City = "Musterstadt",
17 | AddressType = 1,
18 | CountryCode = "DE",
19 | CustomerId = 0
20 | };
21 |
22 | public static CustomerAddress GetCustomerAddress(long? customerId)
23 | {
24 | var address = CustomerAddress;
25 | address.CustomerId = customerId;
26 | address.Street = Guid.NewGuid().ToString().Replace("-", "");
27 | return address;
28 | }
29 | }
30 | }
31 |
32 | namespace Billbee.Api.Client.Test.EndPointIntegrationTests
33 | {
34 | [TestClass]
35 | [TestCategory(TestCategories.IntegrationTests)]
36 | public class CustomerAddressesEndPointIntegrationTest
37 | {
38 | #pragma warning disable CS8618
39 | public TestContext TestContext { get; set; }
40 | #pragma warning restore CS8618
41 |
42 | [TestInitialize]
43 | public void TestInitialize()
44 | {
45 | IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod);
46 | }
47 |
48 | [TestMethod]
49 | [RequiresApiAccess]
50 | public void CustomerAddresses_GetCustomerAddresses_IntegrationTest()
51 | {
52 | CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.CustomerAddresses.GetCustomerAddresses(1, 5));
53 | }
54 |
55 | [TestMethod]
56 | [RequiresApiAccess]
57 | public void CustomerAddresses_GetCustomerAddress_IntegrationTest()
58 | {
59 | var customer =
60 | CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c),
61 | TestData.Customer).Data;
62 |
63 | var customerAddress =
64 | CrudHelpers.CreateApiResult(
65 | a => IntegrationTestHelpers.ApiClient.CustomerAddresses.AddCustomerAddress(a),
66 | TestData.GetCustomerAddress(customer.Id)).Data;
67 | Assert.IsNotNull(customerAddress.Id);
68 | CrudHelpers.GetOneApiResult(
69 | (id) => IntegrationTestHelpers.ApiClient.CustomerAddresses.GetCustomerAddress(id),
70 | customerAddress.Id.Value);
71 | }
72 |
73 | [TestMethod]
74 | [RequiresApiAccess]
75 | public void CustomerAddresses_AddCustomerAddress_IntegrationTest()
76 | {
77 | CustomerAddresses_GetCustomerAddress_IntegrationTest();
78 | }
79 |
80 | [TestMethod]
81 | [RequiresApiAccess]
82 | public void CustomerAddresses_UpdateCustomerAddress_IntegrationTest()
83 | {
84 | var customer =
85 | CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c),
86 | TestData.Customer).Data;
87 |
88 | var customerAddress =
89 | CrudHelpers.CreateApiResult(
90 | a => IntegrationTestHelpers.ApiClient.CustomerAddresses.AddCustomerAddress(a),
91 | TestData.GetCustomerAddress(customer.Id)).Data;
92 | Assert.IsNotNull(customerAddress.Id);
93 | var result = CrudHelpers.GetOneApiResult(
94 | (id) => IntegrationTestHelpers.ApiClient.CustomerAddresses.GetCustomerAddress(id),
95 | customerAddress.Id.Value);
96 | var address = result.Data;
97 |
98 | address.LastName = "Modified";
99 | CrudHelpers.Put(
100 | c => IntegrationTestHelpers.ApiClient.CustomerAddresses.UpdateCustomerAddress(c),
101 | address);
102 | CrudHelpers.GetOneApiResult(
103 | (id) => IntegrationTestHelpers.ApiClient.CustomerAddresses.GetCustomerAddress(id),
104 | customerAddress.Id.Value);
105 | Assert.AreEqual("Modified", address.LastName);
106 | }
107 | }
108 | }
--------------------------------------------------------------------------------
/Billbee.Api.Client.Test/EndPointIntegrationTests/EnumEndPointIntegrationTest.cs:
--------------------------------------------------------------------------------
1 | using Billbee.Api.Client.Endpoint.Interfaces;
2 | using Billbee.Api.Client.Enums;
3 | using Billbee.Api.Client.Model;
4 | using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers;
5 |
6 | namespace Billbee.Api.Client.Test.EndPointIntegrationTests;
7 |
8 | [TestClass]
9 | [TestCategory(TestCategories.IntegrationTests)]
10 | public class EnumEndPointIntegrationTest
11 | {
12 | #pragma warning disable CS8618
13 | public TestContext TestContext { get; set; }
14 | #pragma warning restore CS8618
15 |
16 | [TestInitialize]
17 | public void TestInitialize()
18 | {
19 | IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod);
20 | }
21 |
22 | [TestMethod]
23 | [RequiresApiAccess]
24 | public void Enum_GetPaymentTypes_IntegrationTest()
25 | {
26 | _executeEnumSyncTest(x => x.GetPaymentTypes());
27 | }
28 |
29 | [TestMethod]
30 | [RequiresApiAccess]
31 | public void Enum_GetShippingCarriers_IntegrationTest()
32 | {
33 | _executeEnumSyncTest(x => x.GetShippingCarriers());
34 | }
35 |
36 | [TestMethod]
37 | [RequiresApiAccess]
38 | public void Enum_GetShipmentTypes_IntegrationTest()
39 | {
40 | _executeEnumSyncTest(x => x.GetShipmentTypes());
41 | }
42 |
43 | [TestMethod]
44 | [RequiresApiAccess]
45 | public void Enum_GetOrderStates_IntegrationTest()
46 | {
47 | _executeEnumSyncTest(x => x.GetOrderStates());
48 | }
49 |
50 | private void _executeEnumSyncTest(Func> endpointFunc) where T: struct, System.Enum
51 | {
52 | var apiEnumEntries = endpointFunc(IntegrationTestHelpers.ApiClient.Enums);
53 |
54 | // enum entries in api, but not in sdk
55 | var missingSdkPaymentTypes = _getMissingSdkEnumEntries(apiEnumEntries);
56 |
57 | // enum entries in api and sdk, but with wrong number in sdk
58 | var sdkEnumEntriesWithWrongNumber = _getSdkEnumEntriesWithWrongNumber(apiEnumEntries);
59 |
60 | // enum entries in sdk, but not in api
61 | var deprecatedSdkPaymentTypes = _getDeprecatedSdkEnumEntries(apiEnumEntries);
62 |
63 | Assert.AreEqual(0, missingSdkPaymentTypes.Count);
64 | Assert.AreEqual(0, sdkEnumEntriesWithWrongNumber.Count);
65 | Assert.AreEqual(0, deprecatedSdkPaymentTypes.Count());
66 | }
67 |
68 | private List _getMissingSdkEnumEntries(List apiEnumEntries) where T: struct, System.Enum
69 | {
70 | var result = apiEnumEntries
71 | .Where(apiEnumEntry => !Enum.TryParse(apiEnumEntry.Name, out T _))
72 | .OrderBy(x => x.Id)
73 | .ToList();
74 |
75 | if (result.Count > 0)
76 | {
77 | Console.WriteLine("Missing sdk enum entries:");
78 | foreach (var enumEntry in result)
79 | {
80 | Console.WriteLine($"{enumEntry.Name}: {enumEntry.Id}");
81 | }
82 | }
83 |
84 | return result;
85 | }
86 |
87 | private Dictionary _getSdkEnumEntriesWithWrongNumber(List apiEnumEntries) where T: struct, System.Enum
88 | {
89 | var result = apiEnumEntries
90 | .Where(apiEnumEntry => Enum.TryParse(apiEnumEntry.Name, out T sdkEnumEntry))
91 | .Select(apiEnumEntry =>
92 | {
93 | Enum.TryParse(apiEnumEntry.Name, out T sdkEnumEntry);
94 | return new KeyValuePair(sdkEnumEntry, (apiEnumEntry.Id, Convert.ToInt32(sdkEnumEntry)));
95 | })
96 | .Where(x => x.Value.Item1 != x.Value.Item2)
97 | .OrderBy(x => x.Value.Item1)
98 | .ToDictionary(x => x.Key, x => x.Value);
99 |
100 |
101 | if (result.Count > 0)
102 | {
103 | Console.WriteLine("Sdk enum entries with wrong number:");
104 | foreach (var pair in result)
105 | {
106 | Console.WriteLine($"{pair.Key}: expected:{pair.Value.Item1}, actual:{pair.Value.Item2}");
107 | }
108 | }
109 |
110 | return result;
111 | }
112 |
113 | private IEnumerable _getDeprecatedSdkEnumEntries(List apiEnumEntries) where T: struct, System.Enum
114 | {
115 | var result = new List();
116 | foreach (var sdkEnumEntry in Enum.GetValues())
117 | {
118 | var apiEnumEntry = apiEnumEntries.FirstOrDefault(x => x.Id == Convert.ToInt32(sdkEnumEntry));
119 | if (apiEnumEntry == null)
120 | {
121 | result.Add(sdkEnumEntry);
122 | }
123 | }
124 |
125 | if (result.Count > 0)
126 | {
127 | Console.WriteLine("Deprecated sdk enum entries:");
128 | foreach (var enumEntry in result)
129 | {
130 | Console.WriteLine($"{enumEntry}: {Convert.ToInt32(enumEntry)}");
131 | }
132 | }
133 |
134 | return result;
135 | }
136 | }
--------------------------------------------------------------------------------
/Billbee.Api.Client.Test/EndPointIntegrationTests/EventEndPointIntegrationTest.cs:
--------------------------------------------------------------------------------
1 | using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers;
2 |
3 | namespace Billbee.Api.Client.Test.EndPointIntegrationTests;
4 |
5 | [TestClass]
6 | [TestCategory(TestCategories.IntegrationTests)]
7 | public class EventEndPointIntegrationTest
8 | {
9 | #pragma warning disable CS8618
10 | public TestContext TestContext { get; set; }
11 | #pragma warning restore CS8618
12 |
13 | [TestInitialize]
14 | public void TestInitialize()
15 | {
16 | IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod);
17 | }
18 |
19 | [TestMethod]
20 | [RequiresApiAccess]
21 | public void Event_GetEvents_IntegrationTest()
22 | {
23 | var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Events.GetEvents());
24 | Assert.IsTrue(result.Data.Count > 0);
25 | }
26 | }
--------------------------------------------------------------------------------
/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/IntegrationTestHelpers.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 |
3 | namespace Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers;
4 |
5 | public static class IntegrationTestHelpers
6 | {
7 | private static ApiClient? _apiClient;
8 |
9 | public static void CheckAccess(string? testContextManagedType, string? testContextManagedMethod)
10 | {
11 | Assert.IsNotNull(testContextManagedType);
12 | Assert.IsNotNull(testContextManagedMethod);
13 | if (!IntegrationTestSettings.RunIntegrationTests)
14 | {
15 | Assert.Inconclusive(
16 | $"This test is an integration-test. But integration-tests are disable currently (see property {nameof(IntegrationTestSettings)}{nameof(IntegrationTestSettings.RunIntegrationTests)}).");
17 | return;
18 | }
19 |
20 | var type = Assembly.GetExecutingAssembly().GetType(testContextManagedType);
21 | Assert.IsNotNull(type);
22 | var mi = type.GetMethod(testContextManagedMethod);
23 | Assert.IsNotNull(mi);
24 | bool requiresApiAccess = mi.GetCustomAttributes().Any();
25 | if (requiresApiAccess && !IntegrationTestSettings.AllowReadWriteAccessToBillbeeApi)
26 | {
27 | Assert.Inconclusive(
28 | $"This test is an integration-test and requires api-access. But api-access is not granted currently (see property {nameof(IntegrationTestSettings)}{nameof(IntegrationTestSettings.AllowReadWriteAccessToBillbeeApi)}).");
29 | }
30 | }
31 |
32 | public static ApiClient ApiClient
33 | {
34 | get
35 | {
36 | if (_apiClient == null)
37 | {
38 | var fiDll = new FileInfo(Assembly.GetExecutingAssembly().Location);
39 | Assert.IsNotNull(fiDll.Directory);
40 | var di = new DirectoryInfo(Path.Combine(fiDll.Directory.FullName, "../../../"));
41 | var path = Path.Combine(di.FullName, "config.integration-tests.json");
42 | if (!File.Exists(path))
43 | {
44 | Assert.Fail(
45 | $"This test requires api-access, but the required config-file could not be found: '{path}'");
46 | }
47 |
48 | _apiClient = new ApiClient(path, null, IntegrationTestSettings.AllowReadWriteAccessToBillbeeApi);
49 | Assert.IsTrue(_apiClient.TestConfiguration());
50 | }
51 |
52 | Thread.Sleep(500); // throttle api-calls when executing multiple tests
53 |
54 | return _apiClient;
55 | }
56 | }
57 | }
--------------------------------------------------------------------------------
/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/IntegrationTestSettings.cs:
--------------------------------------------------------------------------------
1 | namespace Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers;
2 |
3 | public static class IntegrationTestSettings
4 | {
5 | public static bool RunIntegrationTests = false;
6 |
7 | // !!! be careful: setting the following property to 'true' will potentially add/change/delete parts your billbee data !!!
8 | public static bool AllowReadWriteAccessToBillbeeApi = false;
9 | }
--------------------------------------------------------------------------------
/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/RequiresApiAccessAttribute.cs:
--------------------------------------------------------------------------------
1 | namespace Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers;
2 |
3 | public class RequiresApiAccessAttribute : Attribute
4 | {
5 |
6 | }
--------------------------------------------------------------------------------
/Billbee.Api.Client.Test/EndPointIntegrationTests/SearchEndPointIntegrationTest.cs:
--------------------------------------------------------------------------------
1 | using Billbee.Api.Client.Model;
2 | using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers;
3 | using Newtonsoft.Json;
4 | using RestSharp.Serialization.Json;
5 | using JsonSerializer = System.Text.Json.JsonSerializer;
6 |
7 | namespace Billbee.Api.Client.Test.EndPointIntegrationTests;
8 |
9 | [TestClass]
10 | [TestCategory(TestCategories.IntegrationTests)]
11 | public class SearchEndPointIntegrationTest
12 | {
13 | #pragma warning disable CS8618
14 | public TestContext TestContext { get; set; }
15 | #pragma warning restore CS8618
16 |
17 | [TestInitialize]
18 | public void TestInitialize()
19 | {
20 | IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod);
21 | }
22 |
23 | [TestMethod]
24 | [RequiresApiAccess]
25 | public void Search_SearchTerm_IntegrationTest()
26 | {
27 | var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer);
28 | Assert.IsNotNull(customer);
29 |
30 | var search = new Search
31 | {
32 | Term = "john",
33 | Type = new List { "customer" }
34 | };
35 | var result = IntegrationTestHelpers.ApiClient.Search.SearchTerm(search);
36 | Assert.IsNotNull(result);
37 | Assert.IsNotNull(result.Customers);
38 | Assert.IsTrue(result.Customers.Count > 0);
39 | }
40 | }
--------------------------------------------------------------------------------
/Billbee.Api.Client.Test/EndPointIntegrationTests/ShipmentEndPointIntegrationTest.cs:
--------------------------------------------------------------------------------
1 | using Billbee.Api.Client.Model;
2 | using Billbee.Api.Client.Model.Rechnungsdruck.WebApp.Model.Api;
3 | using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers;
4 |
5 | namespace Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers
6 | {
7 | public static partial class TestData
8 | {
9 | public static ShipmentWithLabel GetShipmentWithLabel(long orderId, string? printerName, long productId, long providerId) => new ShipmentWithLabel
10 | {
11 | OrderId = orderId,
12 | Dimension = new ShipmentDimensions
13 | {
14 | height = 10,
15 | length = 10,
16 | width = 10,
17 | },
18 | ClientReference = "clientRef",
19 | PrinterName = printerName,
20 | ProductId = productId,
21 | ProviderId = providerId,
22 | ShipDate = DateTime.Now,
23 | WeightInGram = 500,
24 | ChangeStateToSend = true,
25 | };
26 |
27 | public static PostShipment GetPostShipment(string? printerName, string providerName, byte shippingCarrier, string productCode) =>
28 | new PostShipment
29 | {
30 | Dimension = new ShipmentDimensions
31 | {
32 | height = 10,
33 | length = 10,
34 | width = 10,
35 | },
36 | ClientReference = "clientRef",
37 | PrinterName = printerName,
38 | ProviderName = providerName,
39 | ShipDate = DateTime.Now,
40 | WeightInGram = 500,
41 | shippingCarrier = shippingCarrier,
42 | Services = new List