diff --git a/src/Splitio/Domain/EventValidatorResult.cs b/src/Splitio/Domain/EventValidatorResult.cs index a8cf7db2..68f819e7 100644 --- a/src/Splitio/Domain/EventValidatorResult.cs +++ b/src/Splitio/Domain/EventValidatorResult.cs @@ -1,9 +1,9 @@ namespace Splitio.Domain { - public class EventValidatorResult + public class PropertiesValidatorResult { public bool Success { get; set; } public object Value { get; set; } - public long EventSize { get; set; } + public long Size { get; set; } } } diff --git a/src/Splitio/Services/Client/Classes/SplitClient.cs b/src/Splitio/Services/Client/Classes/SplitClient.cs index a8a8fd3a..9e677de8 100644 --- a/src/Splitio/Services/Client/Classes/SplitClient.cs +++ b/src/Splitio/Services/Client/Classes/SplitClient.cs @@ -34,7 +34,7 @@ public abstract class SplitClient : ISplitClient protected readonly IKeyValidator _keyValidator; protected readonly ISplitNameValidator _splitNameValidator; protected readonly IEventTypeValidator _eventTypeValidator; - protected readonly IEventPropertiesValidator _eventPropertiesValidator; + protected readonly IPropertiesValidator _eventPropertiesValidator; protected readonly IWrapperAdapter _wrapperAdapter; protected readonly IConfigService _configService; protected readonly IFlagSetsValidator _flagSetsValidator; @@ -71,7 +71,7 @@ public SplitClient(string apikey) _keyValidator = new KeyValidator(); _splitNameValidator = new SplitNameValidator(); _eventTypeValidator = new EventTypeValidator(); - _eventPropertiesValidator = new EventPropertiesValidator(); + _eventPropertiesValidator = new PropertiesValidator(); _factoryInstantiationsService = FactoryInstantiationsService.Instance(); _flagSetsValidator = new FlagSetsValidator(); _configService = new ConfigService(_wrapperAdapter, _flagSetsValidator, new SdkMetadataValidator()); diff --git a/src/Splitio/Services/InputValidation/Classes/EventPropertiesValidator.cs b/src/Splitio/Services/InputValidation/Classes/PropertiesValidator.cs similarity index 81% rename from src/Splitio/Services/InputValidation/Classes/EventPropertiesValidator.cs rename to src/Splitio/Services/InputValidation/Classes/PropertiesValidator.cs index d42b5fa0..e1e7a29f 100644 --- a/src/Splitio/Services/InputValidation/Classes/EventPropertiesValidator.cs +++ b/src/Splitio/Services/InputValidation/Classes/PropertiesValidator.cs @@ -7,19 +7,19 @@ namespace Splitio.Services.InputValidation.Classes { - public class EventPropertiesValidator : IEventPropertiesValidator + public class PropertiesValidator : IPropertiesValidator { private const int MAX_PROPERTIES_LENGTH_BYTES = 32 * 1024; protected readonly ISplitLogger _log; - public EventPropertiesValidator(ISplitLogger log = null) + public PropertiesValidator(ISplitLogger log = null) { - _log = log ?? WrapperAdapter.Instance().GetLogger(typeof(EventPropertiesValidator)); + _log = log ?? WrapperAdapter.Instance().GetLogger(typeof(PropertiesValidator)); } - public EventValidatorResult IsValid(Dictionary properties) + public PropertiesValidatorResult IsValid(Dictionary properties) { - if (properties == null) return new EventValidatorResult { Success = true }; + if (properties == null) return new PropertiesValidatorResult { Success = true }; var propertiesResult = new Dictionary(); var size = 1024L; @@ -48,21 +48,21 @@ public EventValidatorResult IsValid(Dictionary properties) if (size > MAX_PROPERTIES_LENGTH_BYTES) { _log.Error($"The maximum size allowed for the properties is 32768 bytes. Current one is {size} bytes. Event not queued"); - return new EventValidatorResult { Success = false }; + return new PropertiesValidatorResult { Success = false }; } propertiesResult.Add(entry.Key, value); } - return new EventValidatorResult + return new PropertiesValidatorResult { Success = true, Value = propertiesResult, - EventSize = size + Size = size }; } - private bool IsNumeric(object value) + private static bool IsNumeric(object value) { if (value == null) return false; diff --git a/src/Splitio/Services/InputValidation/Interfaces/IEventPropertiesValidator.cs b/src/Splitio/Services/InputValidation/Interfaces/IEventPropertiesValidator.cs index 0bf8874f..ce862799 100644 --- a/src/Splitio/Services/InputValidation/Interfaces/IEventPropertiesValidator.cs +++ b/src/Splitio/Services/InputValidation/Interfaces/IEventPropertiesValidator.cs @@ -3,8 +3,8 @@ namespace Splitio.Services.InputValidation.Interfaces { - public interface IEventPropertiesValidator + public interface IPropertiesValidator { - EventValidatorResult IsValid(Dictionary properties); + PropertiesValidatorResult IsValid(Dictionary properties); } } \ No newline at end of file diff --git a/src/Splitio/Services/Shared/Classes/ClientExtensionService.cs b/src/Splitio/Services/Shared/Classes/ClientExtensionService.cs index a5956043..8d220230 100644 --- a/src/Splitio/Services/Shared/Classes/ClientExtensionService.cs +++ b/src/Splitio/Services/Shared/Classes/ClientExtensionService.cs @@ -21,7 +21,7 @@ public class ClientExtensionService : IClientExtensionService private readonly ISplitNameValidator _splitNameValidator; private readonly ITelemetryEvaluationProducer _telemetryEvaluationProducer; private readonly IEventTypeValidator _eventTypeValidator; - private readonly IEventPropertiesValidator _eventPropertiesValidator; + private readonly IPropertiesValidator _eventPropertiesValidator; private readonly ITrafficTypeValidator _trafficTypeValidator; private readonly IFlagSetsValidator _flagSetsValidator; private readonly IFlagSetsFilter _flagSetsFilter; @@ -32,7 +32,7 @@ public ClientExtensionService(IBlockUntilReadyService blockUntilReadyService, ISplitNameValidator splitNameValidator, ITelemetryEvaluationProducer telemetryEvaluationProducer, IEventTypeValidator eventTypeValidator, - IEventPropertiesValidator eventPropertiesValidator, + IPropertiesValidator eventPropertiesValidator, ITrafficTypeValidator trafficTypeValidator, IFlagSetsValidator flagSetsValidator, IFlagSetsFilter flagSetsFilter) @@ -55,15 +55,15 @@ public bool TrackValidations(string key, string trafficType, string eventType, d var keyResult = _keyValidator.IsValid(new Key(key, null), API.Track); var eventTypeResult = _eventTypeValidator.IsValid(eventType, nameof(eventType)); - var eventPropertiesResult = _eventPropertiesValidator.IsValid(properties); + var propertiesResult = _eventPropertiesValidator.IsValid(properties); var trafficTypeResult = _trafficTypeValidator.IsValid(trafficType, API.Track); - if (!keyResult || !trafficTypeResult.Success || !eventTypeResult || !eventPropertiesResult.Success) + if (!keyResult || !trafficTypeResult.Success || !eventTypeResult || !propertiesResult.Success) return false; wrappedEvent = new WrappedEvent { - Size = eventPropertiesResult.EventSize, + Size = propertiesResult.Size, Event = new Event { key = key, @@ -71,7 +71,7 @@ public bool TrackValidations(string key, string trafficType, string eventType, d eventTypeId = eventType, value = value, timestamp = CurrentTimeHelper.CurrentTimeMillis(), - properties = (Dictionary)eventPropertiesResult.Value + properties = (Dictionary)propertiesResult.Value } }; diff --git a/tests/Splitio-tests/Unit Tests/InputValidation/EventPropertiesValidatorTests.cs b/tests/Splitio-tests/Unit Tests/InputValidation/EventPropertiesValidatorTests.cs index 6252d492..93f2e17f 100644 --- a/tests/Splitio-tests/Unit Tests/InputValidation/EventPropertiesValidatorTests.cs +++ b/tests/Splitio-tests/Unit Tests/InputValidation/EventPropertiesValidatorTests.cs @@ -12,14 +12,14 @@ namespace Splitio_Tests.Unit_Tests.InputValidation public class EventPropertiesValidatorTests { private Mock _log; - private EventPropertiesValidator eventPropertiesValidator; + private PropertiesValidator eventPropertiesValidator; [TestInitialize] public void Initialize() { _log = new Mock(); - eventPropertiesValidator = new EventPropertiesValidator(_log.Object); + eventPropertiesValidator = new PropertiesValidator(_log.Object); } [TestMethod] @@ -31,7 +31,7 @@ public void IsValid_WhenPropertiesIsNull_ReturnsTrue() // Assert. Assert.IsTrue(result.Success); Assert.IsNull(result.Value); - Assert.IsTrue(result.EventSize == default(long)); + Assert.IsTrue(result.Size == default(long)); } [TestMethod] @@ -95,7 +95,7 @@ public void IsValid_WhenPropertiesIsNotNull_ReturnsTrue() Assert.AreEqual(ushortValue, dicResult["property_11"]); Assert.AreEqual(uintValue, dicResult["property_12"]); Assert.AreEqual(ulongValue, dicResult["property_13"]); - Assert.IsTrue(result.EventSize == sizeExpected); + Assert.IsTrue(result.Size == sizeExpected); _log.Verify(mock => mock.Warn($"Property Splitio.Domain.ParsedSplit is of invalid type. Setting value to null"), Times.Once); _log.Verify(mock => mock.Warn(It.IsAny()), Times.Exactly(1)); @@ -128,7 +128,7 @@ public void IsValid_WhenPropertiesCountIsBiggerThan300_ReturnsTrue() // Assert. Assert.IsTrue(result.Success); Assert.IsNotNull(result.Value); - Assert.IsTrue(result.EventSize == sizeExpected); + Assert.IsTrue(result.Size == sizeExpected); _log.Verify(mock => mock.Warn("Event has more than 300 properties. Some of them will be trimmed when processed"), Times.Once); _log.Verify(mock => mock.Warn(It.IsAny()), Times.Exactly(1)); @@ -153,7 +153,7 @@ public void IsValid_WhenPropertiesBytesIsBiggerThanWeSupport_ReturnsFalse() // Assert. Assert.IsFalse(result.Success); Assert.IsNull(result.Value); - Assert.IsTrue(result.EventSize == default(long)); + Assert.IsTrue(result.Size == default(long)); var size = 1024L; foreach (var item in properties) diff --git a/tests/Splitio-tests/Unit Tests/Shared/ClientExtensionServiceTests.cs b/tests/Splitio-tests/Unit Tests/Shared/ClientExtensionServiceTests.cs index 79833258..8c736a7e 100644 --- a/tests/Splitio-tests/Unit Tests/Shared/ClientExtensionServiceTests.cs +++ b/tests/Splitio-tests/Unit Tests/Shared/ClientExtensionServiceTests.cs @@ -25,7 +25,7 @@ public class ClientExtensionServiceTests private readonly ISplitNameValidator _splitNameValidator; private readonly IKeyValidator _keyValidator; private readonly IEventTypeValidator _eventTypeValidator; - private readonly IEventPropertiesValidator _eventPropertiesValidator; + private readonly IPropertiesValidator _eventPropertiesValidator; private readonly ITrafficTypeValidator _trafficTypeValidator; private readonly IFlagSetsValidator _flagSetsValidator; private readonly IFlagSetsFilter _flagSetsFilter; @@ -42,7 +42,7 @@ public ClientExtensionServiceTests() _splitNameValidator = new SplitNameValidator(); _keyValidator = new KeyValidator(_logger.Object); _eventTypeValidator = new EventTypeValidator(_logger.Object); - _eventPropertiesValidator = new EventPropertiesValidator(_logger.Object); + _eventPropertiesValidator = new PropertiesValidator(_logger.Object); _trafficTypeValidator = new TrafficTypeValidator(_featureFlagCacheConsumer.Object, _blockUntilReadyService.Object, _logger.Object); _flagSetsValidator = new FlagSetsValidator(); _flagSetsFilter = new FlagSetsFilter(new HashSet());