-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- At this point all the tests pass, at least.
- Loading branch information
Showing
21 changed files
with
1,588 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
Keen.NetStandard.Test/ApiResponses/GetDatasetDefinition.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"dataset_name": "count-purchases-gte-100-by-country-daily", | ||
"display_name": "Count Daily Product Purchases Over $100 by Country", | ||
"query": { | ||
"project_id": "5011efa95f546f2ce2000000", | ||
"analysis_type": "count", | ||
"event_collection": "purchases", | ||
"filters": [ | ||
{ | ||
"property_name": "price", | ||
"operator": "gte", | ||
"property_value": 100 | ||
} | ||
], | ||
"timeframe": "this_500_days", | ||
"interval": "daily", | ||
"group_by": [ "ip_geo_info.country" ] | ||
}, | ||
"index_by": [ "product.id" ], | ||
"last_scheduled_date": "2016-11-04T18:52:36.323Z", | ||
"latest_subtimeframe_available": "2016-11-05T00:00:00.000Z", | ||
"milliseconds_behind": 3600000 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"result": [ | ||
{ | ||
"timeframe": { | ||
"start": "2016-11-02T00:00:00.000Z", | ||
"end": "2016-11-03T00:00:00.000Z" | ||
}, | ||
"value": [ | ||
{ | ||
"item.name": "Golden Widget", | ||
"result": 0 | ||
}, | ||
{ | ||
"item.name": "Silver Widget", | ||
"result": 18 | ||
}, | ||
{ | ||
"item.name": "Bronze Widget", | ||
"result": 1 | ||
}, | ||
{ | ||
"item.name": "Platinum Widget", | ||
"result": 9 | ||
} | ||
] | ||
}, | ||
{ | ||
"timeframe": { | ||
"start": "2016-11-03T00:00:00.000Z", | ||
"end": "2016-11-04T00:00:00.000Z" | ||
}, | ||
"value": [ | ||
{ | ||
"item.name": "Golden Widget", | ||
"result": 1 | ||
}, | ||
{ | ||
"item.name": "Silver Widget", | ||
"result": 13 | ||
}, | ||
{ | ||
"item.name": "Bronze Widget", | ||
"result": 0 | ||
}, | ||
{ | ||
"item.name": "Platinum Widget", | ||
"result": 3 | ||
} | ||
] | ||
} | ||
] | ||
} |
60 changes: 60 additions & 0 deletions
60
Keen.NetStandard.Test/ApiResponses/ListDatasetDefinitions.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"datasets": [ | ||
{ | ||
"project_id": "PROJECT_ID", | ||
"organization_id": "ORGANIZATION_ID", | ||
"dataset_name": "DATASET_NAME_1", | ||
"display_name": "a first dataset wee", | ||
"query": { | ||
"project_id": "PROJECT_ID", | ||
"analysis_type": "count", | ||
"event_collection": "best collection", | ||
"filters": [ | ||
{ | ||
"property_name": "request.foo", | ||
"operator": "lt", | ||
"property_value": 300 | ||
} | ||
], | ||
"timeframe": "this_500_hours", | ||
"timezone": "US/Pacific", | ||
"interval": "hourly", | ||
"group_by": [ | ||
"exception.name" | ||
] | ||
}, | ||
"index_by": [ | ||
"project.id" | ||
], | ||
"last_scheduled_date": "2016-11-04T18:03:38.430Z", | ||
"latest_subtimeframe_available": "2016-11-04T19:00:00.000Z", | ||
"milliseconds_behind": 3600000 | ||
}, | ||
{ | ||
"project_id": "PROJECT_ID", | ||
"organization_id": "ORGANIZATION_ID", | ||
"dataset_name": "DATASET_NAME_10", | ||
"display_name": "tenth dataset wee", | ||
"query": { | ||
"project_id": "PROJECT_ID", | ||
"analysis_type": "count", | ||
"event_collection": "tenth best collection", | ||
"filters": [], | ||
"timeframe": "this_500_days", | ||
"timezone": "UTC", | ||
"interval": "daily", | ||
"group_by": [ | ||
"analysis_type" | ||
] | ||
}, | ||
"index_by": [ | ||
"project.organization.id" | ||
], | ||
"last_scheduled_date": "2016-11-04T19:28:36.639Z", | ||
"latest_subtimeframe_available": "2016-11-05T00:00:00.000Z", | ||
"milliseconds_behind": 3600000 | ||
} | ||
], | ||
"next_page_url": "https://api.keen.io/3.0/projects/PROJECT_ID/datasets?limit=LIMIT&after_name=DATASET_NAME_10", | ||
"count": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
using Keen.Core.Dataset; | ||
using Keen.Core.Query; | ||
using Moq; | ||
using Newtonsoft.Json.Linq; | ||
using NUnit.Framework; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
|
||
namespace Keen.Core.Test | ||
{ | ||
[TestFixture] | ||
public class DatasetTests : TestBase | ||
{ | ||
private const string _datasetName = "video-view"; | ||
private const string _indexBy = "12"; | ||
private const int _listDatasetLimit = 1; | ||
|
||
|
||
[Test] | ||
public void GetDatasetResults_Success() | ||
{ | ||
var timeframe = QueryRelativeTimeframe.ThisNMinutes(12); | ||
var result = new JObject(); | ||
var client = new KeenClient(SettingsEnv); | ||
|
||
Mock<IDataset> datasetMock = null; | ||
|
||
if (UseMocks) | ||
{ | ||
datasetMock = new Mock<IDataset>(); | ||
datasetMock.Setup(m => m.GetResultsAsync( | ||
It.Is<string>(n => n == _datasetName), | ||
It.Is<string>(i => i == _indexBy), | ||
It.Is<string>(t => t == timeframe.ToString()))) | ||
.ReturnsAsync(result); | ||
|
||
client.Datasets = datasetMock.Object; | ||
} | ||
|
||
var dataset = client.QueryDataset(_datasetName, _indexBy, timeframe.ToString()); | ||
Assert.IsNotNull(dataset); | ||
|
||
datasetMock?.VerifyAll(); | ||
} | ||
|
||
[Test] | ||
public void GetDatasetDefinition_Success() | ||
{ | ||
var result = new DatasetDefinition(); | ||
var client = new KeenClient(SettingsEnv); | ||
Mock<IDataset> datasetMock = null; | ||
|
||
if (UseMocks) | ||
{ | ||
datasetMock = new Mock<IDataset>(); | ||
datasetMock.Setup(m => m.GetDefinitionAsync( | ||
It.Is<string>(n => n == _datasetName))) | ||
.ReturnsAsync(result); | ||
|
||
client.Datasets = datasetMock.Object; | ||
} | ||
|
||
var datasetDefinition = client.GetDatasetDefinition(_datasetName); | ||
Assert.IsNotNull(datasetDefinition); | ||
|
||
datasetMock?.VerifyAll(); | ||
} | ||
|
||
[Test] | ||
public void ListDatasetDefinitions_Success() | ||
{ | ||
var result = new DatasetDefinitionCollection(); | ||
var client = new KeenClient(SettingsEnv); | ||
Mock<IDataset> datasetMock = null; | ||
|
||
if (UseMocks) | ||
{ | ||
datasetMock = new Mock<IDataset>(); | ||
datasetMock.Setup(m => m.ListDefinitionsAsync( | ||
It.Is<int>(n => n == _listDatasetLimit), | ||
It.Is<string>(n => n == _datasetName))) | ||
.ReturnsAsync(result); | ||
|
||
client.Datasets = datasetMock.Object; | ||
} | ||
|
||
var datasetDefinitionCollection = client.ListDatasetDefinitions(_listDatasetLimit, _datasetName); | ||
Assert.IsNotNull(datasetDefinitionCollection); | ||
|
||
datasetMock?.VerifyAll(); | ||
} | ||
|
||
[Test] | ||
public void ListDatasetAllDefinitions_Success() | ||
{ | ||
IEnumerable<DatasetDefinition> result = new List<DatasetDefinition>(); | ||
var client = new KeenClient(SettingsEnv); | ||
Mock<IDataset> datasetMock = null; | ||
|
||
if (UseMocks) | ||
{ | ||
datasetMock = new Mock<IDataset>(); | ||
datasetMock.Setup(m => m.ListAllDefinitionsAsync()) | ||
.ReturnsAsync(result); | ||
|
||
client.Datasets = datasetMock.Object; | ||
} | ||
|
||
var datasetDefinitions = client.ListAllDatasetDefinitions(); | ||
Assert.IsNotNull(datasetDefinitions); | ||
|
||
datasetMock?.VerifyAll(); | ||
} | ||
|
||
[Test] | ||
public void CreateDataset_Success() | ||
{ | ||
var result = new DatasetDefinition(); | ||
var client = new KeenClient(SettingsEnv); | ||
Mock<IDataset> datasetMock = null; | ||
|
||
if (UseMocks) | ||
{ | ||
datasetMock = new Mock<IDataset>(); | ||
datasetMock.Setup(m => m.CreateDatasetAsync( | ||
It.Is<DatasetDefinition>(n => n != null))) | ||
.ReturnsAsync(result); | ||
|
||
client.Datasets = datasetMock.Object; | ||
} | ||
|
||
var datasetDefinition = client.CreateDataset(new DatasetDefinition()); | ||
Assert.IsNotNull(datasetDefinition); | ||
|
||
datasetMock?.VerifyAll(); | ||
} | ||
|
||
[Test] | ||
public void DeleteDataset_Success() | ||
{ | ||
var client = new KeenClient(SettingsEnv); | ||
Mock<IDataset> datasetMock = null; | ||
|
||
if (UseMocks) | ||
{ | ||
datasetMock = new Mock<IDataset>(); | ||
datasetMock.Setup(m => m.DeleteDatasetAsync( | ||
It.Is<string>(n => n == _datasetName))) | ||
.Returns(Task.Delay(0)); | ||
|
||
client.Datasets = datasetMock.Object; | ||
} | ||
|
||
client.DeleteDataset(_datasetName); | ||
|
||
datasetMock?.VerifyAll(); | ||
} | ||
} | ||
} |
Oops, something went wrong.