diff --git a/.gitignore b/.gitignore index 28f8616..a877282 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +# Project specific +tests/appsettings.tests.json # Created by https://www.gitignore.io/api/dotnetcore,jetbrains+all,visualstudiocode # Edit at https://www.gitignore.io/?templates=dotnetcore,jetbrains+all,visualstudiocode diff --git a/Novaloop.PaymoApi.sln b/Novaloop.PaymoApi.sln index 60606a7..3f4197b 100644 --- a/Novaloop.PaymoApi.sln +++ b/Novaloop.PaymoApi.sln @@ -5,7 +5,7 @@ VisualStudioVersion = 15.0.26124.0 MinimumVisualStudioVersion = 15.0.26124.0 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Novaloop.PaymoApi", "src\Novaloop.PaymoApi.csproj", "{A9612B7C-67C1-4B6B-8260-167079A31FAF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Novaloop.PaymoApi.Tests", "tests\Novaloop.PaymoApi.Tests.csproj", "{202BCB4F-78AF-4E9A-B286-C3147374EB53}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Novaloop.PaymoApi.IntegrationTests", "tests\Novaloop.PaymoApi.IntegrationTests.csproj", "{202BCB4F-78AF-4E9A-B286-C3147374EB53}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Novaloop.PaymoApi.sln.DotSettings.user b/Novaloop.PaymoApi.sln.DotSettings.user new file mode 100644 index 0000000..b3245c8 --- /dev/null +++ b/Novaloop.PaymoApi.sln.DotSettings.user @@ -0,0 +1,4 @@ + + <SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from &lt;Novaloop.PaymoApi.IntegrationTests&gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <Project Location="/home/riscie/novaloop/libs/Novaloop.paymoapi/tests" Presentation="&lt;Novaloop.PaymoApi.IntegrationTests&gt;" /> +</SessionState> \ No newline at end of file diff --git a/src/ClientContacts/IPaymoClientContactsApi.cs b/src/ClientContacts/IPaymoClientContactsApi.cs new file mode 100644 index 0000000..8259570 --- /dev/null +++ b/src/ClientContacts/IPaymoClientContactsApi.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Novaloop.PaymoApi.ClientContacts.Models; + +namespace Novaloop.PaymoApi.ClientContacts +{ + public interface IPaymoClientContactsApi + { + Task> GetClientContacts(); + Task GetClientContact(int contactId); + Task CreateClientContact(PaymoClientContact clientContact); + + /// + /// Deleta a client contact + /// + /// + /// + Task DeleteClientContact(int clientContactId); + } +} \ No newline at end of file diff --git a/src/ClientContacts/Models/GetClientContactsResponse.cs b/src/ClientContacts/Models/GetClientContactsResponse.cs new file mode 100644 index 0000000..273d710 --- /dev/null +++ b/src/ClientContacts/Models/GetClientContactsResponse.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace Novaloop.PaymoApi.ClientContacts.Models +{ + public class GetClientContactsResponse + { + public IEnumerable ClientContacts { get; set; } + } +} \ No newline at end of file diff --git a/src/ClientContacts/Models/PaymoClientContact.cs b/src/ClientContacts/Models/PaymoClientContact.cs new file mode 100644 index 0000000..eb64528 --- /dev/null +++ b/src/ClientContacts/Models/PaymoClientContact.cs @@ -0,0 +1,44 @@ +using Newtonsoft.Json; +using Novaloop.PaymoApi.Shared; + +namespace Novaloop.PaymoApi.ClientContacts.Models +{ + public class PaymoClientContact : BasePaymoModel + { + [JsonProperty("client_id")] + public int ClientId { get; set; } + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("email")] + public string Email { get; set; } + + [JsonProperty("mobile")] + public string Mobile { get; set; } + + [JsonProperty("phone")] + public string Phone { get; set; } + + [JsonProperty("fax")] + public string Fax { get; set; } + + [JsonProperty("skype")] + public string Skype { get; set; } + + [JsonProperty("notes")] + public object Notes { get; set; } + + [JsonProperty("image")] + public string Image { get; set; } + + [JsonProperty("is_main")] + public bool IsMain { get; set; } + + [JsonProperty("position")] + public string Position { get; set; } + + [JsonProperty("access")] + public bool Access { get; set; } + } +} \ No newline at end of file diff --git a/src/ClientContacts/PaymoClientContactsApi.cs b/src/ClientContacts/PaymoClientContactsApi.cs new file mode 100644 index 0000000..06d32ac --- /dev/null +++ b/src/ClientContacts/PaymoClientContactsApi.cs @@ -0,0 +1,72 @@ +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.Extensions.Options; +using Novaloop.PaymoApi.ClientContacts.Models; +using Novaloop.PaymoApi.Extensions; +using Novaloop.PaymoApi.Shared; + +namespace Novaloop.PaymoApi.ClientContacts +{ + public class PaymoClientContactsApi : IPaymoClientContactsApi + { + private readonly PaymoApiOptions _options; + private readonly HttpClient _client; + private const string ResourceUri = "clientcontacts"; + + public PaymoClientContactsApi(PaymoApiClient paymoApiClient, IOptions options) + { + _options = options.Value; + _client = paymoApiClient.Client; + } + + /// + /// Receive all existing client contacts + /// + public async Task> GetClientContacts() + { + _client.SetApiKeyHeader(_options.ApiToken); + var response = await _client.GetAsync($"api/{ResourceUri}"); + await response.ThrowExceptionWithDetailsIfUnsuccessful(); + return (await response.Content.ReadAsAsync()).ClientContacts; + } + + /// + /// Retrieve an existing client contact by id + /// + /// id of the contact + /// + public async Task GetClientContact(int clientContactId) + { + _client.SetApiKeyHeader(_options.ApiToken); + var response = await _client.GetAsync($"api/{ResourceUri}/{clientContactId}"); + await response.ThrowExceptionWithDetailsIfUnsuccessful(); + return (await response.Content.ReadAsAsync()).ClientContacts.Single(); + } + + + /// + /// Create a new client contact + /// + public async Task CreateClientContact(PaymoClientContact clientContact) + { + _client.SetApiKeyHeader(_options.ApiToken); + var response = await _client.PostAsJsonAsync($"api/{ResourceUri}", clientContact); + await response.ThrowExceptionWithDetailsIfUnsuccessful(); + return (await response.Content.ReadAsAsync()).ClientContacts.Single(); + } + + /// + /// Deleta a client contact + /// + /// + /// + public async Task DeleteClientContact(int clientContactId) + { + _client.SetApiKeyHeader(_options.ApiToken); + var response = await _client.DeleteAsync($"api/{ResourceUri}/{clientContactId}"); + await response.ThrowExceptionWithDetailsIfUnsuccessful(); + } + } +} \ No newline at end of file diff --git a/src/Clients/IPaymoClientsApi.cs b/src/Clients/IPaymoClientsApi.cs new file mode 100644 index 0000000..2d9e462 --- /dev/null +++ b/src/Clients/IPaymoClientsApi.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Novaloop.PaymoApi.Clients.Models; + +namespace Novaloop.PaymoApi.Clients +{ + public interface IPaymoClientsApi + { + Task> GetClients(); + Task GetClient(int clientId); + Task CreateClient(PaymoClient client); + Task DeleteClient(int clientId); + } +} \ No newline at end of file diff --git a/src/Clients/Models/GetClientsResponse.cs b/src/Clients/Models/GetClientsResponse.cs new file mode 100644 index 0000000..439be1f --- /dev/null +++ b/src/Clients/Models/GetClientsResponse.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace Novaloop.PaymoApi.Clients.Models +{ + public class GetClientsResponse + { + public IEnumerable Clients { get; set; } + } +} \ No newline at end of file diff --git a/src/Clients/Models/PaymoClient.cs b/src/Clients/Models/PaymoClient.cs new file mode 100644 index 0000000..1c58cbf --- /dev/null +++ b/src/Clients/Models/PaymoClient.cs @@ -0,0 +1,52 @@ +using Newtonsoft.Json; +using Novaloop.PaymoApi.Shared; + +namespace Novaloop.PaymoApi.Clients.Models +{ + public class PaymoClient : BasePaymoModel + { + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("address")] + public string Address { get; set; } + + [JsonProperty("city")] + public string City { get; set; } + + [JsonProperty("state")] + public string State { get; set; } + + [JsonProperty("postal_code")] + public string PostalCode { get; set; } + + [JsonProperty("country")] + public string Country { get; set; } + + [JsonProperty("phone")] + public string Phone { get; set; } + + [JsonProperty("fax")] + public string Fax { get; set; } + + [JsonProperty("email")] + public string Email { get; set; } + + [JsonProperty("website")] + public string Website { get; set; } + + [JsonProperty("image")] + public string Image { get; set; } + + [JsonProperty("fiscal_information")] + public string FiscalInformation { get; set; } + + [JsonProperty("active")] + public bool Active { get; set; } + + public override string ToString() + { + return $"[{Id}] {Name}"; + } + } +} \ No newline at end of file diff --git a/src/Clients/PaymoClientsApi.cs b/src/Clients/PaymoClientsApi.cs new file mode 100644 index 0000000..8f351c7 --- /dev/null +++ b/src/Clients/PaymoClientsApi.cs @@ -0,0 +1,72 @@ +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.Extensions.Options; +using Novaloop.PaymoApi.Clients.Models; +using Novaloop.PaymoApi.Extensions; +using Novaloop.PaymoApi.Shared; + +namespace Novaloop.PaymoApi.Clients +{ + public class PaymoClientsApi : IPaymoClientsApi + { + private readonly PaymoApiOptions _options; + private readonly HttpClient _client; + private const string ResourceUri = "clients"; + + public PaymoClientsApi(PaymoApiClient paymoApiClient, IOptions options) + { + _options = options.Value; + _client = paymoApiClient.Client; + } + + /// + /// Receive all existing clients + /// + public async Task> GetClients() + { + _client.SetApiKeyHeader(_options.ApiToken); + var response = await _client.GetAsync($"api/{ResourceUri}"); + await response.ThrowExceptionWithDetailsIfUnsuccessful(); + return (await response.Content.ReadAsAsync()).Clients; + } + + /// + /// Retrieve an existing client by id + /// + /// id of the contact + /// + public async Task GetClient(int clientId) + { + _client.SetApiKeyHeader(_options.ApiToken); + var response = await _client.GetAsync($"api/{ResourceUri}/{clientId}"); + await response.ThrowExceptionWithDetailsIfUnsuccessful(); + return (await response.Content.ReadAsAsync()).Clients.Single(); + } + + + /// + /// Create a new client + /// + public async Task CreateClient(PaymoClient client) + { + _client.SetApiKeyHeader(_options.ApiToken); + var response = await _client.PostAsJsonAsync($"api/{ResourceUri}", client); + await response.ThrowExceptionWithDetailsIfUnsuccessful(); + return (await response.Content.ReadAsAsync()).Clients.Single(); + } + + /// + /// Delete a client + /// + /// + /// + public async Task DeleteClient(int clientId) + { + _client.SetApiKeyHeader(_options.ApiToken); + var response = await _client.DeleteAsync($"api/{ResourceUri}/{clientId}"); + await response.ThrowExceptionWithDetailsIfUnsuccessful(); + } + } +} \ No newline at end of file diff --git a/src/Extensions/PaymoApiExtensions.cs b/src/Extensions/PaymoApiExtensions.cs index f535b47..b0217f8 100644 --- a/src/Extensions/PaymoApiExtensions.cs +++ b/src/Extensions/PaymoApiExtensions.cs @@ -1,6 +1,8 @@ using System; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; +using Novaloop.PaymoApi.ClientContacts; +using Novaloop.PaymoApi.Clients; using Novaloop.PaymoApi.Shared; using Novaloop.PaymoApi.Tasks; @@ -13,7 +15,9 @@ namespace Novaloop.PaymoApi.Extensions services.Configure(options); var resolvedOptions = (IOptions) services.BuildServiceProvider().GetService(typeof(IOptions)); services.AddHttpClient(client => { client.BaseAddress = new Uri(resolvedOptions.Value.BaseUrl); }); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); return services; } } diff --git a/src/Novaloop.PaymoApi.csproj b/src/Novaloop.PaymoApi.csproj index 7060951..3db115d 100644 --- a/src/Novaloop.PaymoApi.csproj +++ b/src/Novaloop.PaymoApi.csproj @@ -1,19 +1,19 @@ - - netstandard2.0 - Novaloop.PaymoApi - Access your paymo instance for asp.net core - api;paymo;asp.net core; - 0.1.9 - Matthias Langhard - Novaloop AG - https://gitlab.com/novaloop-oss/novaloop.paymoapi - + + netstandard2.0 + Novaloop.PaymoApi + Access your paymo instance for asp.net core + api;paymo;asp.net core; + 1.0.0 + Matthias Langhard + Novaloop AG + https://gitlab.com/novaloop-oss/novaloop.paymoapi + - - - - + + + + diff --git a/src/Shared/BasePaymoModel.cs b/src/Shared/BasePaymoModel.cs new file mode 100644 index 0000000..048577b --- /dev/null +++ b/src/Shared/BasePaymoModel.cs @@ -0,0 +1,11 @@ +using System; + +namespace Novaloop.PaymoApi.Shared +{ + public class BasePaymoModel + { + public int Id { get; set; } + public DateTime CreatedOn { get; set; } + public DateTime UpdatedOn { get; set; } + } +} \ No newline at end of file diff --git a/src/Tasks/IPaymoTasksApi.cs b/src/Tasks/IPaymoTasksApi.cs new file mode 100644 index 0000000..1f28dfb --- /dev/null +++ b/src/Tasks/IPaymoTasksApi.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Novaloop.PaymoApi.Tasks.Models; + +namespace Novaloop.PaymoApi.Tasks +{ + public interface IPaymoTasksApi + { + Task> GetTasks(); + Task GetTask(int taskId); + Task CreateTask(PaymoTask task); + Task DeleteTask(int taskId); + } +} \ No newline at end of file diff --git a/src/Tasks/IPaymoTasksApiService.cs b/src/Tasks/IPaymoTasksApiService.cs deleted file mode 100644 index e86d866..0000000 --- a/src/Tasks/IPaymoTasksApiService.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Threading.Tasks; -using Novaloop.PaymoApi.Tasks.Models; - -namespace Novaloop.PaymoApi.Tasks -{ - public interface IPaymoTasksApiService - { - Task GetTasks(); - Task GetTask(int taskId); - Task CreateTask(CreateTaskRequest createTask); - } -} \ No newline at end of file diff --git a/src/Tasks/Models/CreateTaskRequest.cs b/src/Tasks/Models/CreateTaskRequest.cs deleted file mode 100644 index 880c501..0000000 --- a/src/Tasks/Models/CreateTaskRequest.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Collections.Generic; -using Newtonsoft.Json; - -namespace Novaloop.PaymoApi.Tasks.Models -{ - public class CreateTaskRequest - { - [JsonProperty(PropertyName = "name")] - public string Name { get; set; } - - [JsonProperty(PropertyName = "description")] - public string Description { get; set; } - - [JsonProperty(PropertyName = "tasklist_id")] - public int TasklistId { get; set; } - - [JsonProperty(PropertyName = "users")] - public List Users { get; set; } - } -} \ No newline at end of file diff --git a/src/Tasks/Models/CreateTaskResponse.cs b/src/Tasks/Models/CreateTaskResponse.cs deleted file mode 100644 index 2c5fa15..0000000 --- a/src/Tasks/Models/CreateTaskResponse.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Novaloop.PaymoApi.Tasks.Models -{ - public class CreateTaskResponse : PaymoTask - { - - } -} \ No newline at end of file diff --git a/src/Tasks/Models/PaymoTask.cs b/src/Tasks/Models/PaymoTask.cs index b7a31c5..1cdcc04 100644 --- a/src/Tasks/Models/PaymoTask.cs +++ b/src/Tasks/Models/PaymoTask.cs @@ -1,25 +1,53 @@ -using System; using System.Collections.Generic; +using Newtonsoft.Json; +using Novaloop.PaymoApi.Shared; namespace Novaloop.PaymoApi.Tasks.Models { - public class PaymoTask + public class PaymoTask : BasePaymoModel { - public int Id { get; set; } + [JsonProperty("name")] public string Name { get; set; } + + [JsonProperty("code")] public string Code { get; set; } + + [JsonProperty("project_id")] public int ProjectId { get; set; } + + [JsonProperty("tasklist_id")] public int TasklistId { get; set; } + + [JsonProperty("user_id")] public int UserId { get; set; } + + [JsonProperty("complete")] public bool Complete { get; set; } + + [JsonProperty("billable")] public bool Billable { get; set; } + + [JsonProperty("seq")] public int Seq { get; set; } + + [JsonProperty("description")] public string Description { get; set; } + + [JsonProperty("price_per_hour")] public object PricePerHour { get; set; } + + [JsonProperty("due_date")] public object DueDate { get; set; } + + [JsonProperty("budget_hours")] public object BudgetHours { get; set; } + + [JsonProperty("users")] public List Users { get; set; } - public DateTime CreatedOn { get; set; } - public DateTime UpdatedOn { get; set; } + + public override string ToString() + { + return $"[{Id}] {Name} ({TasklistId})"; + } } } \ No newline at end of file diff --git a/src/Tasks/PaymoTasksApi.cs b/src/Tasks/PaymoTasksApi.cs new file mode 100644 index 0000000..7da1cac --- /dev/null +++ b/src/Tasks/PaymoTasksApi.cs @@ -0,0 +1,73 @@ +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.Extensions.Options; +using Novaloop.PaymoApi.Extensions; +using Novaloop.PaymoApi.Shared; +using Novaloop.PaymoApi.Tasks.Models; + +namespace Novaloop.PaymoApi.Tasks +{ + public class PaymoTasksApi : IPaymoTasksApi + { + private readonly PaymoApiOptions _options; + private readonly HttpClient _client; + private const string ResourceUri = "tasks"; + + + public PaymoTasksApi(PaymoApiClient paymoApiClient, IOptions options) + { + _options = options.Value; + _client = paymoApiClient.Client; + } + + /// + /// Receive all existing tasks + /// + public async Task> GetTasks() + { + _client.SetApiKeyHeader(_options.ApiToken); + var response = await _client.GetAsync($"api/{ResourceUri}"); + await response.ThrowExceptionWithDetailsIfUnsuccessful(); + return (await response.Content.ReadAsAsync()).Tasks; + } + + /// + /// Retrieve an existing Task by id + /// + /// id of the task + /// + public async Task GetTask(int taskId) + { + _client.SetApiKeyHeader(_options.ApiToken); + var response = await _client.GetAsync($"api/{ResourceUri}/{taskId}"); + await response.ThrowExceptionWithDetailsIfUnsuccessful(); + return (await response.Content.ReadAsAsync()).Tasks.Single(); + } + + + /// + /// Creates a new Task + /// + public async Task CreateTask(PaymoTask task) + { + _client.SetApiKeyHeader(_options.ApiToken); + var response = await _client.PostAsJsonAsync($"api/{ResourceUri}", task); + await response.ThrowExceptionWithDetailsIfUnsuccessful(); + return (await response.Content.ReadAsAsync()).Tasks.Single(); + } + + /// + /// Delete a task + /// + /// + /// + public async Task DeleteTask(int taskId) + { + _client.SetApiKeyHeader(_options.ApiToken); + var response = await _client.DeleteAsync($"api/{ResourceUri}/{taskId}"); + await response.ThrowExceptionWithDetailsIfUnsuccessful(); + } + } +} \ No newline at end of file diff --git a/src/Tasks/PaymoTasksApiService.cs b/src/Tasks/PaymoTasksApiService.cs deleted file mode 100644 index 6dc4e57..0000000 --- a/src/Tasks/PaymoTasksApiService.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Microsoft.Extensions.Options; -using Novaloop.PaymoApi.Extensions; -using Novaloop.PaymoApi.Shared; -using Novaloop.PaymoApi.Tasks.Models; - -namespace Novaloop.PaymoApi.Tasks -{ - public class PaymoTasksApiService : IPaymoTasksApiService - { - private readonly PaymoApiOptions _options; - private readonly HttpClient _client; - - public PaymoTasksApiService(PaymoApiClient paymoApiClient, IOptions options) - { - _options = options.Value; - _client = paymoApiClient.Client; - } - - /// - /// Receive all existing tasks - /// - public async Task GetTasks() - { - _client.SetApiKeyHeader(_options.ApiToken); - var response = await _client.GetAsync($"api/tasks"); - await response.ThrowExceptionWithDetailsIfUnsuccessful(); - return await response.Content.ReadAsAsync(); - } - - /// - /// Retrieve an existing Task by id - /// - /// id of the task - /// - public async Task GetTask(int taskId) - { - _client.SetApiKeyHeader(_options.ApiToken); - var response = await _client.GetAsync($"api/tasks/{taskId}"); - await response.ThrowExceptionWithDetailsIfUnsuccessful(); - return await response.Content.ReadAsAsync(); - } - - - /// - /// Creates a new Task - /// - public async Task CreateTask(CreateTaskRequest createTaskRequest) - { - _client.SetApiKeyHeader(_options.ApiToken); - var response = await _client.PostAsJsonAsync("api/tasks", createTaskRequest); - await response.ThrowExceptionWithDetailsIfUnsuccessful(); - return await response.Content.ReadAsAsync(); - } - } -} \ No newline at end of file diff --git a/tests/DependencyFactory.cs b/tests/DependencyFactory.cs new file mode 100644 index 0000000..cea5287 --- /dev/null +++ b/tests/DependencyFactory.cs @@ -0,0 +1,34 @@ +using System; +using System.Net.Http; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; +using Novaloop.PaymoApi.Extensions; +using Novaloop.PaymoApi.Shared; + +namespace Novaloop.PaymoApi.Tests +{ + public static class DependencyFactory + { + public static PaymoApiClient GeneratePaymoApiClient() + { + return new PaymoApiClient(new HttpClient {BaseAddress = new Uri("https://app.paymoapp.com/")}); + } + + public static IOptions GenerateOptions() + { + var paymoToken = new ConfigurationBuilder() + .SetBasePath(AppContext.BaseDirectory) + .AddJsonFile("appsettings.tests.json", true, true) + .AddEnvironmentVariables() + .Build() + .GetSection("PaymoApiIntegrationTests:PaymoTestProjectToken").Value; + + if (string.IsNullOrWhiteSpace(paymoToken)) + { + throw new ArgumentException("Please set the environment variable 'PAYMOAPIINTEGRATIONTESTS__PAYMOTESTPROJECTTOKEN' with the token of your paymo test-project. Look inside Bitwarden if you work @ Novaloop."); + } + + return Options.Create(new PaymoApiOptions {ApiToken = paymoToken}); + } + } +} \ No newline at end of file diff --git a/tests/Novaloop.PaymoApi.IntegrationTests.csproj b/tests/Novaloop.PaymoApi.IntegrationTests.csproj new file mode 100644 index 0000000..3823077 --- /dev/null +++ b/tests/Novaloop.PaymoApi.IntegrationTests.csproj @@ -0,0 +1,33 @@ + + + + netcoreapp3.1 + + false + + Novaloop.PaymoApi.Tests + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + Always + + + + diff --git a/tests/Novaloop.PaymoApi.Tests.csproj b/tests/Novaloop.PaymoApi.Tests.csproj deleted file mode 100644 index f35f1c1..0000000 --- a/tests/Novaloop.PaymoApi.Tests.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - netcoreapp3.1 - - false - - - - - - - - - diff --git a/tests/PaymoClientContactsApiTests.cs b/tests/PaymoClientContactsApiTests.cs new file mode 100644 index 0000000..f3b085f --- /dev/null +++ b/tests/PaymoClientContactsApiTests.cs @@ -0,0 +1,89 @@ +using System.Linq; +using Novaloop.PaymoApi.ClientContacts; +using Novaloop.PaymoApi.ClientContacts.Models; +using Novaloop.PaymoApi.Clients; +using Xunit; + +namespace Novaloop.PaymoApi.Tests +{ + public class PaymoClientContactsApiTests + { + private readonly PaymoClientContactsApi _paymoClientContactsApi; + private readonly PaymoClientsApi _paymoClientsApi; + + private readonly PaymoClientContact _testClientContact = new PaymoClientContact + { + Name = "Testclient", + Email = "test@client.de" + }; + + + public PaymoClientContactsApiTests() + { + _paymoClientContactsApi = new PaymoClientContactsApi(DependencyFactory.GeneratePaymoApiClient(), DependencyFactory.GenerateOptions()); + _paymoClientsApi = new PaymoClientsApi(DependencyFactory.GeneratePaymoApiClient(), DependencyFactory.GenerateOptions()); + } + + + [Fact] + public async void GetClientContacts() + { + // Arrange + + // Act + var clientContacts = (await _paymoClientContactsApi.GetClientContacts()).ToList(); + + // Assert + Assert.NotEmpty(clientContacts); + } + + [Fact] + public async void GetClientContact() + { + // Arrange + + // Act + var clientContacts = (await _paymoClientContactsApi.GetClientContacts()).ToList(); + var clientContact = await _paymoClientContactsApi.GetClientContact(clientContacts.First().Id); + + // Assert + Assert.NotNull(clientContact); + } + + [Fact] + public async void CreateClientContact() + { + // Arrange + var existingClientContact = (await _paymoClientsApi.GetClients()).First(); + + // Act + _testClientContact.ClientId = existingClientContact.Id; + var createdClientContact = await _paymoClientContactsApi.CreateClientContact(_testClientContact); + var clientContact = await _paymoClientContactsApi.GetClientContact(createdClientContact.Id); + + // Assert + Assert.Equal(_testClientContact.Name, clientContact.Name); + Assert.Equal(_testClientContact.Email, clientContact.Email); + + // Cleanup + await _paymoClientContactsApi.DeleteClientContact(createdClientContact.Id); + } + + [Fact] + public async void DeleteClientContact() + { + // Arrange + var existingClientContact = (await _paymoClientsApi.GetClients()).First(); + _testClientContact.ClientId = existingClientContact.Id; + var createdClientContact = await _paymoClientContactsApi.CreateClientContact(_testClientContact); + + // Act + await _paymoClientContactsApi.DeleteClientContact(createdClientContact.Id); + var clientContacts = (await _paymoClientContactsApi.GetClientContacts()).ToList(); + + + // Assert + Assert.Empty(clientContacts.Where(c => c.Id == createdClientContact.Id)); + } + } +} \ No newline at end of file diff --git a/tests/PaymoClientsApiTests.cs b/tests/PaymoClientsApiTests.cs new file mode 100644 index 0000000..b3543d8 --- /dev/null +++ b/tests/PaymoClientsApiTests.cs @@ -0,0 +1,81 @@ +using System.Linq; +using Novaloop.PaymoApi.Clients; +using Novaloop.PaymoApi.Clients.Models; +using Xunit; + +namespace Novaloop.PaymoApi.Tests +{ + public class PaymoClientsApiTests + { + private readonly PaymoClientsApi _paymoClientsApi; + + private readonly PaymoClient _testClient = new PaymoClient + { + Name = "Testclient", + Email = "test@client.de" + }; + + public PaymoClientsApiTests() + { + _paymoClientsApi = new PaymoClientsApi(DependencyFactory.GeneratePaymoApiClient(), DependencyFactory.GenerateOptions()); + } + + + [Fact] + public async void GetClients() + { + // Arrange + + // Act + var clients = (await _paymoClientsApi.GetClients()).ToList(); + + // Assert + Assert.NotEmpty(clients); + } + + [Fact] + public async void GetClient() + { + // Arrange + + // Act + var clients = (await _paymoClientsApi.GetClients()).ToList(); + var client = await _paymoClientsApi.GetClient(clients.First().Id); + + // Assert + Assert.NotNull(client); + } + + [Fact] + public async void CreateClient() + { + // Arrange + + // Act + var createdClient = await _paymoClientsApi.CreateClient(_testClient); + var client = await _paymoClientsApi.GetClient(createdClient.Id); + + // Assert + Assert.Equal(_testClient.Name, client.Name); + Assert.Equal(_testClient.Email, client.Email); + + // Cleanup + await _paymoClientsApi.DeleteClient(createdClient.Id); + } + + [Fact] + public async void DeleteClient() + { + // Arrange + var createdClient = await _paymoClientsApi.CreateClient(_testClient); + + // Act + await _paymoClientsApi.DeleteClient(createdClient.Id); + var clients = (await _paymoClientsApi.GetClients()).ToList(); + + + // Assert + Assert.Empty(clients.Where(c => c.Id == createdClient.Id)); + } + } +} \ No newline at end of file diff --git a/tests/PaymoTasksApiTests.cs b/tests/PaymoTasksApiTests.cs new file mode 100644 index 0000000..9bbf56e --- /dev/null +++ b/tests/PaymoTasksApiTests.cs @@ -0,0 +1,89 @@ +using System.Linq; +using Novaloop.PaymoApi.Tasks; +using Novaloop.PaymoApi.Tasks.Models; +using Xunit; +using Xunit.Abstractions; + +namespace Novaloop.PaymoApi.Tests +{ + public class PaymoTasksApiTests + { + private readonly ITestOutputHelper _testOutputHelper; + private readonly PaymoTasksApi _paymoTasksApi; + private readonly PaymoTask _testTask; + + public PaymoTasksApiTests(ITestOutputHelper testOutputHelper) + { + _testOutputHelper = testOutputHelper; + _paymoTasksApi = new PaymoTasksApi(DependencyFactory.GeneratePaymoApiClient(), DependencyFactory.GenerateOptions()); + _testTask = new PaymoTask + { + Name = "Testtask", + Description = "Just a little task" + }; + } + + + [Fact] + public async void GetTasks() + { + // Arrange + + // Act + var tasks = (await _paymoTasksApi.GetTasks()).ToList(); + + // Assert + Assert.NotEmpty(tasks); + _testOutputHelper.WriteLine(string.Join(",", tasks)); + } + + [Fact] + public async void GetTask() + { + // Arrange + + // Act + var tasks = (await _paymoTasksApi.GetTasks()).ToList(); + var task = await _paymoTasksApi.GetTask(tasks.First().Id); + + // Assert + Assert.NotNull(task); + } + + [Fact] + public async void CreateTask() + { + // Arrange + var existingTaskListId = (await _paymoTasksApi.GetTasks()).First().TasklistId; + + // Act + _testTask.TasklistId = existingTaskListId; + var createdTask = await _paymoTasksApi.CreateTask(_testTask); + var task = await _paymoTasksApi.GetTask(createdTask.Id); + + // Assert + Assert.Equal(_testTask.Name, task.Name); + Assert.Equal(_testTask.Description, task.Description); + + // Cleanup + await _paymoTasksApi.DeleteTask(createdTask.Id); + } + + [Fact] + public async void DeleteTask() + { + // Arrange + var existingTaskListId = (await _paymoTasksApi.GetTasks()).First().TasklistId; + _testTask.TasklistId = existingTaskListId; + var createdTask = await _paymoTasksApi.CreateTask(_testTask); + + // Act + await _paymoTasksApi.DeleteTask(createdTask.Id); + var tasks = (await _paymoTasksApi.GetTasks()).ToList(); + + + // Assert + Assert.Empty(tasks.Where(c => c.Id == createdTask.Id)); + } + } +} \ No newline at end of file diff --git a/tests/UnitTest1.cs b/tests/UnitTest1.cs deleted file mode 100644 index 3ce4835..0000000 --- a/tests/UnitTest1.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Xunit; - -namespace Novaloop.PaymoApi.Tests -{ - public class UnitTest1 - { - [Fact] - public void Test1() - { - Assert.True(true); - } - } -} \ No newline at end of file