Skip to content
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
3 changes: 3 additions & 0 deletions OptimizelySDK.Net35/OptimizelySDK.Net35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@
</Compile>
<Compile Include="..\OptimizelySDK\Utils\Validator.cs">
<Link>Utils\Validator.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Utils\ControlAttributes.cs">
<Link>Utils\ControlAttributes.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="..\OptimizelySDK\Bucketing\Bucketer.cs">
Expand Down
3 changes: 3 additions & 0 deletions OptimizelySDK.Net40/OptimizelySDK.Net40.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@
</Compile>
<Compile Include="..\OptimizelySDK\Utils\Validator.cs">
<Link>Utils\Validator.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Utils\ControlAttributes.cs">
<Link>Utils\ControlAttributes.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="..\OptimizelySDK\Bucketing\Bucketer.cs">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<Compile Include="..\OptimizelySDK\Utils\Validator.cs" />
<Compile Include="..\OptimizelySDK\Utils\ConfigParser.cs" />
<Compile Include="..\OptimizelySDK\Utils\Schema.cs" />
<Compile Include="..\OptimizelySDK\Utils\ControlAttributes.cs" />

<Compile Include="..\OptimizelySDK\Bucketing\Bucketer.cs" />
<Compile Include="..\OptimizelySDK\Bucketing\Decision.cs" />
Expand Down
5 changes: 3 additions & 2 deletions OptimizelySDK.Tests/DecisionServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using OptimizelySDK.Entity;
using NUnit.Framework;
using OptimizelySDK.Bucketing;
using OptimizelySDK.Utils;

namespace OptimizelySDK.Tests
{
Expand Down Expand Up @@ -388,13 +389,13 @@ public void TestGetVariationWithBucketingId()
{"device_type", "iPhone"},
{"company", "Optimizely"},
{"location", "San Francisco"},
{DecisionService.RESERVED_ATTRIBUTE_KEY_BUCKETING_ID, testBucketingIdVariation}
{ControlAttributes.BUCKETING_ID_ATTRIBUTE, testBucketingIdVariation}
};

var invalidUserAttributesWithBucketingId = new UserAttributes
{
{"company", "Optimizely"},
{DecisionService.RESERVED_ATTRIBUTE_KEY_BUCKETING_ID, testBucketingIdControl}
{ControlAttributes.BUCKETING_ID_ATTRIBUTE, testBucketingIdControl}
};

var optlyObject = new Optimizely(TestData.Datafile, new ValidEventDispatcher(), LoggerMock.Object);
Expand Down
512 changes: 490 additions & 22 deletions OptimizelySDK.Tests/EventTests/EventBuilderTest.cs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions OptimizelySDK.Tests/OptimizelyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using OptimizelySDK.Bucketing;
using OptimizelySDK.Notifications;
using OptimizelySDK.Tests.NotificationTests;
using OptimizelySDK.Utils;

namespace OptimizelySDK.Tests
{
Expand Down Expand Up @@ -516,8 +517,7 @@ public void TestTrackInvalidAttributes()

Optimizely.Track("purchase", TestUserId, attributes);

//LoggerMock.Verify(l => l.Log(LogLevel.ERROR, "Provided attributes are in an invalid format."), Times.Once);
ErrorHandlerMock.Verify(e => e.HandleError(It.IsAny<InvalidAttributeException>()), Times.Once);
LoggerMock.Verify(l => l.Log(LogLevel.ERROR, @"Attribute key ""abc"" is not in datafile."), Times.Once);
}

[Test]
Expand Down Expand Up @@ -1112,7 +1112,7 @@ public void TestGetVariationBucketingIdAttribute()
{ "device_type", "iPhone" },
{ "company", "Optimizely" },
{ "location", "San Francisco" },
{ DecisionService.RESERVED_ATTRIBUTE_KEY_BUCKETING_ID, testBucketingIdVariation }
{ ControlAttributes.BUCKETING_ID_ATTRIBUTE, testBucketingIdVariation }
};

// confirm that a valid variation is bucketed without the bucketing ID
Expand Down
59 changes: 56 additions & 3 deletions OptimizelySDK.Tests/ProjectConfigTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017, Optimizely
* Copyright 2017-2018, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,6 +22,9 @@
using OptimizelySDK.Exceptions;
using NUnit.Framework;
using OptimizelySDK.Entity;
using Newtonsoft.Json;
using OptimizelySDK.Event.Builder;
using OptimizelySDK.Utils;

namespace OptimizelySDK.Tests
{
Expand Down Expand Up @@ -51,14 +54,14 @@ public static Dictionary<string, object> CreateDictionary(string name, object en
public void TestInit()
{
// Check Version
Assert.AreEqual(4, Config.Version);
Assert.AreEqual("4", Config.Version);

// Check Account ID
Assert.AreEqual("1592310167", Config.AccountId);
// Check Project ID
Assert.AreEqual("7720880029", Config.ProjectId);
// Check Revision
Assert.AreEqual(15, Config.Revision);
Assert.AreEqual("15", Config.Revision);

// Check Group ID Map
var expectedGroupId = CreateDictionary("7722400015", Config.GetGroup("7722400015"));
Expand Down Expand Up @@ -810,5 +813,55 @@ public void TestVariationFeatureEnabledProperty()
var variation = Config.GetVariationFromKey("test_experiment", "control");
Assert.IsFalse(variation.IsFeatureEnabled);
}

[Test]
public void TestBotFilteringValues()
{
// Verify that bot filtering value is true as defined in Config data.
Assert.True(Config.BotFiltering.GetValueOrDefault());

// Remove botFilering node and verify returned value in null.
JObject projConfig = JObject.Parse(TestData.Datafile);
if (projConfig.TryGetValue("botFiltering", out JToken token))
{
projConfig.Property("botFiltering").Remove();
var configWithoutBotFilter = ProjectConfig.Create(JsonConvert.SerializeObject(projConfig),
LoggerMock.Object, ErrorHandlerMock.Object);

// Verify that bot filtering is null when not defined in datafile.
Assert.Null(configWithoutBotFilter.BotFiltering);
}
}

[Test]
public void TestGetAttributeIdWithReservedPrefix()
{
// Verify that attribute key is returned for reserved attribute key.
Assert.AreEqual(Config.GetAttributeId(ControlAttributes.USER_AGENT_ATTRIBUTE), ControlAttributes.USER_AGENT_ATTRIBUTE);

// Verify that attribute Id is returned for attribute key with reserved prefix that does not exist in datafile.
Assert.AreEqual(Config.GetAttributeId("$opt_reserved_prefix_attribute"), "$opt_reserved_prefix_attribute");

// Create config file copy with additional resered prefix attribute.
string reservedPrefixAttrKey = "$opt_user_defined_attribute";
JObject projConfig = JObject.Parse(TestData.Datafile);
var attributes = (JArray)projConfig["attributes"];

var reservedAttr = new Entity.Attribute { Id = "7723348204", Key = reservedPrefixAttrKey };
attributes.Add((JObject)JToken.FromObject(reservedAttr));

// Verify that attribute Id is returned and warning is logged for attribute key with reserved prefix that exists in datafile.
var reservedAttrConfig = ProjectConfig.Create(JsonConvert.SerializeObject(projConfig), LoggerMock.Object, ErrorHandlerMock.Object);
Assert.AreEqual(reservedAttrConfig.GetAttributeId(reservedPrefixAttrKey), reservedAttrConfig.GetAttribute(reservedPrefixAttrKey).Id);
LoggerMock.Verify(l => l.Log(LogLevel.WARN, $@"Attribute {reservedPrefixAttrKey} unexpectedly has reserved prefix {ProjectConfig.RESERVED_ATTRIBUTE_PREFIX}; using attribute ID instead of reserved attribute name."));
}

[Test]
public void TestGetAttributeIdWithInvalidAttributeKey()
{
// Verify that null is returned when provided attribute key is invalid.
Assert.Null(Config.GetAttributeId("invalid_attribute"));
LoggerMock.Verify(l => l.Log(LogLevel.ERROR, @"Attribute key ""invalid_attribute"" is not in datafile."));
}
}
}
Loading