Example #1
0
        /// <summary>
        ///     Returns an instance, given a comma-separated string where the fields represent,
        ///     in order, the contact ID, the event, and the score. Returns null if the argument
        ///     could not be parsed
        /// </summary>
        /// <param name="line">A comma separated string</param>
        /// <returns>An instnace, or null if the provided string could not be interpreted</returns>
        public static ScoreRecord Parse(string line)
        {
            ScoreRecord result = null;
            var parts = line?.Split(',');

            if (parts?.Length >= 3)
            {
                int contactId;
                Event channel;
                float score;

                if (int.TryParse(parts[0], out contactId)
                    && Enum.TryParse(parts[1], true, out channel)
                    && float.TryParse(parts[2], out score))
                {
                    result = new ScoreRecord
                    {
                        ContactId = contactId,
                        Event = channel,
                        Score = score
                    };
                }
            }
            return result;
        }
Example #2
0
 private static void AssertRecordValues(ScoreRecord target, int contactId, Event channel, float score)
 {
     Assert.AreEqual(target?.Event, channel);
     Assert.AreEqual(target?.ContactId, contactId);
     Assert.AreEqual(target?.Score, score);
 }