Skip to content

Commit

Permalink
[add] UpdateOrders extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
kroniak committed Jul 13, 2017
1 parent 1501f13 commit a2bca45
Show file tree
Hide file tree
Showing 7 changed files with 726 additions and 633 deletions.
2 changes: 1 addition & 1 deletion EcwidExtensions.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
<s:Boolean x:Key="/Default/Environment/Exceptional/IsDocumentationOfExceptionSubtypeSufficientForReferenceExpressions/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/Exceptional/IsDocumentationOfExceptionSubtypeSufficientForThrowStatements/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EXml_002ECodeStyle_002EFormatSettingsUpgrade_002EXmlMoveToCommonFormatterSettingsUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue">&lt;data&gt;&lt;IncludeFilters /&gt;&lt;ExcludeFilters&gt;&lt;Filter ModuleMask="Ecwid.Test" ModuleVersionMask="*" ClassMask="Ecwid.Test.Tools.*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="Ecwid.Test" ModuleVersionMask="*" ClassMask="Ecwid.Test.Services.*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="Ecwid.Test" ModuleVersionMask="*" ClassMask="Ecwid.Test.Services.Legacy.*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="Ecwid.Test.Real" ModuleVersionMask="*" ClassMask="Ecwid.Test.Real.*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="Ecwid.Test" ModuleVersionMask="*" ClassMask="Ecwid.Models.*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="Ecwid.Test" ModuleVersionMask="*" ClassMask="Ecwid.Models.Legacy.*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="Ecwid.Test.Real" ModuleVersionMask="*" ClassMask="Ecwid.Models.Legacy.*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="Ecwid.Test.Real" ModuleVersionMask="*" ClassMask="Ecwid.Models.*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="xunit.core" ModuleVersionMask="*" ClassMask="*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="xunit.assert" ModuleVersionMask="*" ClassMask="*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="xunit.execution.desktop" ModuleVersionMask="*" ClassMask="*" FunctionMask="*" IsEnabled="True" /&gt;&lt;/ExcludeFilters&gt;&lt;/data&gt;</s:String>
<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue">&lt;data&gt;&lt;IncludeFilters /&gt;&lt;ExcludeFilters&gt;&lt;Filter ModuleMask="Ecwid.Test" ModuleVersionMask="*" ClassMask="Ecwid.Test.Tools.*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="Ecwid.Test" ModuleVersionMask="*" ClassMask="Ecwid.Test.Services.*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="Ecwid.Test" ModuleVersionMask="*" ClassMask="Ecwid.Test.Services.Legacy.*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="Ecwid.Test.Real" ModuleVersionMask="*" ClassMask="Ecwid.Test.Real.*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="Ecwid.Test" ModuleVersionMask="*" ClassMask="Ecwid.Models.*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="Ecwid.Test" ModuleVersionMask="*" ClassMask="Ecwid.Models.Legacy.*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="Ecwid.Test.Real" ModuleVersionMask="*" ClassMask="Ecwid.Models.Legacy.*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="Ecwid.Test.Real" ModuleVersionMask="*" ClassMask="Ecwid.Models.*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="xunit.core" ModuleVersionMask="*" ClassMask="*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="xunit.assert" ModuleVersionMask="*" ClassMask="*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="xunit.execution.desktop" ModuleVersionMask="*" ClassMask="*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="Ecwid.Test" ModuleVersionMask="*" ClassMask="*" FunctionMask="*" IsEnabled="True" /&gt;&lt;/ExcludeFilters&gt;&lt;/data&gt;</s:String>
<s:String x:Key="/Default/CodeInspection/XmlDocInspections/ProjectExclusionRegex/@EntryValue">Test$</s:String>
</wpf:ResourceDictionary>
7 changes: 3 additions & 4 deletions src/Ecwid.OAuth/Ecwid.OAuth.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard1.3</TargetFramework>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.0.0-rc</Version>
<Version>1.0.0-rc2</Version>
<Authors>me@kroniak.net</Authors>
<Company>Kroniak</Company>
<Description>ASP.NET Core OAuth2 middleware for Ecwid API v3</Description>
Expand All @@ -18,15 +18,14 @@

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\netstandard1.3\Ecwid.OAuth.xml</DocumentationFile>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PropertyGroup>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OAuth" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OAuth" Version="1.1.2" />
</ItemGroup>

</Project>
5 changes: 2 additions & 3 deletions src/Ecwid/Ecwid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard1.4;net45</TargetFrameworks>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.0.0-rc</Version>
<Version>1.0.0-rc2</Version>
<Authors>me@kroniak.net</Authors>
<Description>C# services and models classes to Ecwid API v1 and v3</Description>
<PackageLicenseUrl>https://raw.githubusercontent.com/kroniak/extensions-ecwid/master/LICENSE</PackageLicenseUrl>
Expand All @@ -18,10 +18,9 @@

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\netstandard1.4\Ecwid.xml</DocumentationFile>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PropertyGroup>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>

Expand Down
36 changes: 28 additions & 8 deletions src/Ecwid/Services/EcwidClientOrders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async Task<List<OrderEntry>> GetNewOrdersAsync()
/// <exception cref="EcwidHttpException">Something happened to the HTTP call.</exception>
/// <exception cref="EcwidConfigException">Credentials are invalid.</exception>
public async Task<List<OrderEntry>> GetNewOrdersAsync(CancellationToken cancellationToken)
=> await GetOrdersAsync(new {fulfillmentStatus = "AWAITING_PROCESSING"}, cancellationToken);
=> await GetOrdersAsync(new { fulfillmentStatus = "AWAITING_PROCESSING" }, cancellationToken);

/// <summary>
/// Gets the non paid orders asynchronous.
Expand All @@ -73,7 +73,7 @@ public async Task<List<OrderEntry>> GetNonPaidOrdersAsync()
/// <exception cref="EcwidHttpException">Something happened to the HTTP call.</exception>
/// <exception cref="EcwidConfigException">Credentials are invalid.</exception>
public async Task<List<OrderEntry>> GetNonPaidOrdersAsync(CancellationToken cancellationToken)
=> await GetOrdersAsync(new {paymentStatus = "AWAITING_PAYMENT"}, cancellationToken);
=> await GetOrdersAsync(new { paymentStatus = "AWAITING_PAYMENT" }, cancellationToken);

/// <summary>
/// Gets the orders count asynchronous.
Expand All @@ -90,7 +90,7 @@ public async Task<int> GetOrdersCountAsync()
/// <exception cref="EcwidHttpException">Something happened to the HTTP call.</exception>
/// <exception cref="EcwidConfigException">Credentials are invalid.</exception>
public async Task<int> GetOrdersCountAsync(CancellationToken cancellationToken)
=> (await GetApiAsync<SearchResult>(GetUrl("orders"), new {limit = 1}, cancellationToken)).Total;
=> (await GetApiAsync<SearchResult>(GetUrl("orders"), new { limit = 1 }, cancellationToken)).Total;

/// <summary>
/// Gets the paid and not shipped orders asynchronous.
Expand All @@ -109,7 +109,7 @@ public async Task<List<OrderEntry>> GetPaidNotShippedOrdersAsync()
public async Task<List<OrderEntry>> GetPaidNotShippedOrdersAsync(CancellationToken cancellationToken)
=>
await
GetOrdersAsync(new {paymentStatus = "PAID", fulfillmentStatus = "AWAITING_PROCESSING,PROCESSING"},
GetOrdersAsync(new { paymentStatus = "PAID", fulfillmentStatus = "AWAITING_PROCESSING,PROCESSING" },
cancellationToken);

/// <summary>
Expand All @@ -126,7 +126,7 @@ public async Task<List<OrderEntry>> GetShippedOrdersAsync()
/// <exception cref="EcwidHttpException">Something happened to the HTTP call.</exception>
/// <exception cref="EcwidConfigException">Credentials are invalid.</exception>
public async Task<List<OrderEntry>> GetShippedOrdersAsync(CancellationToken cancellationToken)
=> await GetOrdersAsync(new {fulfillmentStatus = "SHIPPED"}, cancellationToken);
=> await GetOrdersAsync(new { fulfillmentStatus = "SHIPPED" }, cancellationToken);

/// <summary>
/// Gets the orders asynchronous. If <paramref name="query" /> contains limit or offset parameters gets only one page.
Expand Down Expand Up @@ -170,7 +170,7 @@ public async Task<List<OrderEntry>> GetOrdersAsync(object query, CancellationTok
await
GetApiAsync<SearchResult>(
GetUrl("orders").SetQueryParams(
new {offset = response.Offset + response.Limit}), query, cancellationToken);
new { offset = response.Offset + response.Limit }), query, cancellationToken);

// ReSharper disable once ExceptionNotDocumentedOptional
if (response.Orders != null)
Expand All @@ -196,7 +196,7 @@ public async Task<List<OrderEntry>> GetIncompleteOrdersAsync()
/// <exception cref="EcwidConfigException">Credentials are invalid.</exception>
/// <exception cref="EcwidHttpException">Something happened to the HTTP call.</exception>
public async Task<List<OrderEntry>> GetIncompleteOrdersAsync(CancellationToken cancellationToken)
=> await GetOrdersAsync(new {paymentStatus = "INCOMPLETE"}, cancellationToken);
=> await GetOrdersAsync(new { paymentStatus = "INCOMPLETE" }, cancellationToken);

/// <summary>
/// Gets the one order asynchronous.
Expand All @@ -222,11 +222,31 @@ public async Task<OrderEntry> GetOrderAsync(int orderNumber, CancellationToken c
throw new ArgumentOutOfRangeException(nameof(orderNumber));

// ReSharper disable once RedundantAnonymousTypePropertyName
var orders = await GetOrdersAsync(new {orderNumber = orderNumber}, cancellationToken);
var orders = await GetOrdersAsync(new { orderNumber = orderNumber }, cancellationToken);

return orders.Count == 0 ? null : orders.FirstOrDefault();
}


/// <summary>
/// Update one order asynchronously.
/// </summary>
/// <param name="order">The order to update.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="EcwidConfigException">Order number is 0.</exception>
public async Task<UpdateStatus> UpdateOrderAsync(OrderEntry order, CancellationToken cancellationToken)
{
if (order.OrderNumber == 0) throw new EcwidConfigException("Order number is 0.");
return await PutApiAsync<UpdateStatus>(GetUrl($"orders/{order.OrderNumber}"), order, cancellationToken);
}

/// <summary>
/// Update one order asynchronously.
/// </summary>
/// <param name="order">The order to update.</param>
/// <exception cref="EcwidConfigException">Order number is 0.</exception>
public async Task<UpdateStatus> UpdateOrderAsync(OrderEntry order)
=> await UpdateOrderAsync(order, CancellationToken.None);
#endregion
}
}
15 changes: 15 additions & 0 deletions src/Ecwid/Services/Interfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,21 @@ public interface IEcwidOrdersClient : IEcwidOrdersClient<OrderEntry, UpdateStatu
/// <exception cref="EcwidConfigException">Credentials are invalid.</exception>
/// <exception cref="EcwidHttpException">Something happened to the HTTP call.</exception>
Task<OrderEntry> GetOrderAsync(int orderNumber, CancellationToken cancellationToken);

/// <summary>
/// Update one order asynchronously.
/// </summary>
/// <param name="order">The order to update.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="EcwidConfigException">Order number is 0.</exception>
Task<UpdateStatus> UpdateOrderAsync(OrderEntry order, CancellationToken cancellationToken);

/// <summary>
/// Update one order asynchronously.
/// </summary>
/// <param name="order">The order to update.</param>
/// <exception cref="EcwidConfigException">Order number is 0.</exception>
Task<UpdateStatus> UpdateOrderAsync(OrderEntry order);
}

/// <summary>
Expand Down
34 changes: 34 additions & 0 deletions test/Ecwid.Test/Real/ClientOrdersRealTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed under the GPL License, Version 3.0. See LICENSE in the git repository root for license information.

using System.Diagnostics.CodeAnalysis;
using System.Net;
using Ecwid.Models;
using Xunit;

namespace Ecwid.Test.Real
Expand Down Expand Up @@ -83,5 +85,37 @@ public async void GetOrdersCountAsync()

Assert.Equal(1021, result);
}

[Fact]
public async void UpdateOrderAsync()
{
IEcwidOrdersClient client = new EcwidClient(_credentials)
{
Settings =
{
ApiUrl = "http://www.mocky.io/v2/5967f962110000b9006149e5"
}
};

var result = await client.UpdateOrderAsync(new OrderEntry { Email = "test@test.com", OrderNumber = 123 });

Assert.Equal(1, result.UpdateCount);
}

[Fact]
public async void UpdateOrderAsyncFail()
{
IEcwidOrdersClient client = new EcwidClient(_credentials)
{
Settings =
{
ApiUrl = "http://www.mocky.io/v2/5967f9f8110000b8006149e6"
}
};

var exception = await Assert.ThrowsAsync<EcwidHttpException>(() => client.UpdateOrderAsync(new OrderEntry { Email = "test@test.com", OrderNumber = 123 }));

Assert.Equal(HttpStatusCode.BadRequest, exception.StatusCode);
}
}
}
Loading

0 comments on commit a2bca45

Please sign in to comment.