Skip to content

Commit

Permalink
This should make tests be able to load those JSON files from a local …
Browse files Browse the repository at this point in the history
…path in Windows, Linux and MacOS without issue.
  • Loading branch information
masojus committed Nov 4, 2017
1 parent 74d10c3 commit 81e3f4d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
21 changes: 11 additions & 10 deletions Keen.NET.Test/DataSetTests_Integration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Keen.Core;
using Keen.Core;
using Keen.Core.Dataset;
using Keen.Core.Query;
using Moq;
Expand All @@ -9,7 +9,6 @@
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;


Expand All @@ -26,7 +25,7 @@ public class DatasetTests_Integration : TestBase
[Test]
public void Results_Success()
{
var apiResponse = File.ReadAllText($"{this.GetLocalPath()}/ApiResponses/GetDatasetResults.json");
var apiResponse = File.ReadAllText($"{GetApiResponsesPath()}/GetDatasetResults.json");
IKeenHttpClientProvider httpClientProvider = null;

if (UseMocks)
Expand All @@ -44,7 +43,7 @@ public void Results_Success()
[Test]
public void Definition_Success()
{
var apiResponse = File.ReadAllText($"{this.GetLocalPath()}/ApiResponses/GetDatasetDefinition.json");
var apiResponse = File.ReadAllText($"{GetApiResponsesPath()}/GetDatasetDefinition.json");
IKeenHttpClientProvider httpClientProvider = null;

if (UseMocks)
Expand All @@ -61,7 +60,7 @@ public void Definition_Success()
[Test]
public void ListDefinitions_Success()
{
var apiResponse = File.ReadAllText($"{this.GetLocalPath()}/ApiResponses/ListDatasetDefinitions.json");
var apiResponse = File.ReadAllText($"{GetApiResponsesPath()}/ListDatasetDefinitions.json");
IKeenHttpClientProvider httpClientProvider = null;

if (UseMocks)
Expand All @@ -86,7 +85,7 @@ public void ListDefinitions_Success()
[Test]
public void ListAllDefinitions_Success()
{
var apiResponse = File.ReadAllText($"{this.GetLocalPath()}/ApiResponses/ListDatasetDefinitions.json");
var apiResponse = File.ReadAllText($"{GetApiResponsesPath()}/ListDatasetDefinitions.json");
IKeenHttpClientProvider httpClientProvider = null;

if (UseMocks)
Expand Down Expand Up @@ -124,7 +123,7 @@ public void Delete_Success()
[Test]
public void CreateDataset_Success()
{
var apiResponse = File.ReadAllText($"{this.GetLocalPath()}/ApiResponses/GetDatasetDefinition.json");
var apiResponse = File.ReadAllText($"{GetApiResponsesPath()}/GetDatasetDefinition.json");

IKeenHttpClientProvider httpClientProvider = null;

Expand Down Expand Up @@ -306,10 +305,12 @@ public void CreateDataset_Throws()
Assert.Throws<KeenException>(() => brokenClient.CreateDataset(CreateDatasetDefinition()));
}

private string GetLocalPath()
private string GetApiResponsesPath()
{
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
return new Uri(path).LocalPath;
var localPath = AppDomain.CurrentDomain.BaseDirectory;
var apiResponsesPath = $"{localPath}/ApiResponses";

return apiResponsesPath;
}

private IKeenHttpClientProvider GetMockHttpClientProviderForGetAsync(string response, HttpStatusCode status = HttpStatusCode.OK)
Expand Down
2 changes: 1 addition & 1 deletion Keen.NET.Test/DatasetTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Keen.Core;
using Keen.Core;
using Keen.Core.Dataset;
using Keen.Core.Query;
using Moq;
Expand Down
2 changes: 1 addition & 1 deletion Keen.NET.Test/KeenClientTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Keen.Core;
using Keen.Core;
using Keen.Core.EventCache;
using Moq;
using Newtonsoft.Json.Linq;
Expand Down
31 changes: 16 additions & 15 deletions Keen.NetStandard.Test/DatasetTests_Integration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Keen.Core.Dataset;
using Keen.Core.Dataset;
using Keen.Core.Query;
using Moq;
using NUnit.Framework;
Expand All @@ -8,7 +8,6 @@
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;


Expand All @@ -25,7 +24,7 @@ public class DatasetTests_Integration : TestBase
[Test]
public void Results_Success()
{
var apiResponse = File.ReadAllText($"{this.GetLocalPath()}/ApiResponses/GetDatasetResults.json");
var apiResponse = File.ReadAllText($"{GetApiResponsesPath()}/GetDatasetResults.json");
IKeenHttpClientProvider httpClientProvider = null;

if (UseMocks)
Expand All @@ -43,7 +42,7 @@ public void Results_Success()
[Test]
public void Definition_Success()
{
var apiResponse = File.ReadAllText($"{this.GetLocalPath()}/ApiResponses/GetDatasetDefinition.json");
var apiResponse = File.ReadAllText($"{GetApiResponsesPath()}/GetDatasetDefinition.json");
IKeenHttpClientProvider httpClientProvider = null;

if (UseMocks)
Expand All @@ -60,7 +59,7 @@ public void Definition_Success()
[Test]
public void ListDefinitions_Success()
{
var apiResponse = File.ReadAllText($"{this.GetLocalPath()}/ApiResponses/ListDatasetDefinitions.json");
var apiResponse = File.ReadAllText($"{GetApiResponsesPath()}/ListDatasetDefinitions.json");
IKeenHttpClientProvider httpClientProvider = null;

if (UseMocks)
Expand All @@ -85,7 +84,7 @@ public void ListDefinitions_Success()
[Test]
public void ListAllDefinitions_Success()
{
var apiResponse = File.ReadAllText($"{this.GetLocalPath()}/ApiResponses/ListDatasetDefinitions.json");
var apiResponse = File.ReadAllText($"{GetApiResponsesPath()}/ListDatasetDefinitions.json");
IKeenHttpClientProvider httpClientProvider = null;

if (UseMocks)
Expand Down Expand Up @@ -123,7 +122,7 @@ public void Delete_Success()
[Test]
public void CreateDataset_Success()
{
var apiResponse = File.ReadAllText($"{this.GetLocalPath()}/ApiResponses/GetDatasetDefinition.json");
var apiResponse = File.ReadAllText($"{GetApiResponsesPath()}/GetDatasetDefinition.json");

IKeenHttpClientProvider httpClientProvider = null;

Expand Down Expand Up @@ -197,11 +196,11 @@ public void Results_Throws()

Assert.Throws<KeenException>(() => client.QueryDataset(_datasetName, _indexBy, _timeframe));

var brokenClient = new KeenClient(new ProjectSettingsProvider("5011efa95f546f2ce2000000",
null,
Environment.GetEnvironmentVariable("KEEN_WRITE_KEY") ?? "",
Environment.GetEnvironmentVariable("KEEN_READ_KEY") ?? "",
Environment.GetEnvironmentVariable("KEEN_SERVER_URL") ?? KeenConstants.ServerAddress + "/" + KeenConstants.ApiVersion + "/"),
var brokenClient = new KeenClient(new ProjectSettingsProvider("5011efa95f546f2ce2000000",
null,
Environment.GetEnvironmentVariable("KEEN_WRITE_KEY") ?? "",
Environment.GetEnvironmentVariable("KEEN_READ_KEY") ?? "",
Environment.GetEnvironmentVariable("KEEN_SERVER_URL") ?? KeenConstants.ServerAddress + "/" + KeenConstants.ApiVersion + "/"),
httpClientProvider);

Assert.Throws<KeenException>(() => brokenClient.QueryDataset(_datasetName, _indexBy, _timeframe));
Expand Down Expand Up @@ -305,10 +304,12 @@ public void CreateDataset_Throws()
Assert.Throws<KeenException>(() => brokenClient.CreateDataset(CreateDatasetDefinition()));
}

private string GetLocalPath()
private string GetApiResponsesPath()
{
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
return new Uri(path).LocalPath;
var localPath = AppDomain.CurrentDomain.BaseDirectory;
var apiResponsesPath = $"{localPath}/ApiResponses";

return apiResponsesPath;
}

private IKeenHttpClientProvider GetMockHttpClientProviderForGetAsync(string response, HttpStatusCode status = HttpStatusCode.OK)
Expand Down

0 comments on commit 81e3f4d

Please sign in to comment.