Exemplo n.º 1
0
        private void AssertParseUnixSuccess(object timeToParse, long expectedTime)
        {
            ValueParseResult parseResult = TimeParser.ParseUnix(timeToParse);

            Assert.That(parseResult.Success, Is.True);
            Assert.That(parseResult.Value, Is.EqualTo(expectedTime));
        }
Exemplo n.º 2
0
        private void AssertSuccess(object durationToParse, object expectedDuration)
        {
            ValueParseResult parseResult = DurationParser.Parse(durationToParse);

            Assert.That(parseResult.Success, Is.True);
            Assert.That(parseResult.Value, Is.EqualTo(expectedDuration));
        }
Exemplo n.º 3
0
        private void AssertParseMixpanelFormatSuccess(object timeToParse, string expectedTime)
        {
            ValueParseResult parseResult = TimeParser.ParseMixpanelFormat(timeToParse);

            Assert.That(parseResult.Success, Is.True);
            Assert.That(parseResult.Value, Is.EqualTo(expectedTime));
        }
        private void AssertSuccess(object ipToParse, string expectedIp)
        {
            ValueParseResult parseResult = IpParser.Parse(ipToParse);

            Assert.That(parseResult.Success, Is.True);
            Assert.That(parseResult.Value, Is.EqualTo(expectedIp));
        }
Exemplo n.º 5
0
        private void AssertSuccess(object distinctIdToParse, string expectedDistinctId)
        {
            ValueParseResult parseResult = DistinctIdParser.Parse(distinctIdToParse);

            Assert.That(parseResult.Success, Is.True);
            Assert.That(parseResult.Value, Is.EqualTo(expectedDistinctId));
        }
        public static MessageBuildResult Build(
            string token,
            IEnumerable <ObjectProperty> superProperties,
            object distinctId,
            object alias)
        {
            MessageCandidate messageCandidate = TrackMessageBuilderBase.CreateValidMessageCandidate(
                token,
                superProperties,
                null,
                distinctId,
                null,
                out string messageCandidateErrorMessage);

            if (messageCandidate == null)
            {
                return(MessageBuildResult.CreateFail(messageCandidateErrorMessage));
            }

            var message = new Dictionary <string, object>(2);

            message["event"] = "$create_alias";

            var properties = new Dictionary <string, object>(3);

            message["properties"] = properties;

            // token
            properties["token"] = messageCandidate.GetSpecialProperty(TrackSpecialProperty.Token).Value;

            // distinct_id
            ObjectProperty rawDistinctId = messageCandidate.GetSpecialProperty(TrackSpecialProperty.DistinctId);

            if (rawDistinctId == null)
            {
                return(MessageBuildResult.CreateFail($"'{TrackSpecialProperty.DistinctId}' is not set."));
            }

            ValueParseResult distinctIdParseResult = DistinctIdParser.Parse(rawDistinctId.Value);

            if (!distinctIdParseResult.Success)
            {
                return(MessageBuildResult.CreateFail(
                           $"Error parsing '{TrackSpecialProperty.DistinctId}'.", distinctIdParseResult.ErrorDetails));
            }

            properties["distinct_id"] = distinctIdParseResult.Value;

            // alias
            ValueParseResult aliasParseResult = DistinctIdParser.Parse(alias);

            if (!aliasParseResult.Success)
            {
                return(MessageBuildResult.CreateFail("Error parsing 'alias'. " + aliasParseResult.ErrorDetails));
            }
            properties["alias"] = aliasParseResult.Value;


            return(MessageBuildResult.CreateSuccess(message));
        }
Exemplo n.º 7
0
        public static void RunForValidUserProperties(
            MessageCandidate messageCandidate,
            Func <object, ValueParseResult> parseFn,
            Action <string, object> fn)
        {
            foreach (KeyValuePair <string, ObjectProperty> pair in messageCandidate.UserProperties)
            {
                string         formattedPropertyName = pair.Key;
                ObjectProperty objectProperty        = pair.Value;

                if (objectProperty.Origin == PropertyOrigin.SuperProperty)
                {
                    // Skip all non special super properties as they are not valid for people message
                    continue;
                }

                ValueParseResult result = parseFn(objectProperty.Value);
                if (!result.Success)
                {
                    continue;
                }

                fn(formattedPropertyName, result.Value);
            }
        }
Exemplo n.º 8
0
        private void AssertFail(object durationToParse)
        {
            ValueParseResult parseResult = DurationParser.Parse(durationToParse);

            Assert.That(parseResult.Success, Is.False);
            Assert.That(parseResult.Value, Is.Null);
            Assert.That(parseResult.ErrorDetails, Is.Not.Empty);
        }
Exemplo n.º 9
0
        private void AssertParseMixpanelFormatFail(object timeToParse)
        {
            ValueParseResult parseResult = TimeParser.ParseMixpanelFormat(timeToParse);

            Assert.That(parseResult.Success, Is.False);
            Assert.That(parseResult.Value, Is.Null);
            Assert.That(parseResult.ErrorDetails, Is.Not.Empty);
        }
Exemplo n.º 10
0
        private void AssertFail(object distinctIdToParse)
        {
            ValueParseResult parseResult = DistinctIdParser.Parse(distinctIdToParse);

            Assert.That(parseResult.Success, Is.False);
            Assert.That(parseResult.Value, Is.Null);
            Assert.That(parseResult.ErrorDetails, Is.Not.Empty);
        }
        private void AssertSuccess(
            Func <object, ValueParseResult> itemParseFn,
            object collectionToParse,
            IEnumerable expectedCollection)
        {
            ValueParseResult parseResult = CollectionParser.Parse(collectionToParse, itemParseFn);

            Assert.That(parseResult.Success, Is.True);
            Assert.That(parseResult.Value, Is.EquivalentTo(expectedCollection));
        }
        private void AssertFail(
            Func <object, ValueParseResult> itemParseFn,
            object collectionToParse)
        {
            ValueParseResult parseResult = CollectionParser.Parse(collectionToParse, itemParseFn);

            Assert.That(parseResult.Success, Is.False);
            Assert.That(parseResult.Value, Is.Null);
            Assert.That(parseResult.ErrorDetails, Is.Not.Empty);
        }
Exemplo n.º 13
0
        public static MessageCandidate CreateValidMessageCandidate(
            string token,
            IEnumerable <ObjectProperty> superProperties,
            object rawProperties,
            object distinctId,
            MixpanelConfig config,
            out string errorMessage)
        {
            var messageCandidate = new MessageCandidate(
                token,
                superProperties,
                rawProperties,
                distinctId,
                config,
                PeopleSpecialPropertyMapper.RawNameToSpecialProperty);

            ObjectProperty tokenProp = messageCandidate.GetSpecialProperty(PeopleSpecialProperty.Token);

            if (tokenProp == null)
            {
                errorMessage = $"'{PeopleSpecialProperty.Token}' is not set.";
                return(null);
            }

            ValueParseResult tokenParseResult =
                PeopleSpecialPropertyParser.Parse(PeopleSpecialProperty.Token, tokenProp.Value);

            if (!tokenParseResult.Success)
            {
                errorMessage = $"Error parsing '{PeopleSpecialProperty.Token}'. {tokenParseResult.ErrorDetails}";
                return(null);
            }

            ObjectProperty distinctIdProp = messageCandidate.GetSpecialProperty(PeopleSpecialProperty.DistinctId);

            if (distinctIdProp == null)
            {
                errorMessage = $"'{PeopleSpecialProperty.DistinctId}' is not set.";
                return(null);
            }

            ValueParseResult distinctIdParseResult =
                PeopleSpecialPropertyParser.Parse(PeopleSpecialProperty.DistinctId, distinctIdProp.Value);

            if (!distinctIdParseResult.Success)
            {
                errorMessage = $"Error parsing '{PeopleSpecialProperty.DistinctId}'. {distinctIdParseResult.ErrorDetails}";
                return(null);
            }

            errorMessage = null;
            return(messageCandidate);
        }
Exemplo n.º 14
0
        public static ValueParseResult Parse(object rawValue)
        {
            switch (rawValue)
            {
            case null:
                return(ValueParseResult.CreateFail("Can't be null."));

            case bool _:
                return(ValueParseResult.CreateSuccess(rawValue));

            default:
                return(ValueParseResult.CreateFail("Expected type is: bool."));
            }
        }
Exemplo n.º 15
0
        public static void RunForValidSpecialProperties(
            MessageCandidate messageCandidate,
            Action <string, bool, object> fn)
        {
            foreach (KeyValuePair <string, ObjectProperty> pair in messageCandidate.SpecialProperties)
            {
                string         specialPropertyName = pair.Key;
                ObjectProperty objectProperty      = pair.Value;

                ValueParseResult result = PeopleSpecialPropertyParser.Parse(specialPropertyName, objectProperty.Value);
                if (!result.Success)
                {
                    continue;
                }

                bool isMessageSpecialProperty = PeopleSpecialProperty.IsMessageSpecialProperty(specialPropertyName);

                fn(specialPropertyName, isMessageSpecialProperty, result.Value);
            }
        }
Exemplo n.º 16
0
 public static ValueParseResult Parse(object rawNumber)
 {
     return(IsNumber(rawNumber)
         ? ValueParseResult.CreateSuccess(rawNumber)
         : ValueParseResult.CreateFail("Expected type is: number (int, double etc)"));
 }
Exemplo n.º 17
0
        public static MessageBuildResult Build(
            string token,
            string @event,
            IEnumerable <ObjectProperty> superProperties,
            object rawProperties,
            object distinctId,
            MixpanelConfig config)
        {
            if (string.IsNullOrWhiteSpace(@event))
            {
                return(MessageBuildResult.CreateFail($"'{nameof(@event)}' is not set."));
            }

            MessageCandidate messageCandidate = TrackMessageBuilderBase.CreateValidMessageCandidate(
                token,
                superProperties,
                rawProperties,
                distinctId,
                config,
                out string messageCandidateErrorMessage);

            if (messageCandidate == null)
            {
                return(MessageBuildResult.CreateFail(messageCandidateErrorMessage));
            }

            var message = new Dictionary <string, object>(2);

            message["event"] = @event;

            var properties = new Dictionary <string, object>();

            message["properties"] = properties;

            // Special properties
            foreach (KeyValuePair <string, ObjectProperty> pair in messageCandidate.SpecialProperties)
            {
                string         specialPropertyName = pair.Key;
                ObjectProperty objectProperty      = pair.Value;

                ValueParseResult result =
                    TrackSpecialPropertyParser.Parse(specialPropertyName, objectProperty.Value);
                if (!result.Success)
                {
                    // The only required special properties are 'event' and 'token' which are controlled separately
                    continue;
                }

                properties[specialPropertyName] = result.Value;
            }

            // User properties
            foreach (KeyValuePair <string, ObjectProperty> pair in messageCandidate.UserProperties)
            {
                string         formattedPropertyName = pair.Key;
                ObjectProperty objectProperty        = pair.Value;

                ValueParseResult result = GenericPropertyParser.Parse(objectProperty.Value, allowCollections: true);
                if (!result.Success)
                {
                    continue;
                }

                properties[formattedPropertyName] = result.Value;
            }

            return(MessageBuildResult.CreateSuccess(message));
        }