Skip to content

Commit

Permalink
Port Datasets to NetStandard:
Browse files Browse the repository at this point in the history
- At this point all the tests pass, at least.
  • Loading branch information
masojus committed Nov 4, 2017
1 parent 7379005 commit 74d10c3
Show file tree
Hide file tree
Showing 21 changed files with 1,588 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Keen.NET.Test/DataSetTests_Integration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ private void AssertDatasetIsPopulated(DatasetDefinition dataset)
foreach (var filter in dataset.Query.Filters)
{
AssertFilterIsPopulated(filter);
}
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion Keen.NET.Test/EventCacheTest.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Keen.Core;
using Keen.Core.EventCache;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;


namespace Keen.Net.Test
{
Expand Down
3 changes: 1 addition & 2 deletions Keen.Net/EventCacheMemory.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using Keen.Core;
using Keen.Core.EventCache;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Keen.Net
{
/// <summary>
Expand Down
23 changes: 23 additions & 0 deletions Keen.NetStandard.Test/ApiResponses/GetDatasetDefinition.json
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
}
52 changes: 52 additions & 0 deletions Keen.NetStandard.Test/ApiResponses/GetDatasetResults.json
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 Keen.NetStandard.Test/ApiResponses/ListDatasetDefinitions.json
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
}
160 changes: 160 additions & 0 deletions Keen.NetStandard.Test/DatasetTests.cs
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();
}
}
}
Loading

0 comments on commit 74d10c3

Please sign in to comment.