Skip to content

updated api class and integrations tests #283

New issue

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

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

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,50 @@ public async Task SendBulkImpressionsCountAsync(List<ImpressionsCountModel> impr
// Public for tests
public static string ConvertToJson(List<KeyImpression> impressions)
{
var impressionsPerFeature =
impressions
.GroupBy(item => item.Feature)
.Select(group => new { f = group.Key, i = group.Select(x => new { k = x.KeyName, t = x.Treatment, m = x.Time, c = x.ChangeNumber, r = x.Label, b = x.BucketingKey }) });
List<Dictionary<String, Object>> impressionsPerFeature = new List<Dictionary<String, Object>>();
List<Dictionary<String, Object>> currentFeatureImps = new List<Dictionary<String, Object>>();
String currentFeature = "";
Dictionary<String, Object> impRecord = new Dictionary<String, Object>();
Boolean first = true;
foreach (KeyImpression impression in impressions.OrderBy(i => i.Feature))
{
if (first)
{
currentFeature = impression.Feature;
first = false;
}

if (impression.Feature != currentFeature)
{
impressionsPerFeature.Add(new Dictionary<String, Object>
{
{ "f", currentFeature },
{ "i", currentFeatureImps }
});
currentFeatureImps = new List<Dictionary<String, Object>>();
}
impRecord = new Dictionary<String, Object>
{
{ "k", impression.KeyName },
{ "t", impression.Treatment },
{ "m", impression.Time },
{ "c", impression.ChangeNumber },
{ "r", impression.Label },
{ "b", impression.BucketingKey }
};
if (impression.Properties != null)
{
impRecord.Add("properties", impression.Properties);
}
currentFeatureImps.Add(impRecord);
currentFeature = impression.Feature;
}
impressionsPerFeature.Add(new Dictionary<String, Object>
{
{ "f", currentFeature },
{ "i", currentFeatureImps }
});

return JsonConvert.SerializeObject(impressionsPerFeature);
}

Expand Down
2 changes: 0 additions & 2 deletions tests/Splitio.Integration-tests/PollingClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,6 @@ public void GetTreatments_ValidateDedupeImpressions_Debug()
Assert.AreEqual(0, impressionCounts.Count);
}

// TODO: None mode is not supported yet.
[Ignore]
[TestMethod]
public void GetTreatments_WithImpressionsInNoneMode()
{
Expand Down
11 changes: 9 additions & 2 deletions tests/Splitio.Tests.Common/BaseAsyncClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,24 @@ public async Task GetTreatment_BetweenSemverMatcher()
var client = splitFactory.Client();

client.BlockUntilReady(10000);
EvaluationOptions evaluationOption = new EvaluationOptions(
new Dictionary<string, object> {
{ "prop1", "val1" }
}
);

// Act.
var result1 = await client.GetTreatmentAsync("mauro_test", "semver_between", new Dictionary<string, object> { { "version", "2.0.0" } });
var result1 = await client.GetTreatmentAsync("mauro_test", "semver_between", new Dictionary<string, object> { { "version", "2.0.0" } }, evaluationOptions: evaluationOption);
var result2 = await client.GetTreatmentAsync("mauro_test2", "semver_between", new Dictionary<string, object> { { "version", "3.0.0" } });
client.Destroy();

// Assert.
Assert.AreEqual("on", result1);
Assert.AreEqual("off", result2);

var impressionExpected1 = Helper.GetImpressionExpected("semver_between", "mauro_test");
var impExp = Helper.GetImpressionExpected("semver_between", "mauro_test");
KeyImpression impressionExpected1 = new KeyImpression(impExp.KeyName, impExp.Feature, impExp.Treatment, impExp.Time, impExp.ChangeNumber, impExp.Label, impExp.BucketingKey, impExp.ImpressionsDisabled, impExp.PreviousTime, impExp.Optimized);
impressionExpected1.Properties = "{\"prop1\":\"val1\"}";
var impressionExpected2 = Helper.GetImpressionExpected("semver_between", "mauro_test2");

//Validate impressions sent to the be.
Expand Down
54 changes: 40 additions & 14 deletions tests/Splitio.Tests.Common/BaseIntegrationTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using HandlebarsDotNet.Features;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Splitio.Domain;
using Splitio.Services.Client.Classes;
using Splitio.Services.Impressions.Interfaces;
using Splitio.Tests.Common.Resources;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;

namespace Splitio.Tests.Common
{
Expand Down Expand Up @@ -361,7 +363,9 @@ public void GetTreatment_WithtBUR_WithMultipleCalls_ReturnsTreatments()
Assert.AreEqual("on", result3);
Assert.AreEqual("off", result4);

var impressionExpected1 = GetImpressionExpected("FACUNDO_TEST", "nico_test");
var impExp = GetImpressionExpected("FACUNDO_TEST", "nico_test");
KeyImpression impressionExpected1 = new KeyImpression(impExp.KeyName, impExp.Feature, impExp.Treatment, impExp.Time, impExp.ChangeNumber, impExp.Label, impExp.BucketingKey, impExp.ImpressionsDisabled, impExp.PreviousTime, impExp.Optimized);
impressionExpected1.Properties = "{\"prop1\":\"val1\"}";
var impressionExpected2 = GetImpressionExpected("FACUNDO_TEST", "mauro_test");
var impressionExpected3 = GetImpressionExpected("Test_Save_1", "1");
var impressionExpected4 = GetImpressionExpected("Test_Save_1", "24");
Expand Down Expand Up @@ -516,7 +520,9 @@ public void GetTreatmentWithConfig_WithtBUR_WithMultipleCalls_ReturnsTreatments(
Assert.AreEqual("{\"version\":\"v2\"}", result3.Config);
Assert.AreEqual("{\"version\":\"v1\"}", result4.Config);

var impExpected1 = GetImpressionExpected("FACUNDO_TEST", "nico_test");
var impExp = GetImpressionExpected("FACUNDO_TEST", "nico_test");
KeyImpression impExpected1 = new KeyImpression(impExp.KeyName, impExp.Feature, impExp.Treatment, impExp.Time, impExp.ChangeNumber, impExp.Label, impExp.BucketingKey, impExp.ImpressionsDisabled, impExp.PreviousTime, impExp.Optimized);
impExpected1.Properties = "{\"prop1\":\"val1\"}";
var impExpected2 = GetImpressionExpected("FACUNDO_TEST", "mauro_test");
var impExpected3 = GetImpressionExpected("MAURO_TEST", "mauro");
var impExpected4 = GetImpressionExpected("MAURO_TEST", "test");
Expand Down Expand Up @@ -635,9 +641,15 @@ public void GetTreatments_WithtBUR_ReturnsTreatments()
Assert.AreEqual("off", result["MAURO_TEST"]);
Assert.AreEqual("off", result["Test_Save_1"]);

var impExpected1 = GetImpressionExpected("FACUNDO_TEST", "nico_test");
var impExpected2 = GetImpressionExpected("MAURO_TEST", "nico_test");
var impExpected3 = GetImpressionExpected("Test_Save_1", "nico_test");
var impExp = GetImpressionExpected("FACUNDO_TEST", "nico_test");
KeyImpression impExpected1 = new KeyImpression(impExp.KeyName, impExp.Feature, impExp.Treatment, impExp.Time, impExp.ChangeNumber, impExp.Label, impExp.BucketingKey, impExp.ImpressionsDisabled, impExp.PreviousTime, impExp.Optimized);
impExpected1.Properties = "{\"prop1\":\"val1\"}";
impExp = GetImpressionExpected("MAURO_TEST", "nico_test");
KeyImpression impExpected2 = new KeyImpression(impExp.KeyName, impExp.Feature, impExp.Treatment, impExp.Time, impExp.ChangeNumber, impExp.Label, impExp.BucketingKey, impExp.ImpressionsDisabled, impExp.PreviousTime, impExp.Optimized);
impExpected2.Properties = "{\"prop1\":\"val1\"}";
impExp = GetImpressionExpected("Test_Save_1", "nico_test");
KeyImpression impExpected3 = new KeyImpression(impExp.KeyName, impExp.Feature, impExp.Treatment, impExp.Time, impExp.ChangeNumber, impExp.Label, impExp.BucketingKey, impExp.ImpressionsDisabled, impExp.PreviousTime, impExp.Optimized);
impExpected3.Properties = "{\"prop1\":\"val1\"}";

//Validate impressions sent to the be.
AssertSentImpressions(3, impExpected1, impExpected2, impExpected3);
Expand Down Expand Up @@ -761,9 +773,15 @@ public void GetTreatmentsWithConfig_WithtBUR_ReturnsTreatments()
Assert.AreEqual("{\"version\":\"v1\"}", result["MAURO_TEST"].Config);
Assert.IsNull(result["Test_Save_1"].Config);

var impExpected1 = GetImpressionExpected("FACUNDO_TEST", "nico_test");
var impExpected2 = GetImpressionExpected("MAURO_TEST", "nico_test");
var impExpected3 = GetImpressionExpected("Test_Save_1", "nico_test");
var impExp = GetImpressionExpected("FACUNDO_TEST", "nico_test");
KeyImpression impExpected1 = new KeyImpression(impExp.KeyName, impExp.Feature, impExp.Treatment, impExp.Time, impExp.ChangeNumber, impExp.Label, impExp.BucketingKey, impExp.ImpressionsDisabled, impExp.PreviousTime, impExp.Optimized);
impExpected1.Properties = "{\"prop1\":\"val1\"}";
impExp = GetImpressionExpected("MAURO_TEST", "nico_test");
KeyImpression impExpected2 = new KeyImpression(impExp.KeyName, impExp.Feature, impExp.Treatment, impExp.Time, impExp.ChangeNumber, impExp.Label, impExp.BucketingKey, impExp.ImpressionsDisabled, impExp.PreviousTime, impExp.Optimized);
impExpected2.Properties = "{\"prop1\":\"val1\"}";
impExp = GetImpressionExpected("Test_Save_1", "nico_test");
KeyImpression impExpected3 = new KeyImpression(impExp.KeyName, impExp.Feature, impExp.Treatment, impExp.Time, impExp.ChangeNumber, impExp.Label, impExp.BucketingKey, impExp.ImpressionsDisabled, impExp.PreviousTime, impExp.Optimized);
impExpected3.Properties = "{\"prop1\":\"val1\"}";

//Validate impressions sent to the be.
AssertSentImpressions(3, impExpected1, impExpected2, impExpected3);
Expand Down Expand Up @@ -902,8 +920,10 @@ public void GetTreatmentsWithConfigByFlagSets_WithoutFlagSetsInConfig()
Assert.AreEqual("{\"color\":\"green\"}", treatment.Value.Config);

//Validate impressions sent to the be.
var impressionExpected = new KeyImpression("nico_test", "FACUNDO_TEST", "on", 0, 1506703262916, "whitelisted", null, false, null, false);

var impExp = new KeyImpression("nico_test", "FACUNDO_TEST", "on", 0, 1506703262916, "whitelisted", null, false, null, false);
KeyImpression impressionExpected = new KeyImpression(impExp.KeyName, impExp.Feature, impExp.Treatment, impExp.Time, impExp.ChangeNumber, impExp.Label, impExp.BucketingKey, impExp.ImpressionsDisabled, impExp.PreviousTime, impExp.Optimized);
impressionExpected.Properties = "{\"prop1\":\"val1\"}";

AssertSentImpressions(1, impressionExpected);
AssertImpressionListener(1, impressionListener);
Helper.AssertImpression(impressionListener.Get("FACUNDO_TEST", "nico_test"), impressionExpected);
Expand Down Expand Up @@ -964,7 +984,9 @@ public void GetTreatmentsByFlagSets_WithoutFlagSetsInConfig()
Assert.AreEqual("FACUNDO_TEST", treatment.Key);
Assert.AreEqual("on", treatment.Value);

var impExpected1 = GetImpressionExpected("FACUNDO_TEST", "nico_test");
var impExp = GetImpressionExpected("FACUNDO_TEST", "nico_test");
KeyImpression impExpected1 = new KeyImpression(impExp.KeyName, impExp.Feature, impExp.Treatment, impExp.Time, impExp.ChangeNumber, impExp.Label, impExp.BucketingKey, impExp.ImpressionsDisabled, impExp.PreviousTime, impExp.Optimized);
impExpected1.Properties = "{\"prop1\":\"val1\"}";

//Validate impressions sent to the be.
AssertSentImpressions(1, impExpected1);
Expand Down Expand Up @@ -1028,7 +1050,9 @@ public void GetTreatmentsWithConfigByFlagSet_WithoutFlagSetsInConfig()
Assert.AreEqual("on", treatment.Value.Treatment);
Assert.AreEqual("{\"color\":\"green\"}", treatment.Value.Config);

var impExpected1 = GetImpressionExpected("FACUNDO_TEST", "nico_test");
var impExp = GetImpressionExpected("FACUNDO_TEST", "nico_test");
KeyImpression impExpected1 = new KeyImpression(impExp.KeyName, impExp.Feature, impExp.Treatment, impExp.Time, impExp.ChangeNumber, impExp.Label, impExp.BucketingKey, impExp.ImpressionsDisabled, impExp.PreviousTime, impExp.Optimized);
impExpected1.Properties = "{\"prop1\":\"val1\"}";

//Validate impressions sent to the be.
AssertSentImpressions(1, impExpected1);
Expand Down Expand Up @@ -1091,7 +1115,9 @@ public void GetTreatmentsByFlagSet_WithoutFlagSetsInConfig()
Assert.AreEqual("FACUNDO_TEST", treatment.Key);
Assert.AreEqual("on", treatment.Value);

var impExpected1 = GetImpressionExpected("FACUNDO_TEST", "nico_test");
var impExp = GetImpressionExpected("FACUNDO_TEST", "nico_test");
KeyImpression impExpected1 = new KeyImpression(impExp.KeyName, impExp.Feature, impExp.Treatment, impExp.Time, impExp.ChangeNumber, impExp.Label, impExp.BucketingKey, impExp.ImpressionsDisabled, impExp.PreviousTime, impExp.Optimized);
impExpected1.Properties = "{\"prop1\":\"val1\"}";

//Validate impressions sent to the be.
AssertSentImpressions(1, impExpected1);
Expand Down
1 change: 1 addition & 0 deletions tests/Splitio.Tests.Common/Resources/InMemoryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public static void AssertSentImpressions(int sentImpressionsCount, HttpClientMoc
.Where(si => expectedImp.KeyName == si.K)
.Where(si => expectedImp.Label == si.R)
.Where(si => expectedImp.Treatment == si.T)
.Where(si => expectedImp.Properties == si.PROPERTIES)
.Any());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class ImpressionData
public string B { get; set; }
public string T { get; set; }
public string R { get; set; }
public string PROPERTIES { get; set; }
public long? C { get; set; }
public long? M { get; set; }
}
Expand Down