Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to Create Warehouse, List Warehouses, Get Warehouse, Create Manifest, Liist Manifest, Get Manifest #75

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions ShipEngine.Tests/HttpResponseMocks/CreateWarehouse200Response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "Example Corp. East Warehouse",
"origin_address": {
"company_name": "Example Corp.",
"name": "John Doe",
"phone": "111-111-1111",
"address_line1": "4009 Marathon Blvd",
"address_line2": "Suite 300",
"city_locality": "Austin",
"state_province": "TX",
"postal_code": "78756",
"country_code": "US",
"address_residential_indicator": "no"
},
"return_address": {
"company_name": "Example Corp.",
"name": "John Doe",
"phone": "111-111-1111",
"address_line1": "4009 Marathon Blvd",
"address_line2": "Suite 300",
"city_locality": "Austin",
"state_province": "TX",
"postal_code": "78756",
"country_code": "US",
"address_residential_indicator": "no"
}
}
2 changes: 1 addition & 1 deletion ShipEngine.Tests/ShipEngine.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
<ProjectReference Include="..\ShipEngine\ShipEngine.csproj" />
</ItemGroup>

<ProjectExtensions><VisualStudio><UserProperties httpresponsemocks_4createimplicitmanifest200response_1json__JsonSchema="{" /></VisualStudio></ProjectExtensions>
<ProjectExtensions><VisualStudio><UserProperties /></VisualStudio></ProjectExtensions>

</Project>
87 changes: 87 additions & 0 deletions ShipEngine.Tests/ShipEngineMethodTests/CreateWarehouseTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using Moq;
using Newtonsoft.Json;
using ShipEngineSDK;
using ShipEngineSDK.Common.Enums;
using ShipEngineSDK.CreateWarehouse;
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Xunit;

namespace ShipEngineTest
{
public class CreateWarehouseTest
{

public TestUtils TestUtils;

public Params Params;

public CreateWarehouseTest()
{

Params = new Params()
{
IsDefault = true,
Name = "Warehouse 1",
OriginAddress = new ShipEngineSDK.Common.Address()
{
Name = "John Doe",
AddressLine1 = "4009 Marathon Blvd",
CityLocality = "Austin",
StateProvince = "TX",
PostalCode = "78756",
CountryCode = Country.US,
Phone = "512-555-5555"
},
ReturnAddress = new ShipEngineSDK.Common.Address()
{
Name = "John Doe",
AddressLine1 = "4009 Marathon Blvd",
CityLocality = "Austin",
StateProvince = "TX",
PostalCode = "78756",
CountryCode = Country.US,
Phone = "512-555-5555"
},
};

TestUtils = new TestUtils();
}

[Fact]
public async void ValidCreateWarehouse()
{
var config = new Config("TEST_bTYAskEX6tD7vv6u/cZ/M4LaUSWBJ219+8S1jgFcnkk");
var mockShipEngineFixture = new MockShipEngineFixture(config);

string json = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "../../../HttpResponseMocks/CreateWarehouse200Response.json"));

mockShipEngineFixture.StubRequest(HttpMethod.Post, "/v1/warehouses", System.Net.HttpStatusCode.OK, json);

var result = await mockShipEngineFixture.ShipEngine.CreateWarehouse(Params, config);

Assert.Equal("se-277331", result.WarehouseId);
Assert.Equal("Example Corp. East Warehouse", result.Name);
Assert.Equal("2021-08-27T16:29:56.8779097Z", result.CreatedAt);
}

[Fact]
public async void InvalidRetriesInMethodCall()
{
var apiKeyString = "TEST_bTYAskEX6tD7vv6u/cZ/M4LaUSWBJ219+8S1jgFcnkk";

var config = new Config(apiKey: apiKeyString);
var mockHandler = new Mock<ShipEngine>(config);
var shipEngine = mockHandler.Object;

var ex = await Assert.ThrowsAsync<ShipEngineException>(async () => await shipEngine.CreateLabelFromRate(Params, methodConfig: new Config(apiKey: "12345", retries: -1)));
Assert.Equal(ErrorSource.Shipengine, ex.ErrorSource);
Assert.Equal(ErrorType.Validation, ex.ErrorType);
Assert.Equal(ErrorCode.InvalidFieldValue, ex.ErrorCode);
Assert.Equal("Retries must be greater than zero.", ex.Message);
Assert.Null(ex.RequestId);
}
}
}
16 changes: 16 additions & 0 deletions ShipEngine/Models/Dto/CreateWarehouse/Params.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace ShipEngineSDK.CreateWarehouse
{
using ShipEngineSDK.Common;
using System;
using System.Collections.Generic;
using System.Text;

public class Params
{
public bool IsDefault { get; set; }
public string Name { get; set; }
public Address OriginAddress { get; set; }
public Address ReturnAddress { get; set; }
public string WarehouseId { get; set; }
}
}
12 changes: 12 additions & 0 deletions ShipEngine/Models/Dto/CreateWarehouse/Result.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace ShipEngineSDK.ListWarehouse
{
using ShipEngineSDK.Warehouse;
using System;
using System.Collections.Generic;
using System.Text;

public class Result
{
public Warehouse.Result[] Warehouses { get; set; }
}
}
24 changes: 24 additions & 0 deletions ShipEngine/Models/Dto/ImportOrders/Params.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace ShipEngineSDK.ImportOrders
{
using ShipEngineSDK.Common;
using System;
using System.Collections.Generic;
using System.Text;

public class Params
{
public string OrderSourceId { get; set; }
public string OrderSourceNickname { get; set; }
public string OrderSourceCode { get; set; }
public string OrderSourceFriendlyName { get; set; }
public bool Active { get; set; }
public RefreshInfo RefreshInfo { get; set; }
}

public class RefreshInfo
{
public string Status { get; set; }
public string LastRefreshAttempt { get; set; }
public string RefreshDate { get; set; }
}
}
18 changes: 18 additions & 0 deletions ShipEngine/Models/Dto/ListManifest/Result.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#nullable disable

using ShipEngineSDK.Manifests;
using System.Collections.Generic;

namespace ShipEngineSDK.ListManifest
{
/// <summary>
/// List Carrier Results
/// </summary>
public class Result
{
/// <summary>
/// List of carriers associated with the account
/// </summary>
public List<Manifest> Manifests { get; set; }
}
}
113 changes: 113 additions & 0 deletions ShipEngine/Models/Dto/ListSalesOrder/Result.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#nullable disable

using ShipEngineSDK.Common;
using ShipEngineSDK.Common.Enums;
using System;
using System.Collections.Generic;

namespace ShipEngineSDK.ListSalesOrder
{
/// <summary>
/// List Carrier Results
/// </summary>
public class Result
{
public List<SalesOrder> SalesOrders { get; set; }
public int Total { get; set; }
}

public class SalesOrder
{
public string SalesOrderId { get; set; }
public string ExternalOrderId { get; set; }
public string ExternalOrderNumber { get; set; }
public OrderSource OrderSource { get; set; }
public SalesOrderStatus SalesOrderStatus { get; set; }
public DateTime? OrderDate { get; set; }
public DateTime? CreatedAt { get; set; }
public DateTime? ModifiedAt { get; set; }
public PaymentDetails PaymentDetails { get; set; }
public Customer Customer { get; set; }
public BillTo BillTo { get; set; }
public Address ShipTo { get; set; }
public SalesOrderItems SalesOrderItems { get; set; }
}

public class SalesOrderItems
{
public string SalesOrderItemId { get; set; }
public List<LineItemDetails> LineItemDetails { get; set; }
}

public class LineItemDetails
{
public string Name { get; set; }
public string Sku { get; set; }
public Weight Weight { get; set; }
public Address ShipTo { get; set; }
public RequestedShippingOptions RequestedShippingOptions { get; set; }
public PriceSummary PriceSummary { get; set; }
public int Quantity { get; set; }
public bool IsGift { get; set; }
}

public class PriceSummary
{
public MonetaryValue UnitPrice { get; set; }
public MonetaryValue EstimatedTax { get; set; }
public string EstimatedShipping { get; set; }
public MonetaryValue Total { get; set; }
}

public class RequestedShippingOptions
{
public string ShippingSerive { get; set; }
public DateTime? ShipDate { get; set; }
}

public class BillTo
{
public string Email { get; set; }
public Address Address { get; set; }
}

public class Customer
{
public string Name { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
}

public class PaymentDetails
{
public MonetaryValue Subtotal { get; set; }
public MonetaryValue EstimatesShipping { get; set; }
public MonetaryValue EstimatesTax { get; set; }
public MonetaryValue GrandTotal { get; set; }
}

public class SalesOrderStatus
{
public string PaymentStatus { get; set; }
public string FulfillmentStatus { get; set; }
public bool IsCancelled { get; set; }
}

public class OrderSource
{
public string OrderSourceId { get; set; }
public string OrderSourceNickname { get; set; }
public string OrderSourceCode { get; set; }
public string OrderSourceFriendlyName { get; set; }
public RefreshInfo RefreshInfo { get; set; }
public bool Active { get; set; }
}
public class RefreshInfo
{
public string Status { get; set; }
public string LastRefreshAttempt { get; set; }
public string RefreshDate { get; set; }
}


}
17 changes: 17 additions & 0 deletions ShipEngine/Models/Dto/ListWarehouse/Result.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace ShipEngineSDK.ListWarehouse
{
using ShipEngineSDK.Common;
using System;
using System.Collections.Generic;
using System.Text;

public class Params
{
public string WarehouseId { get; set; }
public bool IsDefault { get; set; }
public string Name { get; set; }
public string CreatedAt { get; set; }
public Address OriginAddress { get; set; }
public Address ReturnAddress { get; set; }
}
}
16 changes: 16 additions & 0 deletions ShipEngine/Models/Dto/Warehouse/Warehouse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace ShipEngineSDK.Warehouse
{
using ShipEngineSDK.Common;
using System;
using System.Collections.Generic;
using System.Text;

public class Result
{
public string WarehouseId { get; set; }
public string Name { get; set; }
public string CreatedAt { get; set; }
public Address OriginAddress { get; set; }
public Address ReturnAddress { get; set; }
}
}
Loading