Skip to content

Commit c0a936a

Browse files
mfahadahmedkellyroach-optimizely
authored andcommitted
Removed Version-3 Datafile from the project. (#57)
1 parent 3402c4d commit c0a936a

File tree

8 files changed

+226
-479
lines changed

8 files changed

+226
-479
lines changed

OptimizelySDK.Tests/DecisionServiceTest.cs

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ public class DecisionServiceTest
3535
private Mock<UserProfileService> UserProfileServiceMock;
3636
private Mock<Bucketer> BucketerMock;
3737
private Mock<DecisionService> DecisionServiceMock;
38-
39-
private ProjectConfig NoAudienceProjectConfig;
40-
private ProjectConfig ValidProjectConfig;
38+
4139
private ProjectConfig ProjectConfig;
4240
private Experiment WhitelistedExperiment;
4341
private Variation WhitelistedVariation;
@@ -54,13 +52,11 @@ public void SetUp()
5452
UserProfileServiceMock = new Mock<UserProfileService>();
5553
BucketerMock = new Mock<Bucketer>(LoggerMock.Object);
5654

57-
ValidProjectConfig = ProjectConfig.Create(TestData.ValidDataFileV3, LoggerMock.Object, ErrorHandlerMock.Object);
58-
NoAudienceProjectConfig = ProjectConfig.Create(TestData.NoAudienceProjectConfigV3, LoggerMock.Object, ErrorHandlerMock.Object);
59-
WhitelistedExperiment = ValidProjectConfig.ExperimentIdMap["223"];
60-
WhitelistedVariation = WhitelistedExperiment.VariationKeyToVariationMap["vtag1"];
6155
ProjectConfig = ProjectConfig.Create(TestData.Datafile, LoggerMock.Object, ErrorHandlerMock.Object);
56+
WhitelistedExperiment = ProjectConfig.ExperimentIdMap["224"];
57+
WhitelistedVariation = WhitelistedExperiment.VariationKeyToVariationMap["vtag5"];
58+
6259
DecisionService = new DecisionService(new Bucketer(LoggerMock.Object), ErrorHandlerMock.Object, ProjectConfig, null, LoggerMock.Object);
63-
6460
DecisionServiceMock = new Mock<DecisionService>(BucketerMock.Object, ErrorHandlerMock.Object, ProjectConfig, null, LoggerMock.Object) { CallBase = true };
6561

6662
VariationWithKeyControl = ProjectConfig.GetVariationFromKey("test_experiment", "control");
@@ -70,17 +66,16 @@ public void SetUp()
7066
[Test]
7167
public void TestGetVariationForcedVariationPrecedesAudienceEval()
7268
{
73-
74-
DecisionService decisionService = new DecisionService(BucketerMock.Object, ErrorHandlerMock.Object, ValidProjectConfig, null, LoggerMock.Object);
75-
Experiment experiment = ValidProjectConfig.Experiments[0];
69+
DecisionService decisionService = new DecisionService(BucketerMock.Object, ErrorHandlerMock.Object, ProjectConfig, null, LoggerMock.Object);
70+
Experiment experiment = ProjectConfig.Experiments[8];
7671
Variation expectedVariation = experiment.Variations[0];
7772

7873
// user excluded without audiences and whitelisting
7974
Assert.IsNull(decisionService.GetVariation(experiment, GenericUserId, new UserAttributes()));
8075

8176
var actualVariation = decisionService.GetVariation(experiment, WhitelistedUserId, new UserAttributes());
8277

83-
LoggerMock.Verify(l => l.Log(LogLevel.INFO, string.Format("User \"{0}\" is forced in variation \"vtag1\".", WhitelistedUserId)), Times.Once);
78+
LoggerMock.Verify(l => l.Log(LogLevel.INFO, string.Format("User \"{0}\" is forced in variation \"vtag5\".", WhitelistedUserId)), Times.Once);
8479
// no attributes provided for a experiment that has an audience
8580
Assert.IsTrue(TestData.CompareObjects(actualVariation, expectedVariation));
8681
BucketerMock.Verify(_ => _.Bucket(It.IsAny<ProjectConfig>(), It.IsAny<Experiment>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
@@ -89,7 +84,7 @@ public void TestGetVariationForcedVariationPrecedesAudienceEval()
8984
[Test]
9085
public void TestGetVariationEvaluatesUserProfileBeforeAudienceTargeting()
9186
{
92-
Experiment experiment = ValidProjectConfig.Experiments[0];
87+
Experiment experiment = ProjectConfig.Experiments[8];
9388
Variation variation = experiment.Variations[0];
9489

9590
Decision decision = new Decision(variation.Id);
@@ -100,7 +95,7 @@ public void TestGetVariationEvaluatesUserProfileBeforeAudienceTargeting()
10095

10196
UserProfileServiceMock.Setup(up => up.Lookup(WhitelistedUserId)).Returns(userProfile.ToMap());
10297

103-
DecisionService decisionService = new DecisionService(BucketerMock.Object, ErrorHandlerMock.Object, ValidProjectConfig, UserProfileServiceMock.Object, LoggerMock.Object);
98+
DecisionService decisionService = new DecisionService(BucketerMock.Object, ErrorHandlerMock.Object, ProjectConfig, UserProfileServiceMock.Object, LoggerMock.Object);
10499

105100
decisionService.GetVariation(experiment, GenericUserId, new UserAttributes());
106101

@@ -116,7 +111,7 @@ public void TestGetVariationEvaluatesUserProfileBeforeAudienceTargeting()
116111
[Test]
117112
public void TestGetForcedVariationReturnsForcedVariation()
118113
{
119-
DecisionService decisionService = new DecisionService(BucketerMock.Object, ErrorHandlerMock.Object, ValidProjectConfig, null, LoggerMock.Object);
114+
DecisionService decisionService = new DecisionService(BucketerMock.Object, ErrorHandlerMock.Object, ProjectConfig, null, LoggerMock.Object);
120115

121116
Assert.IsTrue(TestData.CompareObjects(WhitelistedVariation, decisionService.GetWhitelistedVariation(WhitelistedExperiment, WhitelistedUserId)));
122117
LoggerMock.Verify(l => l.Log(LogLevel.INFO, string.Format("User \"{0}\" is forced in variation \"{1}\".",
@@ -131,7 +126,7 @@ public void TestGetForcedVariationWithInvalidVariation()
131126
string userId = "testUser1";
132127
string invalidVariationKey = "invalidVarKey";
133128

134-
DecisionService decisionService = new DecisionService(BucketerMock.Object, ErrorHandlerMock.Object, ValidProjectConfig, null, LoggerMock.Object);
129+
DecisionService decisionService = new DecisionService(BucketerMock.Object, ErrorHandlerMock.Object, ProjectConfig, null, LoggerMock.Object);
135130

136131
var variations = new Variation[]
137132
{
@@ -171,15 +166,15 @@ public void TestGetForcedVariationWithInvalidVariation()
171166
public void TestGetForcedVariationReturnsNullWhenUserIsNotWhitelisted()
172167
{
173168
Bucketer bucketer = new Bucketer(LoggerMock.Object);
174-
DecisionService decisionService = new DecisionService(bucketer, ErrorHandlerMock.Object, ValidProjectConfig, null, LoggerMock.Object);
169+
DecisionService decisionService = new DecisionService(bucketer, ErrorHandlerMock.Object, ProjectConfig, null, LoggerMock.Object);
175170

176171
Assert.IsNull(decisionService.GetWhitelistedVariation(WhitelistedExperiment, GenericUserId));
177172
}
178173

179174
[Test]
180175
public void TestBucketReturnsVariationStoredInUserProfile()
181176
{
182-
Experiment experiment = NoAudienceProjectConfig.Experiments[0];
177+
Experiment experiment = ProjectConfig.Experiments[6];
183178
Variation variation = experiment.Variations[0];
184179
Decision decision = new Decision(variation.Id);
185180

@@ -191,7 +186,7 @@ public void TestBucketReturnsVariationStoredInUserProfile()
191186
UserProfileServiceMock.Setup(_ => _.Lookup(UserProfileId)).Returns(userProfile.ToMap());
192187

193188

194-
DecisionService decisionService = new DecisionService(BucketerMock.Object, ErrorHandlerMock.Object, NoAudienceProjectConfig, UserProfileServiceMock.Object, LoggerMock.Object);
189+
DecisionService decisionService = new DecisionService(BucketerMock.Object, ErrorHandlerMock.Object, ProjectConfig, UserProfileServiceMock.Object, LoggerMock.Object);
195190

196191
Assert.IsTrue(TestData.CompareObjects(variation, decisionService.GetVariation(experiment, UserProfileId, new UserAttributes())));
197192

@@ -205,7 +200,7 @@ public void TestBucketReturnsVariationStoredInUserProfile()
205200
[Test]
206201
public void TestGetStoredVariationLogsWhenLookupReturnsNull()
207202
{
208-
Experiment experiment = NoAudienceProjectConfig.Experiments[0];
203+
Experiment experiment = ProjectConfig.Experiments[6];
209204

210205
UserProfileService userProfileService = UserProfileServiceMock.Object;
211206
UserProfile userProfile = new UserProfile(UserProfileId, new Dictionary<string, Decision>());
@@ -214,7 +209,7 @@ public void TestGetStoredVariationLogsWhenLookupReturnsNull()
214209
UserProfileServiceMock.Setup(_ => _.Lookup(UserProfileId)).Returns(userProfile.ToMap());
215210

216211
DecisionService decisionService = new DecisionService(bucketer,
217-
ErrorHandlerMock.Object, NoAudienceProjectConfig, userProfileService, LoggerMock.Object);
212+
ErrorHandlerMock.Object, ProjectConfig, userProfileService, LoggerMock.Object);
218213

219214
Assert.IsNull(decisionService.GetStoredVariation(experiment, userProfile));
220215

@@ -225,7 +220,7 @@ public void TestGetStoredVariationLogsWhenLookupReturnsNull()
225220
[Test]
226221
public void TestGetStoredVariationReturnsNullWhenVariationIsNoLongerInConfig()
227222
{
228-
Experiment experiment = NoAudienceProjectConfig.Experiments[0];
223+
Experiment experiment = ProjectConfig.Experiments[6];
229224
string storedVariationId = "missingVariation";
230225
Decision storedDecision = new Decision(storedVariationId);
231226

@@ -239,7 +234,7 @@ public void TestGetStoredVariationReturnsNullWhenVariationIsNoLongerInConfig()
239234

240235
UserProfileServiceMock.Setup(up => up.Lookup(UserProfileId)).Returns(storedUserProfile.ToMap());
241236

242-
DecisionService decisionService = new DecisionService(bucketer, ErrorHandlerMock.Object, NoAudienceProjectConfig,
237+
DecisionService decisionService = new DecisionService(bucketer, ErrorHandlerMock.Object, ProjectConfig,
243238
UserProfileServiceMock.Object, LoggerMock.Object);
244239
Assert.IsNull(decisionService.GetStoredVariation(experiment, storedUserProfile));
245240
LoggerMock.Verify(l => l.Log(LogLevel.INFO, string.Format("User \"{0}\" was previously bucketed into variation with ID \"{1}\" for experiment \"{2}\", but no matching variation was found for that user. We will re-bucket the user."
@@ -249,7 +244,7 @@ public void TestGetStoredVariationReturnsNullWhenVariationIsNoLongerInConfig()
249244
[Test]
250245
public void TestGetVariationSavesBucketedVariationIntoUserProfile()
251246
{
252-
Experiment experiment = NoAudienceProjectConfig.Experiments[0];
247+
Experiment experiment = ProjectConfig.Experiments[6];
253248
Variation variation = experiment.Variations[0];
254249

255250
Decision decision = new Decision(variation.Id);
@@ -265,9 +260,9 @@ public void TestGetVariationSavesBucketedVariationIntoUserProfile()
265260
});
266261

267262
var mockBucketer = new Mock<Bucketer>(LoggerMock.Object);
268-
mockBucketer.Setup(m => m.Bucket(ValidProjectConfig, experiment, UserProfileId, UserProfileId)).Returns(variation);
263+
mockBucketer.Setup(m => m.Bucket(ProjectConfig, experiment, UserProfileId, UserProfileId)).Returns(variation);
269264

270-
DecisionService decisionService = new DecisionService(mockBucketer.Object, ErrorHandlerMock.Object, ValidProjectConfig, UserProfileServiceMock.Object, LoggerMock.Object);
265+
DecisionService decisionService = new DecisionService(mockBucketer.Object, ErrorHandlerMock.Object, ProjectConfig, UserProfileServiceMock.Object, LoggerMock.Object);
271266

272267
Assert.IsTrue(TestData.CompareObjects(variation, decisionService.GetVariation(experiment, UserProfileId, new UserAttributes())));
273268

@@ -279,7 +274,7 @@ public void TestGetVariationSavesBucketedVariationIntoUserProfile()
279274
[Test]
280275
public void TestBucketLogsCorrectlyWhenUserProfileFailsToSave()
281276
{
282-
Experiment experiment = NoAudienceProjectConfig.Experiments[0];
277+
Experiment experiment = ProjectConfig.Experiments[6];
283278
Variation variation = experiment.Variations[0];
284279
Decision decision = new Decision(variation.Id);
285280
Bucketer bucketer = new Bucketer(LoggerMock.Object);
@@ -294,7 +289,7 @@ public void TestBucketLogsCorrectlyWhenUserProfileFailsToSave()
294289
UserProfile saveUserProfile = new UserProfile(UserProfileId, new Dictionary<string, Decision>());
295290

296291
DecisionService decisionService = new DecisionService(bucketer,
297-
ErrorHandlerMock.Object, NoAudienceProjectConfig, UserProfileServiceMock.Object, LoggerMock.Object);
292+
ErrorHandlerMock.Object, ProjectConfig, UserProfileServiceMock.Object, LoggerMock.Object);
298293

299294
decisionService.SaveVariation(experiment, variation, saveUserProfile);
300295

@@ -307,7 +302,7 @@ public void TestBucketLogsCorrectlyWhenUserProfileFailsToSave()
307302
[Test]
308303
public void TestGetVariationSavesANewUserProfile()
309304
{
310-
Experiment experiment = NoAudienceProjectConfig.Experiments[0];
305+
Experiment experiment = ProjectConfig.Experiments[6];
311306
Variation variation = experiment.Variations[0];
312307
Decision decision = new Decision(variation.Id);
313308

@@ -317,13 +312,13 @@ public void TestGetVariationSavesANewUserProfile()
317312
});
318313

319314
var mockBucketer = new Mock<Bucketer>(LoggerMock.Object);
320-
mockBucketer.Setup(m => m.Bucket(NoAudienceProjectConfig, experiment, UserProfileId, UserProfileId)).Returns(variation);
315+
mockBucketer.Setup(m => m.Bucket(ProjectConfig, experiment, UserProfileId, UserProfileId)).Returns(variation);
321316

322317
Dictionary<string, object> userProfile = null;
323318

324319
UserProfileServiceMock.Setup(up => up.Lookup(UserProfileId)).Returns(userProfile);
325320

326-
DecisionService decisionService = new DecisionService(mockBucketer.Object, ErrorHandlerMock.Object, NoAudienceProjectConfig,
321+
DecisionService decisionService = new DecisionService(mockBucketer.Object, ErrorHandlerMock.Object, ProjectConfig,
327322
UserProfileServiceMock.Object, LoggerMock.Object);
328323

329324
Assert.IsTrue(TestData.CompareObjects(variation, decisionService.GetVariation(experiment, UserProfileId, new UserAttributes())));
@@ -441,7 +436,7 @@ public void TestGetVariationWithBucketingId()
441436
});
442437

443438
UserProfileServiceMock.Setup(up => up.Lookup(userId)).Returns(storedUserProfile.ToMap());
444-
DecisionService decisionService = new DecisionService(bucketerMock.Object, ErrorHandlerMock.Object, ValidProjectConfig, UserProfileServiceMock.Object, LoggerMock.Object);
439+
DecisionService decisionService = new DecisionService(bucketerMock.Object, ErrorHandlerMock.Object, ProjectConfig, UserProfileServiceMock.Object, LoggerMock.Object);
445440

446441
actualVariation = optlyObject.GetVariation(experimentKey, userId, userAttributesWithBucketingId);
447442
Assert.IsTrue(TestData.CompareObjects(VariationWithKeyControl, actualVariation), string.Format("Variation \"{0}\" does not match expected user profile variation \"{1}\".", actualVariation?.Key, variationKeyControl));

OptimizelySDK.Tests/NoAudienceProjectConfigV3.json

Lines changed: 0 additions & 93 deletions
This file was deleted.

OptimizelySDK.Tests/OptimizelySDK.Tests.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@
102102
</ProjectReference>
103103
</ItemGroup>
104104
<ItemGroup>
105-
<EmbeddedResource Include="NoAudienceProjectConfigV3.json" />
106105
<None Include="packages.config" />
107-
<EmbeddedResource Include="ValidCachedDataFileV3.json" />
108106
</ItemGroup>
109107
<ItemGroup>
110108
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />

0 commit comments

Comments
 (0)