Skip to content

Commit

Permalink
test: add coverage for collecting invalid user attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
mikechu-optimizely committed Nov 21, 2023
1 parent f1e20c8 commit 6171094
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions OptimizelySDK.Tests/EventTests/UserEventFactoryTest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
/*
*
* Copyright 2019-2020, Optimizely and contributors
* Copyright 2019-2020, 2023 Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -15,6 +15,7 @@
* limitations under the License.
*/

using System;
using Moq;
using NUnit.Framework;
using OptimizelySDK.Config;
Expand Down Expand Up @@ -96,6 +97,25 @@ public void ImpressionEventTestWithAttributes()
TestData.CompareObjects(expectedVisitorAttributes, impressionEvent.VisitorAttributes);
}

[Test]
public void EventFactoryBuildShouldLogInvalidUserAttributes()
{
var projectConfig = Config;

var invalidUserAttributes = new UserAttributes
{
{ "invalid_date_object", new DateTime() },
{ "invalid_array_use", new int[7] },
};
var expectedInvalidMessage =
$"User attributes: invalid_date_object, invalid_array_use were invalid and omitted.";

EventFactory.BuildAttributeList(invalidUserAttributes, projectConfig,
LoggerMock.Object);

LoggerMock.Verify(l => l.Log(LogLevel.WARN, expectedInvalidMessage), Times.Once());
}

[Test]
public void ConversionEventTest()
{
Expand Down

0 comments on commit 6171094

Please sign in to comment.