diff --git a/.gitignore b/.gitignore
index d77b99a..7662fa4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,6 +6,7 @@
*.user
*.userosscache
*.sln.docstates
+*.lock.json
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
diff --git a/KdtSdk.sln b/KdtSdk.sln
deleted file mode 100644
index 3b11c3d..0000000
--- a/KdtSdk.sln
+++ /dev/null
@@ -1,28 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Express 2013 for Windows Desktop
-VisualStudioVersion = 12.0.31101.0
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KdtSdk", "KdtSdk\KdtSdk.csproj", "{10BDEBE8-3AB2-4867-931E-2E352B1E2B72}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KdtTests", "KdtTests\KdtTests.csproj", "{81FEFD51-58CA-404B-9DCC-0BC9024BC4EE}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {10BDEBE8-3AB2-4867-931E-2E352B1E2B72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {10BDEBE8-3AB2-4867-931E-2E352B1E2B72}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {10BDEBE8-3AB2-4867-931E-2E352B1E2B72}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {10BDEBE8-3AB2-4867-931E-2E352B1E2B72}.Release|Any CPU.Build.0 = Release|Any CPU
- {81FEFD51-58CA-404B-9DCC-0BC9024BC4EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {81FEFD51-58CA-404B-9DCC-0BC9024BC4EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {81FEFD51-58CA-404B-9DCC-0BC9024BC4EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {81FEFD51-58CA-404B-9DCC-0BC9024BC4EE}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
-EndGlobal
diff --git a/KdtSdk/KdtSdk.csproj b/KdtSdk/KdtSdk.csproj
deleted file mode 100644
index 619f0c9..0000000
--- a/KdtSdk/KdtSdk.csproj
+++ /dev/null
@@ -1,125 +0,0 @@
-
-
-
-
- Debug
- AnyCPU
- {10BDEBE8-3AB2-4867-931E-2E352B1E2B72}
- Library
- Properties
- KdtSdk
- KdtSdk
- v4.0
- 512
-
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
- false
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
- false
-
-
-
- False
- ..\packages\Newtonsoft.Json.6.0.8\lib\net40\Newtonsoft.Json.dll
-
-
-
-
- ..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.IO.dll
-
-
-
- ..\packages\Microsoft.Net.Http.2.2.28\lib\net40\System.Net.Http.dll
-
-
- False
- ..\packages\Microsoft.Net.Http.2.2.28\lib\net40\System.Net.Http.Extensions.dll
-
-
- False
- ..\packages\Microsoft.Net.Http.2.2.28\lib\net40\System.Net.Http.Primitives.dll
-
-
- ..\packages\Microsoft.Net.Http.2.2.28\lib\net40\System.Net.Http.WebRequest.dll
-
-
- ..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.Runtime.dll
-
-
- ..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.Threading.Tasks.dll
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/KdtSdk/Properties/AssemblyInfo.cs b/KdtSdk/Properties/AssemblyInfo.cs
deleted file mode 100644
index e325af1..0000000
--- a/KdtSdk/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("KdtSdk")]
-[assembly: AssemblyDescription("A sdk to interact with Konduto's api")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Konduto")]
-[assembly: AssemblyProduct("KdtSdk")]
-[assembly: AssemblyCopyright("Copyright © 2015")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("6d3d889c-a4cb-4919-b595-11ebdac583fb")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/KdtSdk/app.config b/KdtSdk/app.config
deleted file mode 100644
index 0c93fe0..0000000
--- a/KdtSdk/app.config
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/KdtSdk/packages.config b/KdtSdk/packages.config
deleted file mode 100644
index bf72313..0000000
--- a/KdtSdk/packages.config
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/KdtTests/KdtTests.csproj b/KdtTests/KdtTests.csproj
deleted file mode 100644
index 6bfafda..0000000
--- a/KdtTests/KdtTests.csproj
+++ /dev/null
@@ -1,201 +0,0 @@
-
-
-
- Debug
- AnyCPU
- {81FEFD51-58CA-404B-9DCC-0BC9024BC4EE}
- Library
- Properties
- KdtTests
- KdtTests
- v4.0
- 512
- {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- 10.0
- $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
- $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages
- False
- UnitTest
-
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
- False
- ..\packages\Newtonsoft.Json.6.0.8\lib\net40\Newtonsoft.Json.dll
-
-
-
- ..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.IO.dll
-
-
- ..\packages\Microsoft.Net.Http.2.2.28\lib\net40\System.Net.Http.dll
-
-
- False
- ..\packages\Microsoft.Net.Http.2.2.28\lib\net40\System.Net.Http.Extensions.dll
-
-
- False
- ..\packages\Microsoft.Net.Http.2.2.28\lib\net40\System.Net.Http.Primitives.dll
-
-
- ..\packages\Microsoft.Net.Http.2.2.28\lib\net40\System.Net.Http.WebRequest.dll
-
-
- ..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.Runtime.dll
-
-
- ..\packages\Microsoft.Bcl.1.1.9\lib\net40\System.Threading.Tasks.dll
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- True
- True
- Resources.resx
-
-
-
-
-
- ResXFileCodeGenerator
- Resources.Designer.cs
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {10bdebe8-3ab2-4867-931e-2e352b1e2b72}
- KdtSdk
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- False
-
-
- False
-
-
- False
-
-
- False
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/KdtTests/KondutoTest.cs b/KdtTests/KondutoTest.cs
deleted file mode 100644
index b3f15e6..0000000
--- a/KdtTests/KondutoTest.cs
+++ /dev/null
@@ -1,724 +0,0 @@
-using KdtSdk;
-using KdtSdk.Exceptions;
-using KdtSdk.Models;
-using KdtTests.Factories;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
-using System;
-using System.Collections.Generic;
-using System.Net;
-using System.Net.Http;
-using System.Threading.Tasks;
-
-
-namespace KdtTests
-{
- [TestClass]
- public class KondutoTest
- {
- //static String AUTH_HEADER = "Basic VDczOEQ1MTZGMDlDQUIzQTJDMUVF";
- static String AUTH_HEADER = "VDczOEQ1MTZGMDlDQUIzQTJDMUVF";
- static String API_KEY = "T738D516F09CAB3A2C1EE";
-
- String ORDER_ID;
-
- JObject ANALYZE_ORDER_RESPONSE;
- KondutoOrder ORDER_FROM_FILE;
-
- JObject NOT_ANALYZE_ORDER_RESPONSE;
-
-
- int[] HTTP_STATUSES = {
- (int)HttpStatusCode.Unauthorized, // 401
- (int)HttpStatusCode.Forbidden, // 403
- (int)HttpStatusCode.NotFound, // 404
- 422, // 422
- (int)HttpStatusCode.MethodNotAllowed, // 425
- 429, // 429
- (int)HttpStatusCode.InternalServerError // 500
- };
-
- private Konduto konduto;
-
- [TestInitialize]
- public void Setup()
- {
- konduto = new Konduto(API_KEY);
-
- ANALYZE_ORDER_RESPONSE = JsonConvert.DeserializeObject(
- Properties.Resources.konduto_order);
-
- JToken jt;
- ANALYZE_ORDER_RESPONSE.TryGetValue("order", out jt);
- ORDER_FROM_FILE = KondutoModel.FromJson(jt.ToString());
- ORDER_ID = ORDER_FROM_FILE.Id;
-
- NOT_ANALYZE_ORDER_RESPONSE = JsonConvert.DeserializeObject(
- Properties.Resources.konduto_order_not_analyzed);
- }
-
- //[TestMethod]
- //public void TestProxy()
- //{
- // Konduto konduto = new Konduto("T738D516F09CAB3A2C1EE");
- // konduto.SetProxy("192.168.0.14:808", "user1", "1234");
-
- // KondutoCustomer Customer = new KondutoCustomer
- // {
- // Id = "28372",
- // Name = "KdtUser",
- // Email = "developer@example.com"
- // };
-
- // KondutoOrder order = new KondutoOrder
- // {
- // Id = ((Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString(),
- // Visitor = "38a9412f0b01b4dd1762ae424169a3e490d75c7a",
- // TotalAmount = 100.00,
- // Customer = Customer,
- // Analyze=true
- // };
-
- // try
- // {
- // konduto.Analyze(order);
- // Assert.IsTrue(order.Recommendation != KondutoRecommendation.none);
- // }
- // catch (KondutoException ex)
- // {
- // Assert.Fail("Konduto exception shouldn't happen here.");
- // }
- //}
-
- [TestMethod]
- public void GetOrderSuccessfullyTest()
- {
- Konduto kdt = new Konduto(API_KEY);
-
- var fakeResponseHandler = new FakeResponseHandler();
- var message = new HttpResponseMessage(HttpStatusCode.OK);
- message.Content = new StringContent(ANALYZE_ORDER_RESPONSE.ToString());
-
- var c = kdt.KondutoGetOrderUrl(ORDER_ID);
-
- fakeResponseHandler.AddFakeResponse(kdt.KondutoGetOrderUrl(ORDER_ID), message);
- kdt.__MessageHandler = fakeResponseHandler;
-
- var v = kdt.GetOrder(ORDER_ID);
-
- Assert.IsTrue(ORDER_FROM_FILE.Equals(kdt.GetOrder(ORDER_ID)));
- }
-
- [TestMethod]
- public void GetOrderErrorTest()
- {
- foreach (int code in HTTP_STATUSES)
- {
- try
- {
- var fakeResponseHandler = new FakeResponseHandler();
-
- var message = new HttpResponseMessage((HttpStatusCode)code);
- message.Content = new StringContent(ORDER_FROM_FILE.ToJson());
-
- fakeResponseHandler.AddFakeResponse(konduto.KondutoGetOrderUrl(ORDER_ID), message);
- konduto.__MessageHandler = fakeResponseHandler;
-
- konduto.GetOrder(ORDER_ID);
- Assert.Fail("Exception expected");
- }
- catch (KondutoHTTPException e)
- {
- //Ok
- }
- catch (Exception e)
- {
- Assert.Fail("KondutoHTTPException was expected");
- }
- }
- }
-
- [TestMethod]
- public void AnalyzeSuccessfullyTest()
- {
- var fakeResponseHandler = new FakeResponseHandler();
- var message = new HttpResponseMessage(HttpStatusCode.OK);
-
- message.Content = new StringContent(ANALYZE_ORDER_RESPONSE.ToString());
-
- fakeResponseHandler.AddFakeResponse(konduto.KondutoPostOrderUrl(), message);
- konduto.__MessageHandler = fakeResponseHandler;
-
- KondutoOrder orderToSend = KondutoOrderFactory.basicOrder();
- String s = orderToSend.ToJson();
- KondutoOrder orderResponse = null;
-
- Assert.IsTrue(orderToSend.Recommendation == KondutoRecommendation.none, "basic order should have no recommendation");
- Assert.IsTrue(orderToSend.Score == null, "basic order should have no score");
- Assert.IsNull(orderToSend.Geolocation, "basic order should have no geolocation");
- Assert.IsNull(orderToSend.Device, "basic order should have no device");
- Assert.IsNull(orderToSend.NavigationInfo, "basic order should have no navigation info");
- Assert.IsTrue(orderToSend.Analyze, "basic order should have analyze set to true");
-
- try
- {
- orderResponse = konduto.Analyze(orderToSend); // do analyze
- }
- catch (KondutoInvalidEntityException e)
- {
- Assert.Fail("order should be valid");
- }
- catch (KondutoUnexpectedAPIResponseException e)
- {
- Assert.Fail("server should respond with status 200");
- }
- catch (KondutoHTTPException e)
- {
- Assert.Fail("server should respond with status 200");
- }
-
- Double? actualScore = ORDER_FROM_FILE.Score;
- KondutoRecommendation? actualRecommendation = ORDER_FROM_FILE.Recommendation;
- KondutoGeolocation actualGeolocation = ORDER_FROM_FILE.Geolocation;
- KondutoDevice actualDevice = ORDER_FROM_FILE.Device;
- KondutoNavigationInfo actualNavigationInfo = ORDER_FROM_FILE.NavigationInfo;
-
- Assert.IsTrue(orderResponse.Geolocation.Equals(actualGeolocation));
- Assert.AreEqual(orderResponse.Recommendation, actualRecommendation);
- Assert.AreEqual(orderResponse.Device, actualDevice);
- Assert.AreEqual(orderResponse.NavigationInfo, actualNavigationInfo);
- Assert.AreEqual(orderResponse.Score, actualScore);
- }
-
- [TestMethod]
- public void PostIntegrationTest()
- {
- Konduto konduto = new Konduto("T738D516F09CAB3A2C1EE");
-
- KondutoCustomer Customer = new KondutoCustomer
- {
- Id = "28372",
- Name = "KdtUser",
- Email = "developer@example.com"
- };
-
- KondutoOrder order = new KondutoOrder
- {
- Id = ((Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString(),
- Visitor = "38a9412f0b01b4dd1762ae424169a3e490d75c7a",
- TotalAmount = 100.00,
- Customer = Customer,
- Analyze = true
- };
-
- try
- {
- konduto.Analyze(order);
- Assert.IsTrue(order.Recommendation != KondutoRecommendation.none);
- }
- catch (KondutoException ex)
- {
- Assert.Fail("Konduto exception shouldn't happen here.");
- }
- }
-
- [TestMethod]
- public void FullJsonIntegrationTest()
- {
- Konduto konduto = new Konduto("T738D516F09CAB3A2C1EE");
-
- KondutoCustomer Customer = new KondutoCustomer
- {
- Id = "28372",
- Name = "KdtUser",
- Email = "developer@example.com",
- TaxId = "613.815.776-10",
- Phone1 = "+559912345678",
- Phone2 = "(11)1234-5678",
- IsNew = false,
- IsVip = false,
- CreatedAt = "2014-12-21"
- };
-
- KondutoPayment payment = new KondutoCreditCardPayment
- {
- Type = KondutoPaymentType.credit,
- Status = KondutoCreditCardPaymentStatus.approved,
- Bin = "490172",
- Last4 = "0012",
- ExpirationDate = "052026"
- };
-
- KondutoAddress billing = new KondutoAddress
- {
- Name = "Mark Thompson",
- Address1 = "101 Maple Road",
- Address2 = "Apto 33",
- City = "Mato Grosso",
- State = "Cuiabá",
- Zip = "302798",
- Country = "BR"
- };
-
- KondutoAddress shipping = new KondutoAddress
- {
- Name = "Mark Thompson",
- Address1 = "101 Maple Road",
- Address2 = "Apto 33",
- City = "Mato Grosso",
- State = "Cuiabá",
- Zip = "302798",
- Country = "BR"
- };
-
- List payments = new List{
- payment
- };
-
- KondutoItem item1 = new KondutoItem
- {
- Sku = "9919023",
- ProductCode = "123456789999",
- Category = 100,
- Name = "Xbox One",
- Description = "Xbox One Promoção Com 2 Controles",
- UnitCost = 1999.99,
- Quantity = 1,
- CreatedAt = "2014-12-21"
- };
-
- KondutoItem item2 = new KondutoItem
- {
- Sku = "0017273",
- Category = 201,
- Name = "CD Nirvana Nevermind",
- Description = "CD Nirvana Nevermind",
- UnitCost = 29.90,
- Quantity = 2,
- Discount = 5.00
- };
-
- KondutoOrder order = new KondutoOrder
- {
- Id = ((Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString(),
- Visitor = "38a9412f0b01b4dd1762ae424169a3e490d75c7a",
- TotalAmount = 100.00,
- ShippingAmount = 6.00,
- TaxAmount = 12.00,
- Ip = "201.27.127.73",
- Currency = "BRL",
- Customer = Customer,
- Payments = payments,
- BillingAddress = billing,
- ShippingAddress = shipping,
- MessagesExchanged = 2,
- PurchasedAt = "2014-12-31T13:00:00Z",
- FirstMessage = "2014-12-31T13:00:00Z",
- ShoppingCart = new List{
- item1,
- item2
- },
- Analyze = true
- };
-
- try
- {
- konduto.Analyze(order);
- Assert.IsTrue(order.Recommendation != KondutoRecommendation.none);
- }
- catch (KondutoException ex)
- {
- Assert.Fail("Konduto exception shouldn't happen here.");
- }
-
- try
- {
- KondutoOrder getOrder = konduto.GetOrder(order.Id);
- Assert.IsNotNull(getOrder);
- }
- catch (KondutoException ex)
- {
- Assert.Fail("Konduto exception shouldn't happen here.");
- }
- }
-
- [TestMethod]
- public void PostBoletoIntegrationTest()
- {
- Konduto konduto = new Konduto("T738D516F09CAB3A2C1EE");
-
- KondutoCustomer Customer = new KondutoCustomer
- {
- Id = "28372",
- Name = "KdtUser",
- Email = "developer@example.com"
- };
-
- KondutoOrder order = new KondutoOrder
- {
- Id = ((Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString(),
- Visitor = "38a9412f0b01b4dd1762ae424169a3e490d75c7a",
- TotalAmount = 100.00,
- Customer = Customer,
- Payments = KondutoPaymentFactory.CreatePayments(),
- Analyze = true
- };
-
- try
- {
- konduto.Analyze(order);
- Assert.IsTrue(order.Recommendation != KondutoRecommendation.none);
- }
- catch (KondutoException ex)
- {
- Assert.Fail("Konduto exception shouldn't happen here.");
- }
- }
-
- [TestMethod]
- public void PostNonCreditIntegrationTest()
- {
- Konduto konduto = new Konduto("T738D516F09CAB3A2C1EE");
-
- KondutoCustomer Customer = new KondutoCustomer
- {
- Id = "28372",
- Name = "KdtUser",
- Email = "developer@example.com"
- };
-
- KondutoOrder order = new KondutoOrder
- {
- Id = ((Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString(),
- Visitor = "38a9412f0b01b4dd1762ae424169a3e490d75c7a",
- TotalAmount = 100.00,
- Customer = Customer,
- Payments = KondutoPaymentFactory.CreateNonCreditPayments(),
- Analyze = true
- };
-
- try
- {
- konduto.Analyze(order);
- Assert.IsTrue(order.Recommendation != KondutoRecommendation.none);
- }
- catch (KondutoException ex)
- {
- Assert.Fail("Konduto exception shouldn't happen here.");
- }
- }
-
- [TestMethod]
- public void GetIntegrationTest()
- {
- Konduto konduto = new Konduto("T738D516F09CAB3A2C1EE");
-
- try
- {
- KondutoOrder order = konduto.GetOrder("1429744771");
- }
- catch (KondutoException ex)
- {
- Assert.Fail("Konduto exception shouldn't happen here.");
- }
- }
-
- [TestMethod]
- public void PutIntegrationTest()
- {
- //String id = ((Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString();
- String id = "1429744771";
-
- Konduto konduto = new Konduto("T738D516F09CAB3A2C1EE");
-
- KondutoCustomer Customer = new KondutoCustomer
- {
- Id = "28372",
- Name = "KdtUser",
- Email = "developer@example.com"
- };
-
- KondutoOrder order = new KondutoOrder
- {
- Id = id,
- Visitor = "38a9412f0b01b4dd1762ae424169a3e490d75c7a",
- TotalAmount = 100.00,
- Customer = Customer,
- Analyze = true
- };
-
- try
- {
- konduto.Analyze(order);
- Assert.IsTrue(order.Recommendation != KondutoRecommendation.none);
- }
- catch (KondutoException ex)
- {
- Assert.Fail("Konduto exception shouldn't happen here.");
- }
-
- try
- {
- konduto.UpdateOrderStatus(id, KondutoOrderStatus.fraud, "Manual Review");
- }
- catch (KondutoException ex)
- {
- Assert.Fail("Konduto exception shouldn't happen here.");
- }
-
- try
- {
- konduto.UpdateOrderStatus(id, KondutoOrderStatus.not_authorized, "Manual Review");
- }
- catch (KondutoException ex)
- {
- Assert.Fail("Konduto exception shouldn't happen here.");
- }
- catch (Exception e)
- {
- Assert.Fail("Exception: " + e.ToString());
- }
-
- try
- {
- KondutoOrder updatedOrder = konduto.GetOrder(id);
- }
- catch (KondutoException ex)
- {
- Assert.Fail("Konduto exception shouldn't happen here.");
- }
- }
-
- [TestMethod]
- public void SendOrderToKondutoButDoNotAnalyzeTest()
- {
- var fakeResponseHandler = new FakeResponseHandler();
- var message = new HttpResponseMessage(HttpStatusCode.OK);
- message.Content = new StringContent(NOT_ANALYZE_ORDER_RESPONSE.ToString());
-
- fakeResponseHandler.AddFakeResponse(konduto.KondutoPostOrderUrl(), message);
- konduto.__MessageHandler = fakeResponseHandler;
-
- KondutoOrder orderToSend = KondutoOrderFactory.basicOrder();
- orderToSend.Analyze = false;
-
- Assert.IsFalse(orderToSend.Analyze, "order analyze should be false");
-
- try
- {
- orderToSend = konduto.Analyze(orderToSend); // do analyze
- }
- catch (KondutoInvalidEntityException e)
- {
- Assert.Fail("order should be valid");
- }
- catch (KondutoHTTPException e)
- {
- Assert.Fail("server should respond with status 200");
- }
- catch (KondutoUnexpectedAPIResponseException e)
- {
- Assert.Fail("server should respond with status 200");
- }
-
- Assert.IsTrue(orderToSend.Score == null);
- Assert.IsTrue(orderToSend.Recommendation == KondutoRecommendation.none);
-
- }
-
- [TestMethod]
- public void AnalyzeInvalidOrderTest()
- {
- var fakeResponseHandler = new FakeResponseHandler();
- var message = new HttpResponseMessage(HttpStatusCode.OK);
- message.Content = new StringContent(ORDER_FROM_FILE.ToJson());
-
- fakeResponseHandler.AddFakeResponse(konduto.KondutoPostOrderUrl(), message);
- konduto.__MessageHandler = fakeResponseHandler;
-
- KondutoOrder orderToSend = new KondutoOrder();
-
- try
- {
- orderToSend = konduto.Analyze(orderToSend); // do analyze
- Assert.Fail("KondutoInvalidEntityException should have been thrown");
- }
- catch (KondutoInvalidEntityException e)
- {
- //ok
- }
- catch (KondutoHTTPException e)
- {
- Assert.Fail("Expected KondutoInvalidEntityException, but got KondutoHTTPException");
- }
- catch (KondutoUnexpectedAPIResponseException e)
- {
- Assert.Fail("Expected KondutoInvalidEntityException, but got KondutoHTTPException");
- }
- }
-
- [TestMethod]
- public void AnalyzeHTTPErrorTest()
- {
- foreach (int code in HTTP_STATUSES)
- {
- try
- {
- var fakeResponseHandler = new FakeResponseHandler();
-
- var message = new HttpResponseMessage((HttpStatusCode)code);
- message.Content = new StringContent(ORDER_FROM_FILE.ToJson());
-
- fakeResponseHandler.AddFakeResponse(konduto.KondutoPostOrderUrl(), message);
- konduto.__MessageHandler = fakeResponseHandler;
-
- konduto.Analyze(KondutoOrderFactory.basicOrder());
- Assert.Fail("Exception expected");
- }
- catch (KondutoHTTPException e)
- {
- //Ok
- }
- catch (Exception e)
- {
- Assert.Fail("KondutoHTTPException was expected");
- }
- }
- }
-
- [TestMethod]
- public void UpdateSuccessfullyTest()
- {
- var fakeResponseHandler = new FakeResponseHandler();
- var message = new HttpResponseMessage(HttpStatusCode.OK);
- message.Content = new StringContent("{\"old_status\":\"review\",\"new_status\":\"approved\"}");
-
- fakeResponseHandler.AddFakeResponse(konduto.KondutoPutOrderUrl(ORDER_ID), message);
- konduto.__MessageHandler = fakeResponseHandler;
-
- try
- {
- konduto.UpdateOrderStatus(ORDER_ID, KondutoOrderStatus.approved, "no comments");
- }
- catch (KondutoHTTPException e)
- {
- Assert.Fail("order update should have succeeded");
- }
- catch (KondutoUnexpectedAPIResponseException e)
- {
- Assert.Fail("order update should have succeeded");
- }
- }
-
- [TestMethod]
- public void UpdateHTTPErrorTest()
- {
- foreach (int code in HTTP_STATUSES)
- {
- try
- {
- var fakeResponseHandler = new FakeResponseHandler();
-
- var message = new HttpResponseMessage((HttpStatusCode)code);
- message.Content = new StringContent("{}");
-
- fakeResponseHandler.AddFakeResponse(konduto.KondutoPutOrderUrl(ORDER_ID), message);
- konduto.__MessageHandler = fakeResponseHandler;
-
- konduto.Analyze(KondutoOrderFactory.basicOrder());
- Assert.Fail("Exception expected");
- }
- catch (KondutoHTTPException e)
- {
- //Ok
- }
- catch (Exception e)
- {
- Assert.Fail("KondutoHTTPException was expected");
- }
- }
- }
-
- [TestMethod, ExpectedException(typeof(ArgumentException))]
- public void InvalidStatusWhenUpdatingTest()
- {
- List forbiddenStatus =
- new List()
- {
- KondutoOrderStatus.not_analyzed,
- KondutoOrderStatus.pending
- };
-
- foreach (KondutoOrderStatus status in forbiddenStatus)
- {
- try
- {
- konduto.UpdateOrderStatus(ORDER_FROM_FILE.Id, status, "");
- Assert.Fail("expected KondutoInvalidOrderStatus exception");
- }
- catch (KondutoHTTPException e)
- {
- Assert.Fail("expected KondutoInvalidOrderStatus exception");
- }
- catch (KondutoUnexpectedAPIResponseException e)
- {
- Assert.Fail("expected KondutoInvalidOrderStatus exception");
- }
- }
- }
-
- [TestMethod, ExpectedException(typeof(NullReferenceException))]
- public void NullCommentsWhenUpdatingTest()
- {
- try
- {
- konduto.UpdateOrderStatus(ORDER_FROM_FILE.Id, KondutoOrderStatus.approved, null);
- }
- catch (KondutoHTTPException e)
- {
- Assert.Fail("expected NullPointerException");
- }
- catch (KondutoUnexpectedAPIResponseException e)
- {
- Assert.Fail("expected NullPointerException");
- }
- }
-
- [TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
- public void InvalidApiKeyTest()
- {
- konduto.SetApiKey("invalid key");
- }
-
- private class FakeResponseHandler : DelegatingHandler
- {
- private readonly Dictionary _FakeResponses = new Dictionary();
-
- public void AddFakeResponse(Uri uri, HttpResponseMessage responseMessage)
- {
- _FakeResponses.Add(uri, responseMessage);
- }
-
- protected async override Task SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
- {
- var v = request.Headers.Authorization.Parameter;
-
- Assert.IsTrue(AUTH_HEADER == request.Headers.Authorization.Parameter, "Failing authorizing request.");
-
- if (_FakeResponses.ContainsKey(request.RequestUri))
- {
- return _FakeResponses[request.RequestUri];
- }
- else
- {
- return new HttpResponseMessage(HttpStatusCode.NotFound)
- {
- RequestMessage = request
- };
- }
- }
- }
-
- }
-}
diff --git a/KdtTests/Models/KondutoAddressTest.cs b/KdtTests/Models/KondutoAddressTest.cs
deleted file mode 100644
index 40ec71b..0000000
--- a/KdtTests/Models/KondutoAddressTest.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-using KdtSdk.Exceptions;
-using KdtSdk.Models;
-using KdtSdk.Utils;
-using KdtTests.Factories;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
-
-namespace KdtTests.Models
-{
- [TestClass]
- public class KondutoAddressTest
- {
- [TestMethod]
- public void SerializeTest()
- {
- String expectedJSON = KondutoUtils.LoadJson(Properties.Resources.address).ToJson();
- String actualJSON = null;
- KondutoAddress address = KondutoAddressFactory.Create();
-
- try
- {
- actualJSON = address.ToJson();
- }
- catch (KondutoInvalidEntityException e)
- {
- Assert.Fail("address should be valid");
- }
-
- Assert.AreEqual(expectedJSON, actualJSON, "address serialization failed");
- KondutoAddress addressFromJSON = KondutoModel.FromJson(expectedJSON);
- Assert.AreEqual(address, addressFromJSON, "address deserialization failed");
- }
- }
-}
diff --git a/KdtTests/Models/KondutoBoletoPaymentTest.cs b/KdtTests/Models/KondutoBoletoPaymentTest.cs
deleted file mode 100644
index 64c1c50..0000000
--- a/KdtTests/Models/KondutoBoletoPaymentTest.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-using KdtSdk.Exceptions;
-using KdtSdk.Models;
-using KdtSdk.Utils;
-using KdtTests.Factories;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
-
-namespace KdtTests.Models
-{
- public class KondutoBoletoPaymentTest
- {
- [TestMethod]
- public void SerializeTest()
- {
- String expectedJSON = KondutoUtils.GetFirstJArrayElement(Properties.Resources.payments);
- String actualJSON = null;
- KondutoCreditCardPayment payment = KondutoPaymentFactory.CreateCreditCardPayment();
-
- try
- {
- actualJSON = payment.ToJson();
- }
- catch (KondutoInvalidEntityException e)
- {
- Assert.Fail("address should be valid");
- }
-
- Assert.AreEqual(expectedJSON, actualJSON, "address serialization failed");
-
- KondutoCreditCardPayment paymentFromJSON = KondutoModel.FromJson(expectedJSON);
- Assert.AreEqual(payment, paymentFromJSON, "address deserialization failed");
- }
- }
-}
diff --git a/KdtTests/Models/KondutoCustomerTest.cs b/KdtTests/Models/KondutoCustomerTest.cs
deleted file mode 100644
index bc6f802..0000000
--- a/KdtTests/Models/KondutoCustomerTest.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-using KdtSdk.Exceptions;
-using KdtSdk.Models;
-using KdtSdk.Utils;
-using KdtTests.Factories;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
-using System.Diagnostics;
-
-namespace KdtTests.Models
-{
- [TestClass]
- public class KondutoCustomerTest
- {
- [TestMethod]
- public void SerializationTest()
- {
- KondutoCustomer customer = KondutoCustomerFactory.CompleteCustomer();
- String customerJSON = KondutoUtils.LoadJson(Properties.Resources.customer).ToJson();
-
- try
- {
- var v = customer.ToJson();
- Assert.AreEqual(customerJSON, customer.ToJson(), "serialization failed");
- }
- catch (KondutoInvalidEntityException e) {
- Debug.WriteLine(e.Message);
- }
-
- KondutoCustomer deserializedCustomer = KondutoModel.FromJson(customerJSON);
- Assert.AreEqual(customer, deserializedCustomer, "deserialization failed");
- }
- }
-}
\ No newline at end of file
diff --git a/KdtTests/Models/KondutoDeviceTest.cs b/KdtTests/Models/KondutoDeviceTest.cs
deleted file mode 100644
index beff4f9..0000000
--- a/KdtTests/Models/KondutoDeviceTest.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-using KdtSdk.Exceptions;
-using KdtSdk.Models;
-using KdtSdk.Utils;
-using KdtTests.Factories;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
-
-namespace KdtTests.Models
-{
- [TestClass]
- public class KondutoDeviceTest
- {
- [TestMethod]
- public void SerializeTest()
- {
- KondutoDevice device = KondutoDeviceFactory.Create();
- String deviceJSON = KondutoUtils.LoadJson(Properties.Resources.device).ToJson();
-
- try
- {
- Assert.AreEqual(deviceJSON, device.ToJson(), "serialization failed");
- }
- catch (KondutoInvalidEntityException e)
- {
- Assert.Fail("device should be valid");
- }
-
- Assert.AreEqual(KondutoModel.FromJson(deviceJSON), device, "deserialization failed");
- }
- }
-}
diff --git a/KdtTests/Models/KondutoItemTest.cs b/KdtTests/Models/KondutoItemTest.cs
deleted file mode 100644
index cb3dd8d..0000000
--- a/KdtTests/Models/KondutoItemTest.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using System;
-using KdtSdk.Exceptions;
-using KdtSdk.Models;
-using KdtSdk.Utils;
-using KdtTests.Factories;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace KdtTests.Models
-{
- [TestClass]
- public class KondutoItemTest
- {
- KondutoItem greenTShirt = KondutoItemFactory.CreateGreenTShirt();
- String greenTShirtJSON = KondutoUtils.GetFirstJArrayElement(Properties.Resources.shopping_cart);
-
- [TestMethod]
- public void SerializationTest()
- {
- try
- {
- var v = greenTShirt.ToJson();
- Assert.AreEqual(greenTShirtJSON, greenTShirt.ToJson(), "serialization failed");
- }
- catch (KondutoInvalidEntityException e)
- {
- Assert.Fail("Green T-Shirt should be valid");
- }
- }
-
- [TestMethod]
- public void Deserializationtest()
- {
- Assert.IsTrue(greenTShirt.Equals(KondutoModel.FromJson(greenTShirtJSON)), "deserialization failed");
- }
- }
-}
diff --git a/KdtTests/Models/KondutoNavigationInfoTest.cs b/KdtTests/Models/KondutoNavigationInfoTest.cs
deleted file mode 100644
index 38035ef..0000000
--- a/KdtTests/Models/KondutoNavigationInfoTest.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-using KdtSdk.Exceptions;
-using KdtSdk.Models;
-using KdtSdk.Utils;
-using KdtTests.Factories;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
-
-namespace KdtTests.Models
-{
- [TestClass]
- public class KondutoNavigationInfoTest
- {
- [TestMethod]
- public void SerializationTest()
- {
- KondutoNavigationInfo navigationInfo = KondutoNavigationInfoFactory.Create();
-
- String navigationInfoJSON = KondutoUtils.LoadJson(Properties.Resources.navigation).ToJson();
-
- try
- {
- var c = navigationInfo.ToJson();
- Assert.AreEqual(navigationInfoJSON ,navigationInfo.ToJson(), "serialization failed");
- }
- catch (KondutoInvalidEntityException e)
- {
- Assert.Fail("navigation info should be valid");
- }
-
- KondutoNavigationInfo navigationInfoDeserialized = KondutoModel.FromJson(navigationInfoJSON);
- Assert.AreEqual(navigationInfoDeserialized, navigationInfo, "deserialization failed");
- }
- }
-}
diff --git a/KdtTests/Models/KondutoOrderTest.cs b/KdtTests/Models/KondutoOrderTest.cs
deleted file mode 100644
index 0800695..0000000
--- a/KdtTests/Models/KondutoOrderTest.cs
+++ /dev/null
@@ -1,79 +0,0 @@
-using KdtSdk.Exceptions;
-using KdtSdk.Models;
-using KdtSdk.Utils;
-using KdtTests.Factories;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
-
-namespace KdtTests.Models
-{
- [TestClass]
- public class KondutoOrderTest
- {
- [TestMethod]
- public void IsValidTest()
- {
- KondutoOrder order = new KondutoOrder();
- Assert.IsFalse(order.IsValid(), "order should be invalid without id");
-
- order.Id = "order1";
- Assert.IsFalse(order.IsValid(), "order should be invalid without total amount");
-
- order.TotalAmount = 120.1;
- Assert.IsFalse(order.IsValid(), "order should be invalid without customer");
-
- order.Customer = KondutoCustomerFactory.BasicCustomer();
- Assert.IsTrue(order.IsValid(), "order should be valid");
- Assert.IsTrue(order.GetError() == null, "order errors should be empty");
- }
-
- [TestMethod]
- public void SerializationTest()
- {
- KondutoOrder order = KondutoOrderFactory.completeOrder();
- String orderJSON = KondutoUtils.LoadJson(Properties.Resources.order).ToJson();
-
- try
- {
- Assert.AreEqual(orderJSON, order.ToJson(), "serialization failed");
- }
- catch (KondutoInvalidEntityException e)
- {
- Assert.Fail("order should be valid");
- }
-
- KondutoOrder deserializedOrder = KondutoModel.FromJson(orderJSON);
- Assert.IsTrue(order.Equals(deserializedOrder), "deserialization failed");
-
- }
-
- [TestMethod]
- public void SerializationTestWithShoppingAndFlight()
- {
- KondutoOrder order = KondutoOrderFactory.completeOrder();
- order.Travel = KondutoFlightFactory.CreateFlight();
-
- try
- {
- order.ToJson();
- Assert.Fail("order should be invalid");
- }
- catch (KondutoInvalidEntityException e)
- {
- //ok
- }
-
- order = KondutoOrderFactory.completeOrder();
- order.Travel = KondutoFlightFactory.CreateFlight();
- order.ShoppingCart = null;
- //ok
- }
-
- [TestMethod, ExpectedException(typeof(KondutoInvalidEntityException))]
- public void invalidOrderSerializationThrowsExceptionTest()
- {
- KondutoOrder order = new KondutoOrder();
- order.ToJson(); // triggers invalid customer exception
- }
- }
-}
diff --git a/KdtTests/Models/KondutoPassengerTest.cs b/KdtTests/Models/KondutoPassengerTest.cs
deleted file mode 100644
index 8e689e2..0000000
--- a/KdtTests/Models/KondutoPassengerTest.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-using KdtSdk.Exceptions;
-using KdtSdk.Models;
-using KdtSdk.Utils;
-using KdtTests.Factories;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
-using System.Diagnostics;
-
-namespace KdtTests.Models
-{
- [TestClass]
- public class KondutoPassengerTest
- {
- [TestMethod]
- public void SerializationTest()
- {
- String expectedJSON = KondutoUtils.LoadJson(Properties.Resources.passenger).ToJson();
- String actualJSON = null;
- KondutoPassenger passenger = KondutoPassengerFactory.CompletePassenger();
-
- try
- {
- actualJSON = passenger.ToJson();
- }
- catch (KondutoInvalidEntityException e)
- {
- Assert.Fail("passenger should be valid");
- }
-
- Assert.AreEqual(expectedJSON, actualJSON, "passenger serialization failed");
- KondutoPassenger passengerFromJson = KondutoModel.FromJson(expectedJSON);
- Assert.AreEqual(passenger, passengerFromJson, "passenger deserialization failed");
- }
- }
-}
\ No newline at end of file
diff --git a/KdtTests/Models/KondutoPaymentTest.cs b/KdtTests/Models/KondutoPaymentTest.cs
deleted file mode 100644
index c3854d8..0000000
--- a/KdtTests/Models/KondutoPaymentTest.cs
+++ /dev/null
@@ -1,128 +0,0 @@
-using KdtSdk.Exceptions;
-using KdtSdk.Models;
-using KdtSdk.Utils;
-using KdtTests.Factories;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Newtonsoft.Json.Linq;
-using System;
-
-namespace KdtTests.Models
-{
- [TestClass]
- public class KondutoPaymentTest
- {
- [TestMethod]
- public void CreditSerializeTest()
- {
- String expectedJSON = KondutoUtils.GetFirstJArrayElement(Properties.Resources.payments);
- String actualJSON = null;
- KondutoCreditCardPayment payment = KondutoPaymentFactory.CreateCreditCardPayment();
-
- try
- {
- actualJSON = payment.ToJson();
- }
- catch (KondutoInvalidEntityException e)
- {
- Assert.Fail("address should be valid");
- }
-
- Assert.AreEqual(expectedJSON, actualJSON, "address serialization failed");
-
- KondutoCreditCardPayment paymentFromJSON = KondutoModel.FromJson(expectedJSON);
- Assert.AreEqual(payment, paymentFromJSON, "address deserialization failed");
- }
-
- [TestMethod]
- public void BoletoSerializeTest()
- {
- JArray a = JArray.Parse(Properties.Resources.payments);
- String expectedJSON = a.Last.ToString();
- String actualJSON = null;
- KondutoBoletoPayment payment = KondutoPaymentFactory.CreateBoletoPayment();
-
- try
- {
- actualJSON = payment.ToJson();
- }
- catch (KondutoInvalidEntityException e)
- {
- Assert.Fail("payment should be valid");
- }
-
- Assert.AreEqual(expectedJSON, actualJSON, "address serialization failed");
-
- KondutoBoletoPayment paymentFromJSON = KondutoModel.FromJson(expectedJSON);
- Assert.AreEqual(payment, paymentFromJSON, "payment deserialization failed");
- }
-
- [TestMethod]
- public void DebitSerializeTest()
- {
- JArray a = JArray.Parse(Properties.Resources.payments);
- String expectedJSON = a[1].ToString();
- String actualJSON = null;
- KondutoDebitPayment payment = KondutoPaymentFactory.CreateDebitPayment();
-
- try
- {
- actualJSON = payment.ToJson();
- }
- catch (KondutoInvalidEntityException e)
- {
- Assert.Fail("payment should be valid");
- }
-
- Assert.AreEqual(expectedJSON, actualJSON, "address serialization failed");
-
- KondutoDebitPayment paymentFromJSON = KondutoModel.FromJson(expectedJSON);
- Assert.AreEqual(payment, paymentFromJSON, "payment deserialization failed");
- }
-
- [TestMethod]
- public void TransferSerializeTest()
- {
- JArray a = JArray.Parse(Properties.Resources.payments);
- String expectedJSON = a[3].ToString();
- String actualJSON = null;
- KondutoTransferPayment payment = KondutoPaymentFactory.CreateTransferPayment();
-
- try
- {
- actualJSON = payment.ToJson();
- }
- catch (KondutoInvalidEntityException e)
- {
- Assert.Fail("payment should be valid");
- }
-
- Assert.AreEqual(expectedJSON, actualJSON, "address serialization failed");
-
- KondutoTransferPayment paymentFromJSON = KondutoModel.FromJson(expectedJSON);
- Assert.AreEqual(payment, paymentFromJSON, "payment deserialization failed");
- }
-
- [TestMethod]
- public void VoucherSerializeTest()
- {
- JArray a = JArray.Parse(Properties.Resources.payments);
- String expectedJSON = a[2].ToString();
- String actualJSON = null;
- KondutoVoucherPayment payment = KondutoPaymentFactory.CreateVoucherPayment();
-
- try
- {
- actualJSON = payment.ToJson();
- }
- catch (KondutoInvalidEntityException e)
- {
- Assert.Fail("payment should be valid");
- }
-
- Assert.AreEqual(expectedJSON, actualJSON, "address serialization failed");
-
- KondutoVoucherPayment paymentFromJSON = KondutoModel.FromJson(expectedJSON);
- Assert.AreEqual(payment, paymentFromJSON, "payment deserialization failed");
- }
- }
-}
\ No newline at end of file
diff --git a/KdtTests/Models/KondutoSellerTest.cs b/KdtTests/Models/KondutoSellerTest.cs
deleted file mode 100644
index 8c8b883..0000000
--- a/KdtTests/Models/KondutoSellerTest.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-using KdtSdk.Exceptions;
-using KdtSdk.Models;
-using KdtSdk.Utils;
-using KdtTests.Factories;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace KdtTests.Models
-{
- [TestClass]
- public class KondutoSellerTest
- {
- [TestMethod]
- public void SerializationTest()
- {
- String expectedJSON = KondutoUtils.LoadJson(Properties.Resources.seller).ToJson();
- String actualJSON = null;
- KondutoSeller seller = KondutoSellerFactory.Create();
-
- try
- {
- actualJSON = seller.ToJson();
- }
- catch (KondutoInvalidEntityException e)
- {
- Assert.Fail("seller should be valid");
- }
-
- Assert.AreEqual(expectedJSON, actualJSON, "seller serialization failed");
- KondutoSeller sellerFromJson = KondutoModel.FromJson(expectedJSON);
- Assert.AreEqual(seller, sellerFromJson, "passenger deserialization failed");
- }
- }
-}
diff --git a/KdtTests/Models/KondutoTravelTest.cs b/KdtTests/Models/KondutoTravelTest.cs
deleted file mode 100644
index 709f7a8..0000000
--- a/KdtTests/Models/KondutoTravelTest.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-using KdtSdk.Exceptions;
-using KdtSdk.Models;
-using KdtSdk.Utils;
-using KdtTests.Factories;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
-
-namespace KdtTests.Models
-{
- [TestClass]
- public class KondutoTravelTest
- {
- [TestMethod]
- public void SerializeTest()
- {
- String expectedJSON = KondutoUtils.LoadJson(Properties.Resources.flight).ToJson();
- String actualJSON = null;
- KondutoTravel flight = KondutoFlightFactory.CreateFlight();
-
- try
- {
- actualJSON = flight.ToJson();
- }
- catch (KondutoInvalidEntityException e)
- {
- Assert.Fail("flight should be valid");
- }
-
- Assert.AreEqual(expectedJSON, actualJSON, "flight serialization failed");
- KondutoTravel flightFromJSON = KondutoModel.FromJson(expectedJSON);
- Assert.AreEqual(flight, flightFromJSON, "flight deserialization failed");
- }
- }
-}
diff --git a/KdtTests/Properties/AssemblyInfo.cs b/KdtTests/Properties/AssemblyInfo.cs
deleted file mode 100644
index 460e3cb..0000000
--- a/KdtTests/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("KdtTests")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("KdtTests")]
-[assembly: AssemblyCopyright("Copyright © 2015")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("54f40858-d37b-4a5d-a7ef-a499f397279a")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/KdtTests/Properties/Resources.Designer.cs b/KdtTests/Properties/Resources.Designer.cs
deleted file mode 100644
index 02f9974..0000000
--- a/KdtTests/Properties/Resources.Designer.cs
+++ /dev/null
@@ -1,346 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// This code was generated by a tool.
-// Runtime Version:4.0.30319.34014
-//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-//
-//------------------------------------------------------------------------------
-
-namespace KdtTests.Properties {
- using System;
-
-
- ///
- /// A strongly-typed resource class, for looking up localized strings, etc.
- ///
- // This class was auto-generated by the StronglyTypedResourceBuilder
- // class via a tool like ResGen or Visual Studio.
- // To add or remove a member, edit your .ResX file then rerun ResGen
- // with the /str option, or rebuild your VS project.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- internal class Resources {
-
- private static global::System.Resources.ResourceManager resourceMan;
-
- private static global::System.Globalization.CultureInfo resourceCulture;
-
- [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
- internal Resources() {
- }
-
- ///
- /// Returns the cached ResourceManager instance used by this class.
- ///
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Resources.ResourceManager ResourceManager {
- get {
- if (object.ReferenceEquals(resourceMan, null)) {
- global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("KdtTests.Properties.Resources", typeof(Resources).Assembly);
- resourceMan = temp;
- }
- return resourceMan;
- }
- }
-
- ///
- /// Overrides the current thread's CurrentUICulture property for all
- /// resource lookups using this strongly typed resource class.
- ///
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Globalization.CultureInfo Culture {
- get {
- return resourceCulture;
- }
- set {
- resourceCulture = value;
- }
- }
-
- ///
- /// Looks up a localized string similar to {
- /// "name":"Konduto",
- /// "address1":"R. Teodoro Sampaio, 2393",
- /// "address2":"CJ. 111",
- /// "zip":"05406-200",
- /// "city":"Sao Paulo",
- /// "state":"SP",
- /// "country":"BR"
- ///}.
- ///
- internal static string address {
- get {
- return ResourceManager.GetString("address", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to {
- /// "id":"1",
- /// "name":"Jose da Silva",
- /// "email":"jose.silva@gmail.com",
- /// "tax_id":"01234567890",
- /// "phone1":"11987654321",
- /// "phone2":"1133333333",
- /// "vip":false,
- /// "new":false,
- /// "created_at":"2014-12-21"
- ///}.
- ///
- internal static string customer {
- get {
- return ResourceManager.GetString("customer", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to {
- /// "user_id": "405961fab293600daeed93ae561",
- /// "fingerprint": "e4f2c690951038a8f77aa583847",
- /// "platform": "MacIntel",
- /// "browser": "Chrome",
- /// "language": "en_US",
- /// "timezone": "GMT -1",
- /// "cookie": true,
- /// "javascript": true,
- /// "flash": true,
- /// "ip": "170.149.100.10"
- ///}.
- ///
- internal static string device {
- get {
- return ResourceManager.GetString("device", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to {
- /// "type":"flight",
- /// "departure":{
- /// "origin_airport":"GRU",
- /// "destination_airport":"SFO",
- /// "date":"2018-12-25T18:00Z",
- /// "number_of_connections":1,
- /// "class":"economy",
- /// "fare_basis":"Y"
- /// },
- /// "return":{
- /// "origin_airport":"SFO",
- /// "destination_airport":"GRU",
- /// "date":"2018-12-30T18:00Z",
- /// "number_of_connections":1,
- /// "class":"business"
- /// },
- /// "passengers":[
- /// {
- /// "name":"Julia da Silva",
- /// "document":"12345678909",
- /// "document_type":"id",
- /// "dob":"1970-01-01",
- /// "nationa [rest of string was truncated]";.
- ///
- internal static string flight {
- get {
- return ResourceManager.GetString("flight", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to {
- /// "city":"Sao Paulo",
- /// "state":"SP",
- /// "country":"BR"
- ///}.
- ///
- internal static string geolocation {
- get {
- return ResourceManager.GetString("geolocation", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to {
- /// "status": "ok",
- /// "order": {
- /// "id": "1406910391037",
- /// "visitor": "f10e2821bbbea527ea02200352313bc059445190",
- /// "timestamp": 1389047680,
- /// "score": 0.75,
- /// "recommendation": "review",
- /// "status": "declined",
- /// "ip": "170.149.100.10",
- /// "total_amount":100.00,
- /// "tax_amount":3.45,
- /// "shipping_amount":20.00,
- /// "installments":2,
- /// "currency":"USD",
- /// "device": {
- /// "user_id": "405961fab293600daeed93ae561",
- /// "fingerprint": "e4f2c690951038a8f77aa583847",
- /// "platform": "MacIntel",
- /// [rest of string was truncated]";.
- ///
- internal static string konduto_order {
- get {
- return ResourceManager.GetString("konduto_order", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to {
- /// "status":"ok",
- /// "order":{
- /// "id":"1422044664262",
- /// "visitor":"da39a3ee5e6b4b0d3255bfef95601890afd80709",
- /// "score":-1.0,
- /// "recommendation":"NONE",
- /// "ip":"170.149.100.10"
- /// }
- ///}.
- ///
- internal static string konduto_order_not_analyzed {
- get {
- return ResourceManager.GetString("konduto_order_not_analyzed", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to {
- /// "session_time": 12,
- /// "referrer": "http://www.google.com?q=buy+shirt",
- /// "time_site_1d": 26,
- /// "new_accounts_1d": 2,
- /// "password_resets_1d": 0,
- /// "sales_declined_1d": 1,
- /// "sessions_1d": 4,
- /// "time_site_7d": 58,
- /// "time_per_page_7d": 7,
- /// "new_accounts_7d": 9,
- /// "password_resets_7d": 3,
- /// "checkout_count_7d": 4,
- /// "sales_declined_7d": 5,
- /// "sessions_7d": 12,
- /// "time_since_last_sale": 4
- ///}.
- ///
- internal static string navigation {
- get {
- return ResourceManager.GetString("navigation", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to {
- /// "id":"1",
- /// "visitor":"a9031kdlas",
- /// "timestamp":123123123123,
- /// "total_amount":120.5,
- /// "shipping_amount":5.0,
- /// "tax_amount":3.0,
- /// "currency":"USD",
- /// "installments":1,
- /// "ip":"192.168.0.1",
- /// "customer":{
- /// "id":"1",
- /// "name":"Jose da Silva",
- /// "email":"jose.silva@gmail.com",
- /// "tax_id":"01234567890",
- /// "phone1":"11987654321",
- /// "phone2":"1133333333",
- /// "vip":false,
- /// "new":false
- /// },
- /// "recommendation":"approve",
- /// "geolocation":{
- /// "ci [rest of string was truncated]";.
- ///
- internal static string order {
- get {
- return ResourceManager.GetString("order", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to {
- /// "name": "Carlos Siqueira",
- /// "document": "XYZ1234",
- /// "document_type": "passport",
- /// "dob": "1970-12-01",
- /// "nationality": "US",
- /// "frequent_passenger": false,
- /// "special_needs": true,
- /// "loyalty": {
- /// "program": "multiplus",
- /// "category": "silver"
- /// }
- ///}.
- ///
- internal static string passenger {
- get {
- return ResourceManager.GetString("passenger", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to [
- /// {
- /// "bin":"1234",
- /// "last4":"1234",
- /// "expiration_date":"010214",
- /// "status":"approved",
- /// "type":"credit"
- /// },
- /// {
- /// "expiration_date":"010214",
- /// "type": "boleto"
- /// }
- ///].
- ///
- internal static string payments {
- get {
- return ResourceManager.GetString("payments", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to https://github.com/konduto/dotnet-sdk.git.
- ///
- internal static string seller {
- get {
- return ResourceManager.GetString("seller", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to [
- /// {
- /// "sku": "9919023",
- /// "category": 201,
- /// "name": "Green T-Shirt",
- /// "description": "Male Green T-Shirt V Neck",
- /// "product_code": "123456789999",
- /// "unit_cost": 1999.99,
- /// "quantity": 1.0,
- /// "created_at": "2014-12-21"
- /// },
- /// {
- /// "sku": "0017273",
- /// "category": 202,
- /// "name": "Yellow Socks",
- /// "description": "Pair of Yellow Socks",
- /// "unit_cost": 29.90,
- /// "quantity": 2.0,
- /// "discount": 5.00
- /// }
- ///].
- ///
- internal static string shopping_cart {
- get {
- return ResourceManager.GetString("shopping_cart", resourceCulture);
- }
- }
- }
-}
diff --git a/KdtTests/Properties/Resources.resx b/KdtTests/Properties/Resources.resx
deleted file mode 100644
index c8eea9f..0000000
--- a/KdtTests/Properties/Resources.resx
+++ /dev/null
@@ -1,160 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- text/microsoft-resx
-
-
- 2.0
-
-
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
-
- ..\Resources\address.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8
-
-
- ..\Resources\customer.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8
-
-
- ..\Resources\device.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252
-
-
- ..\Resources\flight.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252
-
-
- ..\Resources\geolocation.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8
-
-
- ..\Resources\konduto_order.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252
-
-
- ..\Resources\order_not_analyzed.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252
-
-
- ..\Resources\navigation.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252
-
-
- ..\Resources\order.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8
-
-
- ..\Resources\passenger.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252
-
-
- ..\Resources\payments.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252
-
-
- ..\Resources\seller.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252
-
-
- ..\Resources\shopping_cart.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252
-
-
\ No newline at end of file
diff --git a/KdtTests/app.config b/KdtTests/app.config
deleted file mode 100644
index 19b1cb9..0000000
--- a/KdtTests/app.config
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/KdtTests/packages.config b/KdtTests/packages.config
deleted file mode 100644
index bf72313..0000000
--- a/KdtTests/packages.config
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/KdtSdk.sln b/src/KdtSdk.sln
new file mode 100644
index 0000000..e080402
--- /dev/null
+++ b/src/KdtSdk.sln
@@ -0,0 +1,37 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.28010.2050
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{CAC47624-8884-4855-936B-A0B5E8E7E4CC}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KdtSdk", "KdtSdk\KdtSdk.csproj", "{73A6BCA3-9019-498C-BE89-DB8233DDC79B}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KdtTests", "KdtTests\KdtTests.csproj", "{424BD126-E187-4A6D-808E-B332B0E68026}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {73A6BCA3-9019-498C-BE89-DB8233DDC79B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {73A6BCA3-9019-498C-BE89-DB8233DDC79B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {73A6BCA3-9019-498C-BE89-DB8233DDC79B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {73A6BCA3-9019-498C-BE89-DB8233DDC79B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {424BD126-E187-4A6D-808E-B332B0E68026}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {424BD126-E187-4A6D-808E-B332B0E68026}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {424BD126-E187-4A6D-808E-B332B0E68026}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {424BD126-E187-4A6D-808E-B332B0E68026}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(NestedProjects) = preSolution
+ {73A6BCA3-9019-498C-BE89-DB8233DDC79B} = {CAC47624-8884-4855-936B-A0B5E8E7E4CC}
+ {424BD126-E187-4A6D-808E-B332B0E68026} = {CAC47624-8884-4855-936B-A0B5E8E7E4CC}
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {4BB89A18-F00C-49D9-A09A-94820829B32B}
+ EndGlobalSection
+EndGlobal
diff --git a/KdtSdk/Exceptions/KondutoException.cs b/src/KdtSdk/Exceptions/KondutoException.cs
similarity index 100%
rename from KdtSdk/Exceptions/KondutoException.cs
rename to src/KdtSdk/Exceptions/KondutoException.cs
diff --git a/KdtSdk/Exceptions/KondutoHTTPException.cs b/src/KdtSdk/Exceptions/KondutoHTTPException.cs
similarity index 100%
rename from KdtSdk/Exceptions/KondutoHTTPException.cs
rename to src/KdtSdk/Exceptions/KondutoHTTPException.cs
diff --git a/KdtSdk/Exceptions/KondutoHTTPExceptionFactory.cs b/src/KdtSdk/Exceptions/KondutoHTTPExceptionFactory.cs
similarity index 100%
rename from KdtSdk/Exceptions/KondutoHTTPExceptionFactory.cs
rename to src/KdtSdk/Exceptions/KondutoHTTPExceptionFactory.cs
diff --git a/KdtSdk/Exceptions/KondutoInvalidEntityException.cs b/src/KdtSdk/Exceptions/KondutoInvalidEntityException.cs
similarity index 100%
rename from KdtSdk/Exceptions/KondutoInvalidEntityException.cs
rename to src/KdtSdk/Exceptions/KondutoInvalidEntityException.cs
diff --git a/KdtSdk/Exceptions/KondutoUnexpectedAPIRespondeException.cs b/src/KdtSdk/Exceptions/KondutoUnexpectedAPIRespondeException.cs
similarity index 100%
rename from KdtSdk/Exceptions/KondutoUnexpectedAPIRespondeException.cs
rename to src/KdtSdk/Exceptions/KondutoUnexpectedAPIRespondeException.cs
diff --git a/src/KdtSdk/KdtSdk.csproj b/src/KdtSdk/KdtSdk.csproj
new file mode 100644
index 0000000..7d3b2b1
--- /dev/null
+++ b/src/KdtSdk/KdtSdk.csproj
@@ -0,0 +1,18 @@
+
+
+
+ A sdk to interact with Konduto's api
+ Copyright © 2015
+ KdtSdk
+ 1.1.0
+ Konduto
+ KdtSdk
+ KdtSdk
+ netstandard2.0
+
+
+
+
+
+
+
diff --git a/KdtSdk/Konduto.cs b/src/KdtSdk/Konduto.cs
similarity index 68%
rename from KdtSdk/Konduto.cs
rename to src/KdtSdk/Konduto.cs
index 672068d..5b71ebd 100644
--- a/KdtSdk/Konduto.cs
+++ b/src/KdtSdk/Konduto.cs
@@ -7,7 +7,7 @@
using KdtSdk.Exceptions;
using System.Net.Http.Headers;
using Newtonsoft.Json.Linq;
-using System.Net;
+using System.Threading.Tasks;
namespace KdtSdk
{
@@ -151,27 +151,9 @@ public void SetProxy(String proxyAddress, String proxyUser, String proxyPassword
///
private HttpClient CreateHttpClient()
{
- String base64 = Base64Encode(apiKey);
+ var base64 = Base64Encode(apiKey);
- HttpClient httpClient;
-
- if (!this.useProxy)
- {
- httpClient = __MessageHandler == null ? new HttpClient() : new HttpClient(__MessageHandler);
- }
- else
- {
- var httpClientHandler = new HttpClientHandler
- {
- UseDefaultCredentials = false,
- Proxy = new WebProxy(this.proxyAddress, false, null, new NetworkCredential(this.proxyUsername, this.proxyPassword)),
- UseProxy = true
- };
-
- //httpClient = HttpClientFactory.Create(httpClientHandler);
- httpClient = new HttpClient(httpClientHandler);
- }
-
+ var httpClient = __MessageHandler == null ? new HttpClient() : new HttpClient(__MessageHandler);
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Add("Authorization", "Basic " + base64);
httpClient.DefaultRequestHeaders.Add("X-Requested-With", "Konduto SDK .NET " + VERSION);
@@ -189,35 +171,52 @@ private HttpClient CreateHttpClient()
/// a {@link KondutoOrder} instance
///
///
- public KondutoOrder GetOrder(String orderId)
+ public async Task GetOrderAsync(String orderId)
{
- HttpClient client = CreateHttpClient();
+ var client = CreateHttpClient();
+ requestBody = orderId;
- this.requestBody = orderId;
-
- var response = client.GetAsync(KondutoGetOrderSuffix(orderId)).Result;
+ var response = await client.GetAsync(KondutoGetOrderSuffix(orderId));
if (response.IsSuccessStatusCode)
{
var responseContent = response.Content;
- String responseString = responseContent.ReadAsStringAsync().Result;
- this.responseBody = responseString;
-
- JObject getResponse = JsonConvert.DeserializeObject(responseString);
+ var responseString = await responseContent.ReadAsStringAsync();
+ responseBody = responseString;
+ var getResponse = JsonConvert.DeserializeObject(responseString);
KondutoOrder order = null;
-
JToken jt;
if (getResponse.TryGetValue("order", out jt))
{
order = KondutoModel.FromJson(jt.ToString());
}
-
return order;
}
- else
+ throw KondutoHTTPExceptionFactory.buildException(
+ (int)response.StatusCode,
+ await response.Content.ReadAsStringAsync()
+ );
+ }
+
+ ///
+ /// Queries an order from Konduto's API.
+ /// Syncronous
+ /// @see Konduto API Spec
+ ///
+ /// the order identifier
+ /// a {@link KondutoOrder} instance
+ ///
+ ///
+ public KondutoOrder GetOrder(String orderId)
+ {
+ try
+ {
+ return GetOrderAsync(orderId).Result;
+ }
+ catch (AggregateException ae)
{
- throw KondutoHTTPExceptionFactory.buildException((int)response.StatusCode, response.Content.ReadAsStringAsync().Result);
+ throw ae.InnerException;
}
}
@@ -230,37 +229,55 @@ public KondutoOrder GetOrder(String orderId)
///
///
///
- public KondutoOrder Analyze(KondutoOrder order)
+ public async Task AnalyzeAsync(KondutoOrder order)
{
- HttpClient httpClient = CreateHttpClient();
-
- var response = httpClient.PostAsync(KondutoPostOrderUrl(),
+ var httpClient = CreateHttpClient();
+ var response = await httpClient.PostAsync(KondutoPostOrderUrl(),
new StringContent(order.ToJson(),
Encoding.UTF8,
"application/json"));
- this.requestBody = order.ToJson();
-
- if (response.Result.IsSuccessStatusCode)
+ requestBody = order.ToJson();
+ if (response.IsSuccessStatusCode)
{
- // by calling. Result you are performing a synchronous call
- var responseContent = response.Result.Content;
-
- // by calling. Result you are synchronously reading the result
- String responseString = responseContent.ReadAsStringAsync().Result;
-
- this.responseBody = responseString;
+ var responseContent = response.Content;
+ var responseString = await responseContent.ReadAsStringAsync();
+ responseBody = responseString;
if (order.Analyze)
- order.MergeKondutoOrderResponse(KondutoAPIFullResponse.FromJson(responseString).Order);
-
+ order.MergeKondutoOrderResponse(
+ KondutoAPIFullResponse.FromJson(responseString).Order
+ );
return order;
}
else
{
- var responseContentError = response.Result.Content != null ? response.Result.Content.ReadAsStringAsync().Result : "Error with response";
- throw KondutoHTTPExceptionFactory.buildException((int)response.Result.StatusCode,
- responseContentError);
+ var responseContentError = response.Content != null ?
+ await response.Content.ReadAsStringAsync() :
+ "Error with response";
+ throw KondutoHTTPExceptionFactory.buildException(
+ (int)response.StatusCode, responseContentError);
+ }
+ }
+
+ ///
+ /// Sends an order for Konduto and gets it analyzed
+ /// (i.e with recommendation, score, device, geolocation and navigation info).
+ /// @see Konduto API Spec
+ ///
+ /// a {@link KondutoOrder} instance
+ ///
+ ///
+ ///
+ public KondutoOrder Analyze(KondutoOrder order)
+ {
+ try
+ {
+ return AnalyzeAsync(order).Result;
+ }
+ catch (AggregateException ae)
+ {
+ throw ae.InnerException;
}
}
@@ -281,7 +298,7 @@ private class KondutoAPIFullResponse : KondutoModel
/// some comments (an empty String is accepted, although we recommend setting it to at least a timestamp)
///
///
- public void UpdateOrderStatus(String orderId, KondutoOrderStatus newStatus, String comments)
+ public async Task UpdateOrderStatusAsync(string orderId, KondutoOrderStatus newStatus, string comments)
{
HashSet allowed = new HashSet
{
@@ -293,36 +310,28 @@ public void UpdateOrderStatus(String orderId, KondutoOrderStatus newStatus, Stri
};
if (!allowed.Contains(newStatus)) { throw new ArgumentException("Illegal status: " + newStatus); }
-
if (comments == null) { throw new NullReferenceException("Comments cannot be null."); }
JObject requestBody = new JObject();
requestBody.Add("status", newStatus.ToString().ToLower());
requestBody.Add("comments", comments);
- HttpClient client = CreateHttpClient();
+ var client = CreateHttpClient();
+ var response = await client.PutAsync(KondutoPutOrderUrl(orderId),
+ new StringContent(requestBody.ToString(), Encoding.UTF8, "application/json"));
- var response = client.PutAsync(KondutoPutOrderUrl(orderId),
- new StringContent(
- requestBody.ToString(),
- Encoding.UTF8,
- "application/json"));
-
- if (response.Result.IsSuccessStatusCode)
+ if (response.IsSuccessStatusCode)
{
- JObject responseBody = JsonConvert.DeserializeObject(
- response.Result.Content.ReadAsStringAsync().Result);
+ var responseBody = JsonConvert.DeserializeObject(
+ await response.Content.ReadAsStringAsync());
this.responseBody = responseBody.ToString();
JToken orderUpdateResponse;
-
if (responseBody.TryGetValue("order", out orderUpdateResponse))
{
- JObject updatedOrder = JsonConvert.DeserializeObject(orderUpdateResponse.ToString());
-
+ var updatedOrder = JsonConvert.DeserializeObject(orderUpdateResponse.ToString());
JToken statusResponse;
-
if (!updatedOrder.TryGetValue("old_status", out statusResponse) ||
!updatedOrder.TryGetValue("new_status", out statusResponse))
{
@@ -331,10 +340,33 @@ public void UpdateOrderStatus(String orderId, KondutoOrderStatus newStatus, Stri
}
}
else
- {
- throw KondutoHTTPExceptionFactory.buildException((int)response.Result.StatusCode,
- response.Result.Content.ReadAsStringAsync().Result);
+ {
+ throw KondutoHTTPExceptionFactory.buildException(
+ (int)response.StatusCode,
+ await response.Content.ReadAsStringAsync());
+ }
+ }
+
+ ///
+ /// Updates an order status.
+ /// @see Konduto API Spec
+ ///
+ /// the order to update
+ /// the new status (APPROVED, DECLINED or FRAUD)
+ /// some comments (an empty String is accepted, although we recommend setting it to at least a timestamp)
+ ///
+ ///
+ public void UpdateOrderStatus(string orderId, KondutoOrderStatus newStatus, string comments)
+ {
+ try
+ {
+ UpdateOrderStatusAsync(orderId, newStatus, comments).Wait();
}
+ catch (AggregateException ae)
+ {
+ throw ae.InnerException;
+ }
+
}
///
diff --git a/KdtSdk/Models/KondutoAddress.cs b/src/KdtSdk/Models/KondutoAddress.cs
similarity index 100%
rename from KdtSdk/Models/KondutoAddress.cs
rename to src/KdtSdk/Models/KondutoAddress.cs
diff --git a/KdtSdk/Models/KondutoBoletoPayment.cs b/src/KdtSdk/Models/KondutoBoletoPayment.cs
similarity index 100%
rename from KdtSdk/Models/KondutoBoletoPayment.cs
rename to src/KdtSdk/Models/KondutoBoletoPayment.cs
diff --git a/KdtSdk/Models/KondutoCreditCardPayment.cs b/src/KdtSdk/Models/KondutoCreditCardPayment.cs
similarity index 100%
rename from KdtSdk/Models/KondutoCreditCardPayment.cs
rename to src/KdtSdk/Models/KondutoCreditCardPayment.cs
diff --git a/KdtSdk/Models/KondutoCreditCardPaymentStatus.cs b/src/KdtSdk/Models/KondutoCreditCardPaymentStatus.cs
similarity index 100%
rename from KdtSdk/Models/KondutoCreditCardPaymentStatus.cs
rename to src/KdtSdk/Models/KondutoCreditCardPaymentStatus.cs
diff --git a/KdtSdk/Models/KondutoCustomer.cs b/src/KdtSdk/Models/KondutoCustomer.cs
similarity index 100%
rename from KdtSdk/Models/KondutoCustomer.cs
rename to src/KdtSdk/Models/KondutoCustomer.cs
diff --git a/KdtSdk/Models/KondutoDebitPayment.cs b/src/KdtSdk/Models/KondutoDebitPayment.cs
similarity index 100%
rename from KdtSdk/Models/KondutoDebitPayment.cs
rename to src/KdtSdk/Models/KondutoDebitPayment.cs
diff --git a/KdtSdk/Models/KondutoDevice.cs b/src/KdtSdk/Models/KondutoDevice.cs
similarity index 100%
rename from KdtSdk/Models/KondutoDevice.cs
rename to src/KdtSdk/Models/KondutoDevice.cs
diff --git a/KdtSdk/Models/KondutoGeolocation.cs b/src/KdtSdk/Models/KondutoGeolocation.cs
similarity index 100%
rename from KdtSdk/Models/KondutoGeolocation.cs
rename to src/KdtSdk/Models/KondutoGeolocation.cs
diff --git a/KdtSdk/Models/KondutoItem.cs b/src/KdtSdk/Models/KondutoItem.cs
similarity index 100%
rename from KdtSdk/Models/KondutoItem.cs
rename to src/KdtSdk/Models/KondutoItem.cs
diff --git a/KdtSdk/Models/KondutoLoyaltyProgram.cs b/src/KdtSdk/Models/KondutoLoyaltyProgram.cs
similarity index 100%
rename from KdtSdk/Models/KondutoLoyaltyProgram.cs
rename to src/KdtSdk/Models/KondutoLoyaltyProgram.cs
diff --git a/KdtSdk/Models/KondutoModel.cs b/src/KdtSdk/Models/KondutoModel.cs
similarity index 100%
rename from KdtSdk/Models/KondutoModel.cs
rename to src/KdtSdk/Models/KondutoModel.cs
diff --git a/KdtSdk/Models/KondutoNavigationInfo.cs b/src/KdtSdk/Models/KondutoNavigationInfo.cs
similarity index 100%
rename from KdtSdk/Models/KondutoNavigationInfo.cs
rename to src/KdtSdk/Models/KondutoNavigationInfo.cs
diff --git a/KdtSdk/Models/KondutoOrder.cs b/src/KdtSdk/Models/KondutoOrder.cs
similarity index 100%
rename from KdtSdk/Models/KondutoOrder.cs
rename to src/KdtSdk/Models/KondutoOrder.cs
diff --git a/KdtSdk/Models/KondutoOrderResponse.cs b/src/KdtSdk/Models/KondutoOrderResponse.cs
similarity index 100%
rename from KdtSdk/Models/KondutoOrderResponse.cs
rename to src/KdtSdk/Models/KondutoOrderResponse.cs
diff --git a/KdtSdk/Models/KondutoOrderStatus.cs b/src/KdtSdk/Models/KondutoOrderStatus.cs
similarity index 100%
rename from KdtSdk/Models/KondutoOrderStatus.cs
rename to src/KdtSdk/Models/KondutoOrderStatus.cs
diff --git a/KdtSdk/Models/KondutoPassenger.cs b/src/KdtSdk/Models/KondutoPassenger.cs
similarity index 100%
rename from KdtSdk/Models/KondutoPassenger.cs
rename to src/KdtSdk/Models/KondutoPassenger.cs
diff --git a/KdtSdk/Models/KondutoPayment.cs b/src/KdtSdk/Models/KondutoPayment.cs
similarity index 100%
rename from KdtSdk/Models/KondutoPayment.cs
rename to src/KdtSdk/Models/KondutoPayment.cs
diff --git a/KdtSdk/Models/KondutoPaymentType.cs b/src/KdtSdk/Models/KondutoPaymentType.cs
similarity index 100%
rename from KdtSdk/Models/KondutoPaymentType.cs
rename to src/KdtSdk/Models/KondutoPaymentType.cs
diff --git a/KdtSdk/Models/KondutoRecommendation.cs b/src/KdtSdk/Models/KondutoRecommendation.cs
similarity index 100%
rename from KdtSdk/Models/KondutoRecommendation.cs
rename to src/KdtSdk/Models/KondutoRecommendation.cs
diff --git a/KdtSdk/Models/KondutoSeller.cs b/src/KdtSdk/Models/KondutoSeller.cs
similarity index 100%
rename from KdtSdk/Models/KondutoSeller.cs
rename to src/KdtSdk/Models/KondutoSeller.cs
diff --git a/KdtSdk/Models/KondutoTransferPayment.cs b/src/KdtSdk/Models/KondutoTransferPayment.cs
similarity index 100%
rename from KdtSdk/Models/KondutoTransferPayment.cs
rename to src/KdtSdk/Models/KondutoTransferPayment.cs
diff --git a/KdtSdk/Models/KondutoTravel.cs b/src/KdtSdk/Models/KondutoTravel.cs
similarity index 100%
rename from KdtSdk/Models/KondutoTravel.cs
rename to src/KdtSdk/Models/KondutoTravel.cs
diff --git a/KdtSdk/Models/KondutoTravelInformation.cs b/src/KdtSdk/Models/KondutoTravelInformation.cs
similarity index 100%
rename from KdtSdk/Models/KondutoTravelInformation.cs
rename to src/KdtSdk/Models/KondutoTravelInformation.cs
diff --git a/KdtSdk/Models/KondutoTravelType.cs b/src/KdtSdk/Models/KondutoTravelType.cs
similarity index 100%
rename from KdtSdk/Models/KondutoTravelType.cs
rename to src/KdtSdk/Models/KondutoTravelType.cs
diff --git a/KdtSdk/Models/KondutoVoucherPayment.cs b/src/KdtSdk/Models/KondutoVoucherPayment.cs
similarity index 100%
rename from KdtSdk/Models/KondutoVoucherPayment.cs
rename to src/KdtSdk/Models/KondutoVoucherPayment.cs
diff --git a/KdtSdk/Utils/KondutoUtils.cs b/src/KdtSdk/Utils/KondutoUtils.cs
similarity index 95%
rename from KdtSdk/Utils/KondutoUtils.cs
rename to src/KdtSdk/Utils/KondutoUtils.cs
index 1d87ded..45e694b 100644
--- a/KdtSdk/Utils/KondutoUtils.cs
+++ b/src/KdtSdk/Utils/KondutoUtils.cs
@@ -5,6 +5,7 @@
using Newtonsoft.Json.Converters;
+using System.Reflection;
namespace KdtSdk.Utils
{
@@ -82,7 +83,11 @@ public abstract class JsonCreationConverter : JsonConverter
public override bool CanConvert(Type objectType)
{
+ #if NETSTANDARD1_3
+ return typeof(T).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo());
+ #else
return typeof(T).IsAssignableFrom(objectType);
+ #endif
}
public override object ReadJson(JsonReader reader,
diff --git a/KdtTests/Exceptions/KondutoHTTPExceptionFactoryTest.cs b/src/KdtTests/Exceptions/KondutoHTTPExceptionFactoryTest.cs
similarity index 88%
rename from KdtTests/Exceptions/KondutoHTTPExceptionFactoryTest.cs
rename to src/KdtTests/Exceptions/KondutoHTTPExceptionFactoryTest.cs
index 9a9bf37..1385480 100644
--- a/KdtTests/Exceptions/KondutoHTTPExceptionFactoryTest.cs
+++ b/src/KdtTests/Exceptions/KondutoHTTPExceptionFactoryTest.cs
@@ -1,11 +1,10 @@
using KdtSdk.Exceptions;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
+using Xunit;
namespace KdtTests.Exceptions
{
- [TestClass]
public class KondutoHTTPExceptionFactoryTest
{
private static Dictionary HTTP_STATUSES = new Dictionary()
@@ -20,17 +19,17 @@ public class KondutoHTTPExceptionFactoryTest
{500, typeof(KdtSdk.Exceptions.KondutoHTTPExceptionFactory.KondutoHTTPInternalErrorException)}
};
- [TestMethod]
+ [Fact]
public void BuildExceptionTest()
{
foreach (var entry in HTTP_STATUSES)
{
int statusCode = entry.Key;
- var klass = entry.Value;
+ var type = entry.Value;
String responseBody = "{\"statusCode\": \"" + statusCode + "\"}";
var exception = KondutoHTTPExceptionFactory.buildException(statusCode, responseBody);
- Assert.IsTrue(klass == exception.GetType());
+ Assert.Equal(type, exception.GetType());
}
}
}
diff --git a/KdtTests/Exceptions/KondutoHTTPExceptionTest.cs b/src/KdtTests/Exceptions/KondutoHTTPExceptionTest.cs
similarity index 74%
rename from KdtTests/Exceptions/KondutoHTTPExceptionTest.cs
rename to src/KdtTests/Exceptions/KondutoHTTPExceptionTest.cs
index 5973d69..15f0a47 100644
--- a/KdtTests/Exceptions/KondutoHTTPExceptionTest.cs
+++ b/src/KdtTests/Exceptions/KondutoHTTPExceptionTest.cs
@@ -1,10 +1,9 @@
using KdtSdk.Exceptions;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
+using Xunit;
namespace KdtTests.Exceptions
{
- [TestClass]
public class KondutoHTTPExceptionTest
{
private class KondutoFakeHTTPException : KondutoHTTPException
@@ -13,14 +12,14 @@ public KondutoFakeHTTPException(String message, String responseBody)
: base(message, responseBody) { }
}
- [TestMethod]
+ [Fact]
public void ConstructorTest()
{
String message = "fake message";
String json = "";
KondutoFakeHTTPException fakeException = new KondutoFakeHTTPException(message, json);
- Assert.AreEqual(fakeException.Message, String.Format("{0} Response body: {1}", message, json));
+ Assert.Equal(fakeException.Message, $"{message} Response body: {json}");
}
}
}
diff --git a/KdtTests/Exceptions/KondutoInvalidEntityExceptionTest.cs b/src/KdtTests/Exceptions/KondutoInvalidEntityExceptionTest.cs
similarity index 60%
rename from KdtTests/Exceptions/KondutoInvalidEntityExceptionTest.cs
rename to src/KdtTests/Exceptions/KondutoInvalidEntityExceptionTest.cs
index 5110794..4f9d7ba 100644
--- a/KdtTests/Exceptions/KondutoInvalidEntityExceptionTest.cs
+++ b/src/KdtTests/Exceptions/KondutoInvalidEntityExceptionTest.cs
@@ -1,22 +1,19 @@
using KdtSdk.Exceptions;
using KdtSdk.Models;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
+using Xunit;
namespace KdtTests.Exceptions
{
- [TestClass]
public class KondutoInvalidEntityExceptionTest
{
- [TestMethod]
+ [Fact]
public void InvalidEntityExceptionMessageTest()
{
KondutoCustomer customer = new KondutoCustomer();
customer.IsValid(); // triggers errors
KondutoInvalidEntityException exception = new KondutoInvalidEntityException(customer);
- Assert.AreEqual(String.Format("{0} is invalid: {1}", customer.ToString(), customer.GetError()),
- exception.Message, "incorrect expected exception message");
+ Assert.Equal($"{customer} is invalid: {customer.GetError()}", exception.Message);
}
}
}
diff --git a/KdtTests/Exceptions/KondutoUnexpectedAPIResponseTest.cs b/src/KdtTests/Exceptions/KondutoUnexpectedAPIResponseTest.cs
similarity index 67%
rename from KdtTests/Exceptions/KondutoUnexpectedAPIResponseTest.cs
rename to src/KdtTests/Exceptions/KondutoUnexpectedAPIResponseTest.cs
index 749c28c..090c08a 100644
--- a/KdtTests/Exceptions/KondutoUnexpectedAPIResponseTest.cs
+++ b/src/KdtTests/Exceptions/KondutoUnexpectedAPIResponseTest.cs
@@ -1,19 +1,18 @@
using System;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
using KdtSdk.Exceptions;
+using Xunit;
namespace KdtTests.Exceptions
{
- [TestClass]
public class KondutoUnexpectedAPIResponseExceptionTest
{
- [TestMethod]
+ [Fact]
public void GetMessageTest()
{
String responseBody = "";
KondutoUnexpectedAPIResponseException e = new KondutoUnexpectedAPIResponseException(responseBody);
- Assert.AreEqual("Unexpected API response: " + responseBody, e.Message);
+ Assert.Equal($"Unexpected API response: {responseBody}", e.Message);
}
}
}
diff --git a/KdtTests/Factories/KondutoAddressFactory.cs b/src/KdtTests/Factories/KondutoAddressFactory.cs
similarity index 100%
rename from KdtTests/Factories/KondutoAddressFactory.cs
rename to src/KdtTests/Factories/KondutoAddressFactory.cs
diff --git a/KdtTests/Factories/KondutoCustomerFactory.cs b/src/KdtTests/Factories/KondutoCustomerFactory.cs
similarity index 100%
rename from KdtTests/Factories/KondutoCustomerFactory.cs
rename to src/KdtTests/Factories/KondutoCustomerFactory.cs
diff --git a/KdtTests/Factories/KondutoDeviceFactory.cs b/src/KdtTests/Factories/KondutoDeviceFactory.cs
similarity index 100%
rename from KdtTests/Factories/KondutoDeviceFactory.cs
rename to src/KdtTests/Factories/KondutoDeviceFactory.cs
diff --git a/KdtTests/Factories/KondutoFlightFactory.cs b/src/KdtTests/Factories/KondutoFlightFactory.cs
similarity index 100%
rename from KdtTests/Factories/KondutoFlightFactory.cs
rename to src/KdtTests/Factories/KondutoFlightFactory.cs
diff --git a/KdtTests/Factories/KondutoGeolocationFactory.cs b/src/KdtTests/Factories/KondutoGeolocationFactory.cs
similarity index 100%
rename from KdtTests/Factories/KondutoGeolocationFactory.cs
rename to src/KdtTests/Factories/KondutoGeolocationFactory.cs
diff --git a/KdtTests/Factories/KondutoItemFactory.cs b/src/KdtTests/Factories/KondutoItemFactory.cs
similarity index 100%
rename from KdtTests/Factories/KondutoItemFactory.cs
rename to src/KdtTests/Factories/KondutoItemFactory.cs
diff --git a/KdtTests/Factories/KondutoNavigationInfoFactory.cs b/src/KdtTests/Factories/KondutoNavigationInfoFactory.cs
similarity index 100%
rename from KdtTests/Factories/KondutoNavigationInfoFactory.cs
rename to src/KdtTests/Factories/KondutoNavigationInfoFactory.cs
diff --git a/KdtTests/Factories/KondutoOrderFactory.cs b/src/KdtTests/Factories/KondutoOrderFactory.cs
similarity index 100%
rename from KdtTests/Factories/KondutoOrderFactory.cs
rename to src/KdtTests/Factories/KondutoOrderFactory.cs
diff --git a/KdtTests/Factories/KondutoPassengerFactory.cs b/src/KdtTests/Factories/KondutoPassengerFactory.cs
similarity index 100%
rename from KdtTests/Factories/KondutoPassengerFactory.cs
rename to src/KdtTests/Factories/KondutoPassengerFactory.cs
diff --git a/KdtTests/Factories/KondutoPaymentFactory.cs b/src/KdtTests/Factories/KondutoPaymentFactory.cs
similarity index 100%
rename from KdtTests/Factories/KondutoPaymentFactory.cs
rename to src/KdtTests/Factories/KondutoPaymentFactory.cs
diff --git a/KdtTests/Factories/KondutoSellerFactory.cs b/src/KdtTests/Factories/KondutoSellerFactory.cs
similarity index 100%
rename from KdtTests/Factories/KondutoSellerFactory.cs
rename to src/KdtTests/Factories/KondutoSellerFactory.cs
diff --git a/src/KdtTests/KdtTests.csproj b/src/KdtTests/KdtTests.csproj
new file mode 100644
index 0000000..c334d84
--- /dev/null
+++ b/src/KdtTests/KdtTests.csproj
@@ -0,0 +1,32 @@
+
+
+
+ Copyright © 2015
+ KdtTests
+ 1.1.0
+ Konduto
+ KdtTests
+ KdtTests
+ true
+ netcoreapp2.1
+
+
+
+
+
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+
+
+
+
+
+
diff --git a/src/KdtTests/KondutoTest.cs b/src/KdtTests/KondutoTest.cs
new file mode 100644
index 0000000..0595e3e
--- /dev/null
+++ b/src/KdtTests/KondutoTest.cs
@@ -0,0 +1,483 @@
+using KdtSdk;
+using KdtSdk.Exceptions;
+using KdtSdk.Models;
+using KdtTests.Factories;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using System;
+using System.Collections.Generic;
+using System.Net;
+using System.Net.Http;
+using System.Threading.Tasks;
+using Xunit;
+using KdtTests.Properties;
+
+namespace KdtTests
+{
+ public class KondutoTest
+ {
+ //static String AUTH_HEADER = "Basic VDczOEQ1MTZGMDlDQUIzQTJDMUVF";
+ static String AUTH_HEADER = "VDczOEQ1MTZGMDlDQUIzQTJDMUVF";
+ static String API_KEY = "T738D516F09CAB3A2C1EE";
+
+ String ORDER_ID;
+
+ JObject ANALYZE_ORDER_RESPONSE;
+ KondutoOrder ORDER_FROM_FILE;
+
+ JObject NOT_ANALYZE_ORDER_RESPONSE;
+
+
+ int[] HTTP_STATUSES = {
+ (int)HttpStatusCode.Unauthorized, // 401
+ (int)HttpStatusCode.Forbidden, // 403
+ (int)HttpStatusCode.NotFound, // 404
+ 422, // 422
+ (int)HttpStatusCode.MethodNotAllowed, // 425
+ 429, // 429
+ (int)HttpStatusCode.InternalServerError // 500
+ };
+
+ private Konduto konduto;
+
+ public KondutoTest()
+ {
+ konduto = new Konduto(API_KEY);
+
+ ANALYZE_ORDER_RESPONSE = JsonConvert.DeserializeObject(
+ Resources.Load("konduto_order"));
+
+ JToken jt;
+ ANALYZE_ORDER_RESPONSE.TryGetValue("order", out jt);
+ ORDER_FROM_FILE = KondutoModel.FromJson(jt.ToString());
+ ORDER_ID = ORDER_FROM_FILE.Id;
+
+ NOT_ANALYZE_ORDER_RESPONSE = JsonConvert.DeserializeObject(
+ Resources.Load("order_not_analyzed"));
+ }
+
+ [Fact]
+ public void GetOrderSuccessfullyTest()
+ {
+ Konduto kdt = new Konduto(API_KEY);
+
+ var fakeResponseHandler = new FakeResponseHandler();
+ var message = new HttpResponseMessage(HttpStatusCode.OK);
+ message.Content = new StringContent(ANALYZE_ORDER_RESPONSE.ToString());
+
+ var c = kdt.KondutoGetOrderUrl(ORDER_ID);
+
+ fakeResponseHandler.AddFakeResponse(kdt.KondutoGetOrderUrl(ORDER_ID), message);
+ kdt.__MessageHandler = fakeResponseHandler;
+
+ var v = kdt.GetOrder(ORDER_ID);
+
+ Assert.True(ORDER_FROM_FILE.Equals(kdt.GetOrder(ORDER_ID)));
+ }
+
+ [Fact]
+ public void GetOrderErrorTest()
+ {
+ foreach (int code in HTTP_STATUSES)
+ {
+ var fakeResponseHandler = new FakeResponseHandler();
+
+ var message = new HttpResponseMessage((HttpStatusCode)code);
+ message.Content = new StringContent(ORDER_FROM_FILE.ToJson());
+
+ fakeResponseHandler.AddFakeResponse(konduto.KondutoGetOrderUrl(ORDER_ID), message);
+ konduto.__MessageHandler = fakeResponseHandler;
+ Assert.ThrowsAny(() => konduto.GetOrder(ORDER_ID));
+ }
+ }
+
+ [Fact]
+ public void AnalyzeSuccessfullyTest()
+ {
+ var fakeResponseHandler = new FakeResponseHandler();
+ var message = new HttpResponseMessage(HttpStatusCode.OK);
+
+ message.Content = new StringContent(ANALYZE_ORDER_RESPONSE.ToString());
+
+ fakeResponseHandler.AddFakeResponse(konduto.KondutoPostOrderUrl(), message);
+ konduto.__MessageHandler = fakeResponseHandler;
+
+ KondutoOrder orderToSend = KondutoOrderFactory.basicOrder();
+ String s = orderToSend.ToJson();
+ KondutoOrder orderResponse = null;
+
+ Assert.True(orderToSend.Recommendation == KondutoRecommendation.none, "basic order should have no recommendation");
+ Assert.True(null == orderToSend.Score, "basic order should have no score");
+ Assert.True(null == orderToSend.Geolocation, "basic order should have no geolocation");
+ Assert.True(null == orderToSend.Device, "basic order should have no device");
+ Assert.True(null == orderToSend.NavigationInfo, "basic order should have no navigation info");
+ Assert.True(orderToSend.Analyze, "basic order should have analyze set to true");
+
+
+ orderResponse = konduto.Analyze(orderToSend);
+ Double? actualScore = ORDER_FROM_FILE.Score;
+ KondutoRecommendation? actualRecommendation = ORDER_FROM_FILE.Recommendation;
+ KondutoGeolocation actualGeolocation = ORDER_FROM_FILE.Geolocation;
+ KondutoDevice actualDevice = ORDER_FROM_FILE.Device;
+ KondutoNavigationInfo actualNavigationInfo = ORDER_FROM_FILE.NavigationInfo;
+
+ Assert.True(orderResponse.Geolocation.Equals(actualGeolocation));
+ Assert.Equal(orderResponse.Recommendation, actualRecommendation);
+ Assert.Equal(orderResponse.Device, actualDevice);
+ Assert.Equal(orderResponse.NavigationInfo, actualNavigationInfo);
+ Assert.Equal(orderResponse.Score, actualScore);
+ }
+
+ [Fact]
+ public void PostIntegrationTest()
+ {
+ Konduto konduto = new Konduto("T738D516F09CAB3A2C1EE");
+
+ KondutoCustomer Customer = new KondutoCustomer
+ {
+ Id = "28372",
+ Name = "KdtUser",
+ Email = "developer@example.com"
+ };
+
+ KondutoOrder order = new KondutoOrder
+ {
+ Id = Guid.NewGuid().ToString(),
+ Visitor = "38a9412f0b01b4dd1762ae424169a3e490d75c7a",
+ TotalAmount = 100.00,
+ Customer = Customer,
+ Analyze = true
+ };
+ konduto.Analyze(order);
+ Assert.True(order.Recommendation != KondutoRecommendation.none);
+ }
+
+ [Fact]
+ public void FullJsonIntegrationTest()
+ {
+ Konduto konduto = new Konduto("T738D516F09CAB3A2C1EE");
+
+ KondutoCustomer Customer = new KondutoCustomer
+ {
+ Id = "28372",
+ Name = "KdtUser",
+ Email = "developer@example.com",
+ TaxId = "613.815.776-10",
+ Phone1 = "+559912345678",
+ Phone2 = "(11)1234-5678",
+ IsNew = false,
+ IsVip = false,
+ CreatedAt = "2014-12-21"
+ };
+
+ KondutoPayment payment = new KondutoCreditCardPayment
+ {
+ Type = KondutoPaymentType.credit,
+ Status = KondutoCreditCardPaymentStatus.approved,
+ Bin = "490172",
+ Last4 = "0012",
+ ExpirationDate = "052026"
+ };
+
+ KondutoAddress billing = new KondutoAddress
+ {
+ Name = "Mark Thompson",
+ Address1 = "101 Maple Road",
+ Address2 = "Apto 33",
+ City = "Mato Grosso",
+ State = "Cuiabá",
+ Zip = "302798",
+ Country = "BR"
+ };
+
+ KondutoAddress shipping = new KondutoAddress
+ {
+ Name = "Mark Thompson",
+ Address1 = "101 Maple Road",
+ Address2 = "Apto 33",
+ City = "Mato Grosso",
+ State = "Cuiabá",
+ Zip = "302798",
+ Country = "BR"
+ };
+
+ List payments = new List{
+ payment
+ };
+
+ KondutoItem item1 = new KondutoItem
+ {
+ Sku = "9919023",
+ ProductCode = "123456789999",
+ Category = 100,
+ Name = "Xbox One",
+ Description = "Xbox One Promoção Com 2 Controles",
+ UnitCost = 1999.99,
+ Quantity = 1,
+ CreatedAt = "2014-12-21"
+ };
+
+ KondutoItem item2 = new KondutoItem
+ {
+ Sku = "0017273",
+ Category = 201,
+ Name = "CD Nirvana Nevermind",
+ Description = "CD Nirvana Nevermind",
+ UnitCost = 29.90,
+ Quantity = 2,
+ Discount = 5.00
+ };
+
+ KondutoOrder order = new KondutoOrder
+ {
+ Id = Guid.NewGuid().ToString(),
+ Visitor = "38a9412f0b01b4dd1762ae424169a3e490d75c7a",
+ TotalAmount = 100.00,
+ ShippingAmount = 6.00,
+ TaxAmount = 12.00,
+ Ip = "201.27.127.73",
+ Currency = "BRL",
+ Customer = Customer,
+ Payments = payments,
+ BillingAddress = billing,
+ ShippingAddress = shipping,
+ MessagesExchanged = 2,
+ PurchasedAt = "2014-12-31T13:00:00Z",
+ FirstMessage = "2014-12-31T13:00:00Z",
+ ShoppingCart = new List{
+ item1,
+ item2
+ },
+ Analyze = true
+ };
+ konduto.Analyze(order);
+ Assert.True(order.Recommendation != KondutoRecommendation.none);
+ var getOrder = konduto.GetOrder(order.Id);
+ Assert.NotNull(getOrder);
+ }
+
+ [Fact]
+ public void PostBoletoIntegrationTest()
+ {
+ Konduto konduto = new Konduto("T738D516F09CAB3A2C1EE");
+
+ KondutoCustomer Customer = new KondutoCustomer
+ {
+ Id = "28372",
+ Name = "KdtUser",
+ Email = "developer@example.com"
+ };
+
+ KondutoOrder order = new KondutoOrder
+ {
+ Id = Guid.NewGuid().ToString(),
+ Visitor = "38a9412f0b01b4dd1762ae424169a3e490d75c7a",
+ TotalAmount = 100.00,
+ Customer = Customer,
+ Payments = KondutoPaymentFactory.CreatePayments(),
+ Analyze = true
+ };
+ konduto.Analyze(order);
+ Assert.True(order.Recommendation != KondutoRecommendation.none);
+ }
+
+ [Fact]
+ public void PostNonCreditIntegrationTest()
+ {
+ Konduto konduto = new Konduto("T738D516F09CAB3A2C1EE");
+
+ KondutoCustomer Customer = new KondutoCustomer
+ {
+ Id = "28372",
+ Name = "KdtUser",
+ Email = "developer@example.com"
+ };
+
+ KondutoOrder order = new KondutoOrder
+ {
+ Id = Guid.NewGuid().ToString(),
+ Visitor = "38a9412f0b01b4dd1762ae424169a3e490d75c7a",
+ TotalAmount = 100.00,
+ Customer = Customer,
+ Payments = KondutoPaymentFactory.CreateNonCreditPayments(),
+ Analyze = true
+ };
+
+ konduto.Analyze(order);
+ Assert.True(order.Recommendation != KondutoRecommendation.none);
+ }
+
+ [Fact]
+ public void GetIntegrationTest()
+ {
+ var konduto = new Konduto("T738D516F09CAB3A2C1EE");
+ var order = konduto.GetOrder("1429744771");
+ Assert.NotNull(order);
+ }
+
+ [Fact]
+ public void PutIntegrationTest()
+ {
+ var id = $"{Guid.NewGuid()}";
+ Konduto konduto = new Konduto("T738D516F09CAB3A2C1EE");
+
+ KondutoCustomer Customer = new KondutoCustomer
+ {
+ Id = "28372",
+ Name = "KdtUser",
+ Email = "developer@example.com"
+ };
+
+ KondutoOrder order = new KondutoOrder
+ {
+ Id = id,
+ Visitor = "38a9412f0b01b4dd1762ae424169a3e490d75c7a",
+ TotalAmount = 100.00,
+ Customer = Customer,
+ Analyze = true
+ };
+ konduto.Analyze(order);
+ Assert.True(order.Recommendation != KondutoRecommendation.none);
+ konduto.UpdateOrderStatus(id, KondutoOrderStatus.fraud, "Manual Review");
+ konduto.UpdateOrderStatus(id, KondutoOrderStatus.not_authorized, "Manual Review");
+ var updatedOrder = konduto.GetOrder(id);
+ Assert.NotNull(updatedOrder);
+ }
+
+ [Fact]
+ public void SendOrderToKondutoButDoNotAnalyzeTest()
+ {
+ var fakeResponseHandler = new FakeResponseHandler();
+ var message = new HttpResponseMessage(HttpStatusCode.OK);
+ message.Content = new StringContent(NOT_ANALYZE_ORDER_RESPONSE.ToString());
+
+ fakeResponseHandler.AddFakeResponse(konduto.KondutoPostOrderUrl(), message);
+ konduto.__MessageHandler = fakeResponseHandler;
+
+ KondutoOrder orderToSend = KondutoOrderFactory.basicOrder();
+ orderToSend.Analyze = false;
+
+ Assert.False(orderToSend.Analyze, "order analyze should be false");
+
+ orderToSend = konduto.Analyze(orderToSend);
+ Assert.Null(orderToSend.Score);
+ Assert.Equal(KondutoRecommendation.none, orderToSend.Recommendation);
+ }
+
+ [Fact]
+ public void AnalyzeInvalidOrderTest()
+ {
+ var fakeResponseHandler = new FakeResponseHandler();
+ var message = new HttpResponseMessage(HttpStatusCode.OK);
+ message.Content = new StringContent(ORDER_FROM_FILE.ToJson());
+
+ fakeResponseHandler.AddFakeResponse(konduto.KondutoPostOrderUrl(), message);
+ konduto.__MessageHandler = fakeResponseHandler;
+
+ KondutoOrder orderToSend = new KondutoOrder();
+ Assert.Throws(() => konduto.Analyze(orderToSend));
+ }
+
+ [Fact]
+ public void AnalyzeHTTPErrorTest()
+ {
+ foreach (int code in HTTP_STATUSES)
+ {
+ var fakeResponseHandler = new FakeResponseHandler();
+
+ var message = new HttpResponseMessage((HttpStatusCode)code);
+ message.Content = new StringContent(ORDER_FROM_FILE.ToJson());
+
+ fakeResponseHandler.AddFakeResponse(konduto.KondutoPostOrderUrl(), message);
+ konduto.__MessageHandler = fakeResponseHandler;
+
+ Assert.ThrowsAny(() => konduto.Analyze(KondutoOrderFactory.basicOrder()));
+ }
+ }
+
+ [Fact]
+ public void UpdateSuccessfullyTest()
+ {
+ var fakeResponseHandler = new FakeResponseHandler();
+ var message = new HttpResponseMessage(HttpStatusCode.OK);
+ message.Content = new StringContent("{\"old_status\":\"review\",\"new_status\":\"approved\"}");
+
+ fakeResponseHandler.AddFakeResponse(konduto.KondutoPutOrderUrl(ORDER_ID), message);
+ konduto.__MessageHandler = fakeResponseHandler;
+ konduto.UpdateOrderStatus(ORDER_ID, KondutoOrderStatus.approved, "no comments");
+ }
+
+ [Fact]
+ public void UpdateHTTPErrorTest()
+ {
+ foreach (int code in HTTP_STATUSES)
+ {
+ var fakeResponseHandler = new FakeResponseHandler();
+
+ var message = new HttpResponseMessage((HttpStatusCode)code);
+ message.Content = new StringContent("{}");
+
+ fakeResponseHandler.AddFakeResponse(konduto.KondutoPutOrderUrl(ORDER_ID), message);
+ konduto.__MessageHandler = fakeResponseHandler;
+ Assert.ThrowsAny(() => konduto.Analyze(KondutoOrderFactory.basicOrder()));
+ }
+ }
+
+ [Fact]
+ public void InvalidStatusWhenUpdatingTest()
+ {
+ List forbiddenStatus =
+ new List()
+ {
+ KondutoOrderStatus.not_analyzed,
+ KondutoOrderStatus.pending
+ };
+ foreach (var status in forbiddenStatus)
+ Assert.Throws(() => konduto.UpdateOrderStatus(ORDER_FROM_FILE.Id, status, ""));
+ }
+
+ [Fact]
+ public void NullCommentsWhenUpdatingTest()
+ {
+ Assert.Throws(() =>
+ konduto.UpdateOrderStatus(ORDER_FROM_FILE.Id, KondutoOrderStatus.approved, null));
+ }
+
+ [Fact]
+ public void InvalidApiKeyTest()
+ {
+ Assert.Throws(() => konduto.SetApiKey("invalid key"));
+ }
+
+ private class FakeResponseHandler : DelegatingHandler
+ {
+ private readonly Dictionary _FakeResponses = new Dictionary();
+
+ public void AddFakeResponse(Uri uri, HttpResponseMessage responseMessage)
+ {
+ _FakeResponses.Add(uri, responseMessage);
+ }
+
+ protected async override Task SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
+ {
+ return await Task.Run(() =>
+ {
+ Assert.True(AUTH_HEADER == request.Headers.Authorization.Parameter, "Failing authorizing request.");
+
+ if (_FakeResponses.ContainsKey(request.RequestUri))
+ {
+ return _FakeResponses[request.RequestUri];
+ }
+ else
+ {
+ return new HttpResponseMessage(HttpStatusCode.NotFound)
+ {
+ RequestMessage = request
+ };
+ }
+ });
+ }
+ }
+
+ }
+}
diff --git a/src/KdtTests/Models/KondutoAddressTest.cs b/src/KdtTests/Models/KondutoAddressTest.cs
new file mode 100644
index 0000000..94b651d
--- /dev/null
+++ b/src/KdtTests/Models/KondutoAddressTest.cs
@@ -0,0 +1,25 @@
+using KdtSdk.Exceptions;
+using KdtSdk.Models;
+using KdtSdk.Utils;
+using KdtTests.Factories;
+using System;
+using Xunit;
+using KdtTests.Properties;
+
+namespace KdtTests.Models
+{
+ public class KondutoAddressTest
+ {
+ [Fact]
+ public void SerializeTest()
+ {
+ String expectedJSON = KondutoUtils.LoadJson(Resources.Load("address")).ToJson();
+ KondutoAddress address = KondutoAddressFactory.Create();
+
+ var actualJSON = address.ToJson();
+ Assert.Equal(expectedJSON, actualJSON);
+ var addressFromJSON = KondutoModel.FromJson(expectedJSON);
+ Assert.Equal(address, addressFromJSON);
+ }
+ }
+}
diff --git a/src/KdtTests/Models/KondutoBoletoPaymentTest.cs b/src/KdtTests/Models/KondutoBoletoPaymentTest.cs
new file mode 100644
index 0000000..c943cb0
--- /dev/null
+++ b/src/KdtTests/Models/KondutoBoletoPaymentTest.cs
@@ -0,0 +1,25 @@
+using KdtSdk.Exceptions;
+using KdtSdk.Models;
+using KdtSdk.Utils;
+using KdtTests.Factories;
+using System;
+using Xunit;
+using KdtTests.Properties;
+
+namespace KdtTests.Models
+{
+ public class KondutoBoletoPaymentTest
+ {
+ [Fact]
+ public void SerializeTest()
+ {
+ String expectedJSON = KondutoUtils.GetFirstJArrayElement(Resources.Load("payments"));
+ KondutoCreditCardPayment payment = KondutoPaymentFactory.CreateCreditCardPayment();
+
+ var actualJSON = payment.ToJson();
+ Assert.Equal(expectedJSON, actualJSON);
+ KondutoCreditCardPayment paymentFromJSON = KondutoModel.FromJson(expectedJSON);
+ Assert.Equal(payment, paymentFromJSON);
+ }
+ }
+}
diff --git a/src/KdtTests/Models/KondutoCustomerTest.cs b/src/KdtTests/Models/KondutoCustomerTest.cs
new file mode 100644
index 0000000..0c49eb4
--- /dev/null
+++ b/src/KdtTests/Models/KondutoCustomerTest.cs
@@ -0,0 +1,24 @@
+using KdtSdk.Exceptions;
+using KdtSdk.Models;
+using KdtSdk.Utils;
+using KdtTests.Factories;
+using System;
+using System.Diagnostics;
+using Xunit;
+using KdtTests.Properties;
+
+namespace KdtTests.Models
+{
+ public class KondutoCustomerTest
+ {
+ [Fact]
+ public void SerializationTest()
+ {
+ var customer = KondutoCustomerFactory.CompleteCustomer();
+ var customerJSON = KondutoUtils.LoadJson(Resources.Load("customer")).ToJson();
+ Assert.Equal(customerJSON, customer.ToJson());
+ var deserializedCustomer = KondutoModel.FromJson(customerJSON);
+ Assert.Equal(customer, deserializedCustomer);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/KdtTests/Models/KondutoDeviceTest.cs b/src/KdtTests/Models/KondutoDeviceTest.cs
new file mode 100644
index 0000000..8d115b7
--- /dev/null
+++ b/src/KdtTests/Models/KondutoDeviceTest.cs
@@ -0,0 +1,22 @@
+using KdtSdk.Exceptions;
+using KdtSdk.Models;
+using KdtSdk.Utils;
+using KdtTests.Factories;
+using System;
+using Xunit;
+using KdtTests.Properties;
+
+namespace KdtTests.Models
+{
+ public class KondutoDeviceTest
+ {
+ [Fact]
+ public void SerializeTest()
+ {
+ KondutoDevice device = KondutoDeviceFactory.Create();
+ String deviceJSON = KondutoUtils.LoadJson(Resources.Load("device")).ToJson();
+ Assert.Equal(deviceJSON, device.ToJson());
+ Assert.Equal(KondutoModel.FromJson(deviceJSON), device);
+ }
+ }
+}
diff --git a/KdtTests/Models/KondutoGeolocationTest.cs b/src/KdtTests/Models/KondutoGeolocationTest.cs
similarity index 50%
rename from KdtTests/Models/KondutoGeolocationTest.cs
rename to src/KdtTests/Models/KondutoGeolocationTest.cs
index 2232ebf..4112b2f 100644
--- a/KdtTests/Models/KondutoGeolocationTest.cs
+++ b/src/KdtTests/Models/KondutoGeolocationTest.cs
@@ -2,33 +2,25 @@
using KdtSdk.Models;
using KdtSdk.Utils;
using KdtTests.Factories;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Text;
+using Xunit;
+using KdtTests.Properties;
namespace KdtTests.Models
{
- [TestClass]
public class KondutoGeolocationTest
{
- [TestMethod]
+ [Fact]
public void SerializationTest()
{
KondutoGeolocation geolocation = KondutoGeolocationFactory.Create();
- String geolocationJSON = KondutoUtils.LoadJson(Properties.Resources.geolocation).ToJson();
-
- try
- {
- Assert.AreEqual(geolocationJSON, geolocation.ToJson(), "serialization failed");
- }
- catch (KondutoInvalidEntityException e)
- {
- Assert.Fail("geolocation should be valid");
- }
+ String geolocationJSON = KondutoUtils.LoadJson(Resources.Load("geolocation")).ToJson();
+ Assert.Equal(geolocationJSON, geolocation.ToJson());
KondutoGeolocation geolocationDeserialized = KondutoModel.FromJson(geolocationJSON);
- Assert.AreEqual(geolocation, geolocationDeserialized, "deserialization failed");
+ Assert.Equal(geolocation, geolocationDeserialized);
}
}
}
\ No newline at end of file
diff --git a/src/KdtTests/Models/KondutoItemTest.cs b/src/KdtTests/Models/KondutoItemTest.cs
new file mode 100644
index 0000000..ff2997e
--- /dev/null
+++ b/src/KdtTests/Models/KondutoItemTest.cs
@@ -0,0 +1,28 @@
+using System;
+using KdtSdk.Exceptions;
+using KdtSdk.Models;
+using KdtSdk.Utils;
+using KdtTests.Factories;
+using KdtTests.Properties;
+using Xunit;
+
+namespace KdtTests.Models
+{
+ public class KondutoItemTest
+ {
+ KondutoItem greenTShirt = KondutoItemFactory.CreateGreenTShirt();
+ String greenTShirtJSON = KondutoUtils.GetFirstJArrayElement(Resources.Load("shopping_cart"));
+
+ [Fact]
+ public void SerializationTest()
+ {
+ Assert.Equal(greenTShirtJSON, greenTShirt.ToJson());
+ }
+
+ [Fact]
+ public void Deserializationtest()
+ {
+ Assert.True(greenTShirt.Equals(KondutoModel.FromJson(greenTShirtJSON)));
+ }
+ }
+}
diff --git a/src/KdtTests/Models/KondutoNavigationInfoTest.cs b/src/KdtTests/Models/KondutoNavigationInfoTest.cs
new file mode 100644
index 0000000..4961688
--- /dev/null
+++ b/src/KdtTests/Models/KondutoNavigationInfoTest.cs
@@ -0,0 +1,24 @@
+using KdtSdk.Exceptions;
+using KdtSdk.Models;
+using KdtSdk.Utils;
+using KdtTests.Factories;
+using System;
+using Xunit;
+using KdtTests.Properties;
+
+namespace KdtTests.Models
+{
+ public class KondutoNavigationInfoTest
+ {
+ [Fact]
+ public void SerializationTest()
+ {
+ KondutoNavigationInfo navigationInfo = KondutoNavigationInfoFactory.Create();
+
+ String navigationInfoJSON = KondutoUtils.LoadJson(Resources.Load("navigation")).ToJson();
+ Assert.Equal(navigationInfoJSON ,navigationInfo.ToJson());
+ KondutoNavigationInfo navigationInfoDeserialized = KondutoModel.FromJson(navigationInfoJSON);
+ Assert.Equal(navigationInfoDeserialized, navigationInfo);
+ }
+ }
+}
diff --git a/src/KdtTests/Models/KondutoOrderTest.cs b/src/KdtTests/Models/KondutoOrderTest.cs
new file mode 100644
index 0000000..cf3dbb3
--- /dev/null
+++ b/src/KdtTests/Models/KondutoOrderTest.cs
@@ -0,0 +1,60 @@
+using KdtSdk.Exceptions;
+using KdtSdk.Models;
+using KdtSdk.Utils;
+using KdtTests.Factories;
+using System;
+using Xunit;
+using KdtTests.Properties;
+
+namespace KdtTests.Models
+{
+ public class KondutoOrderTest
+ {
+ [Fact]
+ public void IsValidTest()
+ {
+ KondutoOrder order = new KondutoOrder();
+ Assert.False(order.IsValid(), "order should be invalid without id");
+
+ order.Id = "order1";
+ Assert.False(order.IsValid(), "order should be invalid without total amount");
+
+ order.TotalAmount = 120.1;
+ Assert.False(order.IsValid(), "order should be invalid without customer");
+
+ order.Customer = KondutoCustomerFactory.BasicCustomer();
+ Assert.True(order.IsValid(), "order should be valid");
+ Assert.True(order.GetError() == null, "order errors should be empty");
+ }
+
+ [Fact]
+ public void SerializationTest()
+ {
+ KondutoOrder order = KondutoOrderFactory.completeOrder();
+ String orderJSON = KondutoUtils.LoadJson(Resources.Load("order")).ToJson();
+
+ Assert.Equal(orderJSON, order.ToJson());
+ KondutoOrder deserializedOrder = KondutoModel.FromJson(orderJSON);
+ Assert.True(order.Equals(deserializedOrder), "deserialization failed");
+ }
+
+ [Fact]
+ public void SerializationTestWithShoppingAndFlight()
+ {
+ KondutoOrder order = KondutoOrderFactory.completeOrder();
+ order.Travel = KondutoFlightFactory.CreateFlight();
+ Assert.Throws(() => order.ToJson());
+
+ order = KondutoOrderFactory.completeOrder();
+ order.Travel = KondutoFlightFactory.CreateFlight();
+ order.ShoppingCart = null;
+ }
+
+ [Fact]
+ public void invalidOrderSerializationThrowsExceptionTest()
+ {
+ KondutoOrder order = new KondutoOrder();
+ Assert.Throws(() => order.ToJson());
+ }
+ }
+}
diff --git a/src/KdtTests/Models/KondutoPassengerTest.cs b/src/KdtTests/Models/KondutoPassengerTest.cs
new file mode 100644
index 0000000..dd08900
--- /dev/null
+++ b/src/KdtTests/Models/KondutoPassengerTest.cs
@@ -0,0 +1,26 @@
+using KdtSdk.Exceptions;
+using KdtSdk.Models;
+using KdtSdk.Utils;
+using KdtTests.Factories;
+using System;
+using System.Diagnostics;
+using Xunit;
+using KdtTests.Properties;
+
+namespace KdtTests.Models
+{
+ public class KondutoPassengerTest
+ {
+ [Fact]
+ public void SerializationTest()
+ {
+ String expectedJSON = KondutoUtils.LoadJson(Resources.Load("passenger")).ToJson();
+ KondutoPassenger passenger = KondutoPassengerFactory.CompletePassenger();
+
+ var actualJSON = passenger.ToJson();
+ Assert.Equal(expectedJSON, actualJSON);
+ KondutoPassenger passengerFromJson = KondutoModel.FromJson(expectedJSON);
+ Assert.Equal(passenger, passengerFromJson);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/KdtTests/Models/KondutoPaymentTest.cs b/src/KdtTests/Models/KondutoPaymentTest.cs
new file mode 100644
index 0000000..f6c8837
--- /dev/null
+++ b/src/KdtTests/Models/KondutoPaymentTest.cs
@@ -0,0 +1,78 @@
+using KdtSdk.Exceptions;
+using KdtSdk.Models;
+using KdtSdk.Utils;
+using KdtTests.Factories;
+using Newtonsoft.Json.Linq;
+using System;
+using Xunit;
+using KdtTests.Properties;
+
+namespace KdtTests.Models
+{
+ public class KondutoPaymentTest
+ {
+ [Fact]
+ public void CreditSerializeTest()
+ {
+ String expectedJSON = KondutoUtils.GetFirstJArrayElement(Resources.Load("payments"));
+ KondutoCreditCardPayment payment = KondutoPaymentFactory.CreateCreditCardPayment();
+
+ var actualJSON = payment.ToJson();
+ Assert.Equal(expectedJSON, actualJSON);
+ KondutoCreditCardPayment paymentFromJSON = KondutoModel.FromJson(expectedJSON);
+ Assert.Equal(payment, paymentFromJSON);
+ }
+
+ [Fact]
+ public void BoletoSerializeTest()
+ {
+ JArray a = JArray.Parse(Resources.Load("payments"));
+ String expectedJSON = a.Last.ToString();
+ KondutoBoletoPayment payment = KondutoPaymentFactory.CreateBoletoPayment();
+
+ var actualJSON = payment.ToJson();
+ Assert.Equal(expectedJSON, actualJSON);
+ KondutoBoletoPayment paymentFromJSON = KondutoModel.FromJson(expectedJSON);
+ Assert.Equal(payment, paymentFromJSON);
+ }
+
+ [Fact]
+ public void DebitSerializeTest()
+ {
+ JArray a = JArray.Parse(Resources.Load("payments"));
+ String expectedJSON = a[1].ToString();
+ KondutoDebitPayment payment = KondutoPaymentFactory.CreateDebitPayment();
+
+ var actualJSON = payment.ToJson();
+ Assert.Equal(expectedJSON, actualJSON);
+ KondutoDebitPayment paymentFromJSON = KondutoModel.FromJson(expectedJSON);
+ Assert.Equal(payment, paymentFromJSON);
+ }
+
+ [Fact]
+ public void TransferSerializeTest()
+ {
+ JArray a = JArray.Parse(Resources.Load("payments"));
+ String expectedJSON = a[3].ToString();
+ KondutoTransferPayment payment = KondutoPaymentFactory.CreateTransferPayment();
+
+ var actualJSON = payment.ToJson();
+ Assert.Equal(expectedJSON, actualJSON);
+ KondutoTransferPayment paymentFromJSON = KondutoModel.FromJson(expectedJSON);
+ Assert.Equal(payment, paymentFromJSON);
+ }
+
+ [Fact]
+ public void VoucherSerializeTest()
+ {
+ JArray a = JArray.Parse(Resources.Load("payments"));
+ String expectedJSON = a[2].ToString();
+ KondutoVoucherPayment payment = KondutoPaymentFactory.CreateVoucherPayment();
+
+ var actualJSON = payment.ToJson();
+ Assert.Equal(expectedJSON, actualJSON);
+ KondutoVoucherPayment paymentFromJSON = KondutoModel.FromJson(expectedJSON);
+ Assert.Equal(payment, paymentFromJSON);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/KdtTests/Models/KondutoSellerTest.cs b/src/KdtTests/Models/KondutoSellerTest.cs
new file mode 100644
index 0000000..d8e0131
--- /dev/null
+++ b/src/KdtTests/Models/KondutoSellerTest.cs
@@ -0,0 +1,25 @@
+using KdtSdk.Exceptions;
+using KdtSdk.Models;
+using KdtSdk.Utils;
+using KdtTests.Factories;
+using System;
+using Xunit;
+using KdtTests.Properties;
+
+namespace KdtTests.Models
+{
+ public class KondutoSellerTest
+ {
+ [Fact]
+ public void SerializationTest()
+ {
+ String expectedJSON = KondutoUtils.LoadJson(Resources.Load("seller")).ToJson();
+ KondutoSeller seller = KondutoSellerFactory.Create();
+
+ var actualJSON = seller.ToJson();
+ Assert.Equal(expectedJSON, actualJSON);
+ KondutoSeller sellerFromJson = KondutoModel.FromJson(expectedJSON);
+ Assert.Equal(seller, sellerFromJson);
+ }
+ }
+}
diff --git a/src/KdtTests/Models/KondutoTravelTest.cs b/src/KdtTests/Models/KondutoTravelTest.cs
new file mode 100644
index 0000000..6052f4c
--- /dev/null
+++ b/src/KdtTests/Models/KondutoTravelTest.cs
@@ -0,0 +1,25 @@
+using KdtSdk.Exceptions;
+using KdtSdk.Models;
+using KdtSdk.Utils;
+using KdtTests.Factories;
+using System;
+using Xunit;
+using KdtTests.Properties;
+
+namespace KdtTests.Models
+{
+ public class KondutoTravelTest
+ {
+ [Fact]
+ public void SerializeTest()
+ {
+ String expectedJSON = KondutoUtils.LoadJson(Resources.Load("flight")).ToJson();
+ KondutoTravel flight = KondutoFlightFactory.CreateFlight();
+
+ var actualJSON = flight.ToJson();
+ Assert.Equal(expectedJSON, actualJSON);
+ KondutoTravel flightFromJSON = KondutoModel.FromJson(expectedJSON);
+ Assert.Equal(flight, flightFromJSON);
+ }
+ }
+}
diff --git a/src/KdtTests/Properties/Resources.cs b/src/KdtTests/Properties/Resources.cs
new file mode 100644
index 0000000..7f805ef
--- /dev/null
+++ b/src/KdtTests/Properties/Resources.cs
@@ -0,0 +1,21 @@
+using System.IO;
+using System.Reflection;
+
+namespace KdtTests.Properties
+{
+ internal static class Resources
+ {
+ ///
+ /// Loads an embed resource file
+ ///
+ /// File name
+ /// File extension
+ /// String
+ internal static string Load(string name, string extension = "txt")
+ {
+ var assembly = typeof(Resources).GetTypeInfo().Assembly;
+ var resource = assembly.GetManifestResourceStream($"KdtTests.Resources.{name}.{extension}");
+ return new StreamReader(resource).ReadToEnd();
+ }
+ }
+}
diff --git a/KdtTests/Resources/address.txt b/src/KdtTests/Resources/address.txt
similarity index 100%
rename from KdtTests/Resources/address.txt
rename to src/KdtTests/Resources/address.txt
diff --git a/KdtTests/Resources/customer.txt b/src/KdtTests/Resources/customer.txt
similarity index 100%
rename from KdtTests/Resources/customer.txt
rename to src/KdtTests/Resources/customer.txt
diff --git a/KdtTests/Resources/device.txt b/src/KdtTests/Resources/device.txt
similarity index 100%
rename from KdtTests/Resources/device.txt
rename to src/KdtTests/Resources/device.txt
diff --git a/KdtTests/Resources/flight.txt b/src/KdtTests/Resources/flight.txt
similarity index 100%
rename from KdtTests/Resources/flight.txt
rename to src/KdtTests/Resources/flight.txt
diff --git a/KdtTests/Resources/geolocation.txt b/src/KdtTests/Resources/geolocation.txt
similarity index 100%
rename from KdtTests/Resources/geolocation.txt
rename to src/KdtTests/Resources/geolocation.txt
diff --git a/KdtTests/Resources/konduto_order.txt b/src/KdtTests/Resources/konduto_order.txt
similarity index 100%
rename from KdtTests/Resources/konduto_order.txt
rename to src/KdtTests/Resources/konduto_order.txt
diff --git a/KdtTests/Resources/navigation.txt b/src/KdtTests/Resources/navigation.txt
similarity index 100%
rename from KdtTests/Resources/navigation.txt
rename to src/KdtTests/Resources/navigation.txt
diff --git a/KdtTests/Resources/order.txt b/src/KdtTests/Resources/order.txt
similarity index 100%
rename from KdtTests/Resources/order.txt
rename to src/KdtTests/Resources/order.txt
diff --git a/KdtTests/Resources/order_not_analyzed.txt b/src/KdtTests/Resources/order_not_analyzed.txt
similarity index 100%
rename from KdtTests/Resources/order_not_analyzed.txt
rename to src/KdtTests/Resources/order_not_analyzed.txt
diff --git a/KdtTests/Resources/passenger.txt b/src/KdtTests/Resources/passenger.txt
similarity index 100%
rename from KdtTests/Resources/passenger.txt
rename to src/KdtTests/Resources/passenger.txt
diff --git a/KdtTests/Resources/payments.txt b/src/KdtTests/Resources/payments.txt
similarity index 100%
rename from KdtTests/Resources/payments.txt
rename to src/KdtTests/Resources/payments.txt
diff --git a/KdtTests/Resources/seller.txt b/src/KdtTests/Resources/seller.txt
similarity index 100%
rename from KdtTests/Resources/seller.txt
rename to src/KdtTests/Resources/seller.txt
diff --git a/KdtTests/Resources/shopping_cart.txt b/src/KdtTests/Resources/shopping_cart.txt
similarity index 100%
rename from KdtTests/Resources/shopping_cart.txt
rename to src/KdtTests/Resources/shopping_cart.txt