1 Commits
0.1.9 ... 1.0.0

28 changed files with 775 additions and 145 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,5 @@
# Project specific
tests/appsettings.tests.json
# Created by https://www.gitignore.io/api/dotnetcore,jetbrains+all,visualstudiocode # Created by https://www.gitignore.io/api/dotnetcore,jetbrains+all,visualstudiocode
# Edit at https://www.gitignore.io/?templates=dotnetcore,jetbrains+all,visualstudiocode # Edit at https://www.gitignore.io/?templates=dotnetcore,jetbrains+all,visualstudiocode

View File

@@ -5,7 +5,7 @@ VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 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}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Novaloop.PaymoApi", "src\Novaloop.PaymoApi.csproj", "{A9612B7C-67C1-4B6B-8260-167079A31FAF}"
EndProject 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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@@ -0,0 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=dc84371d_002D5ed8_002D46d3_002Dac3d_002D11c77b97626a/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from &amp;lt;Novaloop.PaymoApi.IntegrationTests&amp;gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;Project Location="/home/riscie/novaloop/libs/Novaloop.paymoapi/tests" Presentation="&amp;lt;Novaloop.PaymoApi.IntegrationTests&amp;gt;" /&gt;
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>

View File

@@ -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<IEnumerable<PaymoClientContact>> GetClientContacts();
Task<PaymoClientContact> GetClientContact(int contactId);
Task<PaymoClientContact> CreateClientContact(PaymoClientContact clientContact);
/// <summary>
/// Deleta a client contact
/// </summary>
/// <param name="clientContactId"></param>
/// <returns></returns>
Task DeleteClientContact(int clientContactId);
}
}

View File

@@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace Novaloop.PaymoApi.ClientContacts.Models
{
public class GetClientContactsResponse
{
public IEnumerable<PaymoClientContact> ClientContacts { get; set; }
}
}

View File

@@ -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; }
}
}

View File

@@ -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<PaymoApiOptions> options)
{
_options = options.Value;
_client = paymoApiClient.Client;
}
/// <summary>
/// Receive all existing client contacts
/// </summary>
public async Task<IEnumerable<PaymoClientContact>> GetClientContacts()
{
_client.SetApiKeyHeader(_options.ApiToken);
var response = await _client.GetAsync($"api/{ResourceUri}");
await response.ThrowExceptionWithDetailsIfUnsuccessful();
return (await response.Content.ReadAsAsync<GetClientContactsResponse>()).ClientContacts;
}
/// <summary>
/// Retrieve an existing client contact by id
/// </summary>
/// <param name="clientContactId">id of the contact</param>
/// <returns></returns>
public async Task<PaymoClientContact> GetClientContact(int clientContactId)
{
_client.SetApiKeyHeader(_options.ApiToken);
var response = await _client.GetAsync($"api/{ResourceUri}/{clientContactId}");
await response.ThrowExceptionWithDetailsIfUnsuccessful();
return (await response.Content.ReadAsAsync<GetClientContactsResponse>()).ClientContacts.Single();
}
/// <summary>
/// Create a new client contact
/// </summary>
public async Task<PaymoClientContact> CreateClientContact(PaymoClientContact clientContact)
{
_client.SetApiKeyHeader(_options.ApiToken);
var response = await _client.PostAsJsonAsync($"api/{ResourceUri}", clientContact);
await response.ThrowExceptionWithDetailsIfUnsuccessful();
return (await response.Content.ReadAsAsync<GetClientContactsResponse>()).ClientContacts.Single();
}
/// <summary>
/// Deleta a client contact
/// </summary>
/// <param name="clientContactId"></param>
/// <returns></returns>
public async Task DeleteClientContact(int clientContactId)
{
_client.SetApiKeyHeader(_options.ApiToken);
var response = await _client.DeleteAsync($"api/{ResourceUri}/{clientContactId}");
await response.ThrowExceptionWithDetailsIfUnsuccessful();
}
}
}

View File

@@ -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<IEnumerable<PaymoClient>> GetClients();
Task<PaymoClient> GetClient(int clientId);
Task<PaymoClient> CreateClient(PaymoClient client);
Task DeleteClient(int clientId);
}
}

View File

@@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace Novaloop.PaymoApi.Clients.Models
{
public class GetClientsResponse
{
public IEnumerable<PaymoClient> Clients { get; set; }
}
}

View File

@@ -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}";
}
}
}

View File

@@ -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<PaymoApiOptions> options)
{
_options = options.Value;
_client = paymoApiClient.Client;
}
/// <summary>
/// Receive all existing clients
/// </summary>
public async Task<IEnumerable<PaymoClient>> GetClients()
{
_client.SetApiKeyHeader(_options.ApiToken);
var response = await _client.GetAsync($"api/{ResourceUri}");
await response.ThrowExceptionWithDetailsIfUnsuccessful();
return (await response.Content.ReadAsAsync<GetClientsResponse>()).Clients;
}
/// <summary>
/// Retrieve an existing client by id
/// </summary>
/// <param name="clientId">id of the contact</param>
/// <returns></returns>
public async Task<PaymoClient> GetClient(int clientId)
{
_client.SetApiKeyHeader(_options.ApiToken);
var response = await _client.GetAsync($"api/{ResourceUri}/{clientId}");
await response.ThrowExceptionWithDetailsIfUnsuccessful();
return (await response.Content.ReadAsAsync<GetClientsResponse>()).Clients.Single();
}
/// <summary>
/// Create a new client
/// </summary>
public async Task<PaymoClient> CreateClient(PaymoClient client)
{
_client.SetApiKeyHeader(_options.ApiToken);
var response = await _client.PostAsJsonAsync($"api/{ResourceUri}", client);
await response.ThrowExceptionWithDetailsIfUnsuccessful();
return (await response.Content.ReadAsAsync<GetClientsResponse>()).Clients.Single();
}
/// <summary>
/// Delete a client
/// </summary>
/// <param name="clientId"></param>
/// <returns></returns>
public async Task DeleteClient(int clientId)
{
_client.SetApiKeyHeader(_options.ApiToken);
var response = await _client.DeleteAsync($"api/{ResourceUri}/{clientId}");
await response.ThrowExceptionWithDetailsIfUnsuccessful();
}
}
}

View File

@@ -1,6 +1,8 @@
using System; using System;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Novaloop.PaymoApi.ClientContacts;
using Novaloop.PaymoApi.Clients;
using Novaloop.PaymoApi.Shared; using Novaloop.PaymoApi.Shared;
using Novaloop.PaymoApi.Tasks; using Novaloop.PaymoApi.Tasks;
@@ -13,7 +15,9 @@ namespace Novaloop.PaymoApi.Extensions
services.Configure(options); services.Configure(options);
var resolvedOptions = (IOptions<PaymoApiOptions>) services.BuildServiceProvider().GetService(typeof(IOptions<PaymoApiOptions>)); var resolvedOptions = (IOptions<PaymoApiOptions>) services.BuildServiceProvider().GetService(typeof(IOptions<PaymoApiOptions>));
services.AddHttpClient<PaymoApiClient>(client => { client.BaseAddress = new Uri(resolvedOptions.Value.BaseUrl); }); services.AddHttpClient<PaymoApiClient>(client => { client.BaseAddress = new Uri(resolvedOptions.Value.BaseUrl); });
services.AddTransient<IPaymoTasksApiService, PaymoTasksApiService>(); services.AddTransient<IPaymoTasksApi, PaymoTasksApi>();
services.AddTransient<IPaymoClientContactsApi, PaymoClientContactsApi>();
services.AddTransient<IPaymoClientsApi, PaymoClientsApi>();
return services; return services;
} }
} }

View File

@@ -1,19 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<PackageId>Novaloop.PaymoApi</PackageId> <PackageId>Novaloop.PaymoApi</PackageId>
<title>Access your paymo instance for asp.net core</title> <title>Access your paymo instance for asp.net core</title>
<PackageTags>api;paymo;asp.net core;</PackageTags> <PackageTags>api;paymo;asp.net core;</PackageTags>
<Version>0.1.9</Version> <Version>1.0.0</Version>
<Authors>Matthias Langhard</Authors> <Authors>Matthias Langhard</Authors>
<Company>Novaloop AG</Company> <Company>Novaloop AG</Company>
<PackageProjectUrl>https://gitlab.com/novaloop-oss/novaloop.paymoapi</PackageProjectUrl> <PackageProjectUrl>https://gitlab.com/novaloop-oss/novaloop.paymoapi</PackageProjectUrl>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" /> <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" /> <PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -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; }
}
}

View File

@@ -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<IEnumerable<PaymoTask>> GetTasks();
Task<PaymoTask> GetTask(int taskId);
Task<PaymoTask> CreateTask(PaymoTask task);
Task DeleteTask(int taskId);
}
}

View File

@@ -1,12 +0,0 @@
using System.Threading.Tasks;
using Novaloop.PaymoApi.Tasks.Models;
namespace Novaloop.PaymoApi.Tasks
{
public interface IPaymoTasksApiService
{
Task<GetTasksResponse> GetTasks();
Task<GetTasksResponse> GetTask(int taskId);
Task<CreateTaskResponse> CreateTask(CreateTaskRequest createTask);
}
}

View File

@@ -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<int> Users { get; set; }
}
}

View File

@@ -1,7 +0,0 @@
namespace Novaloop.PaymoApi.Tasks.Models
{
public class CreateTaskResponse : PaymoTask
{
}
}

View File

@@ -1,25 +1,53 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json;
using Novaloop.PaymoApi.Shared;
namespace Novaloop.PaymoApi.Tasks.Models namespace Novaloop.PaymoApi.Tasks.Models
{ {
public class PaymoTask public class PaymoTask : BasePaymoModel
{ {
public int Id { get; set; } [JsonProperty("name")]
public string Name { get; set; } public string Name { get; set; }
[JsonProperty("code")]
public string Code { get; set; } public string Code { get; set; }
[JsonProperty("project_id")]
public int ProjectId { get; set; } public int ProjectId { get; set; }
[JsonProperty("tasklist_id")]
public int TasklistId { get; set; } public int TasklistId { get; set; }
[JsonProperty("user_id")]
public int UserId { get; set; } public int UserId { get; set; }
[JsonProperty("complete")]
public bool Complete { get; set; } public bool Complete { get; set; }
[JsonProperty("billable")]
public bool Billable { get; set; } public bool Billable { get; set; }
[JsonProperty("seq")]
public int Seq { get; set; } public int Seq { get; set; }
[JsonProperty("description")]
public string Description { get; set; } public string Description { get; set; }
[JsonProperty("price_per_hour")]
public object PricePerHour { get; set; } public object PricePerHour { get; set; }
[JsonProperty("due_date")]
public object DueDate { get; set; } public object DueDate { get; set; }
[JsonProperty("budget_hours")]
public object BudgetHours { get; set; } public object BudgetHours { get; set; }
[JsonProperty("users")]
public List<int> Users { get; set; } public List<int> Users { get; set; }
public DateTime CreatedOn { get; set; }
public DateTime UpdatedOn { get; set; } public override string ToString()
{
return $"[{Id}] {Name} ({TasklistId})";
}
} }
} }

View File

@@ -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<PaymoApiOptions> options)
{
_options = options.Value;
_client = paymoApiClient.Client;
}
/// <summary>
/// Receive all existing tasks
/// </summary>
public async Task<IEnumerable<PaymoTask>> GetTasks()
{
_client.SetApiKeyHeader(_options.ApiToken);
var response = await _client.GetAsync($"api/{ResourceUri}");
await response.ThrowExceptionWithDetailsIfUnsuccessful();
return (await response.Content.ReadAsAsync<GetTasksResponse>()).Tasks;
}
/// <summary>
/// Retrieve an existing Task by id
/// </summary>
/// <param name="taskId">id of the task</param>
/// <returns></returns>
public async Task<PaymoTask> GetTask(int taskId)
{
_client.SetApiKeyHeader(_options.ApiToken);
var response = await _client.GetAsync($"api/{ResourceUri}/{taskId}");
await response.ThrowExceptionWithDetailsIfUnsuccessful();
return (await response.Content.ReadAsAsync<GetTasksResponse>()).Tasks.Single();
}
/// <summary>
/// Creates a new Task
/// </summary>
public async Task<PaymoTask> CreateTask(PaymoTask task)
{
_client.SetApiKeyHeader(_options.ApiToken);
var response = await _client.PostAsJsonAsync($"api/{ResourceUri}", task);
await response.ThrowExceptionWithDetailsIfUnsuccessful();
return (await response.Content.ReadAsAsync<GetTasksResponse>()).Tasks.Single();
}
/// <summary>
/// Delete a task
/// </summary>
/// <param name="taskId"></param>
/// <returns></returns>
public async Task DeleteTask(int taskId)
{
_client.SetApiKeyHeader(_options.ApiToken);
var response = await _client.DeleteAsync($"api/{ResourceUri}/{taskId}");
await response.ThrowExceptionWithDetailsIfUnsuccessful();
}
}
}

View File

@@ -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<PaymoApiOptions> options)
{
_options = options.Value;
_client = paymoApiClient.Client;
}
/// <summary>
/// Receive all existing tasks
/// </summary>
public async Task<GetTasksResponse> GetTasks()
{
_client.SetApiKeyHeader(_options.ApiToken);
var response = await _client.GetAsync($"api/tasks");
await response.ThrowExceptionWithDetailsIfUnsuccessful();
return await response.Content.ReadAsAsync<GetTasksResponse>();
}
/// <summary>
/// Retrieve an existing Task by id
/// </summary>
/// <param name="taskId">id of the task</param>
/// <returns></returns>
public async Task<GetTasksResponse> GetTask(int taskId)
{
_client.SetApiKeyHeader(_options.ApiToken);
var response = await _client.GetAsync($"api/tasks/{taskId}");
await response.ThrowExceptionWithDetailsIfUnsuccessful();
return await response.Content.ReadAsAsync<GetTasksResponse>();
}
/// <summary>
/// Creates a new Task
/// </summary>
public async Task<CreateTaskResponse> CreateTask(CreateTaskRequest createTaskRequest)
{
_client.SetApiKeyHeader(_options.ApiToken);
var response = await _client.PostAsJsonAsync("api/tasks", createTaskRequest);
await response.ThrowExceptionWithDetailsIfUnsuccessful();
return await response.Content.ReadAsAsync<CreateTaskResponse>();
}
}
}

View File

@@ -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<PaymoApiOptions> 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});
}
}
}

View File

@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
<RootNamespace>Novaloop.PaymoApi.Tests</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\Novaloop.PaymoApi.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.tests.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@@ -1,15 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.1"/>
<PackageReference Include="xunit" Version="2.4.1"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
</ItemGroup>
</Project>

View File

@@ -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));
}
}
}

View File

@@ -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));
}
}
}

View File

@@ -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));
}
}
}

View File

@@ -1,13 +0,0 @@
using Xunit;
namespace Novaloop.PaymoApi.Tests
{
public class UnitTest1
{
[Fact]
public void Test1()
{
Assert.True(true);
}
}
}