Example #1
0
        public void MapObject_NullDateTime_Success()
        {
            StringMap <DateTime?> map = "snapshot-times/{this:yyyy/MM/dd/HH/mm/ss}";

            var actual = map.Map(null as DateTime?, true);

            Assert.Equal("snapshot-times/", actual);
        }
Example #2
0
        public void MapString_NullDateTime_Success()
        {
            StringMap <DateTime?> map = "snapshot-times/{this:yyyy/MM/dd/HH/mm/ss}";

            var actual = map.Map("snapshot-times/");

            Assert.Equal(null, actual);
        }
Example #3
0
        public void TestWeirdThing()
        {
            var s = "call-extensions/account-id/0006124a2c1d4c11b71a7c2d50d09d12/GoogleAdWords";

            var m = new StringMap <CallExtensionOverride.Key>("call-extensions/account-id/{AccountId}/{AdPlatform:P}");

            var r = m.Map(s);
        }
Example #4
0
        public void MapString_NonFullMatch_ThenNull()
        {
            var map = new StringMap <ExchangeCurrencyPairTimeKey>("apples/{Exchange}/oranges");

            var result = map.Map("/apples/bitstamp/oranges");

            Assert.Null(result);
        }
Example #5
0
        public void MapString_WhenPatternNotMatched_ThenDefault()
        {
            var map = new StringMap <Wrapper <Guid> >("alfa/{Property}/bravo");

            var str = "alfa/ff14cea6a92c4a82bd8478c3d17220d2/charlie";

            var obj = map.Map(str);

            Assert.Null(obj);
        }
Example #6
0
        public void MapString_WhenInvalidValue_ThenDefault()
        {
            var map = new StringMap <Wrapper <Guid> >("alfa/{Property}/bravo");

            var str = "alfa/not-a-guid/bravo";

            var obj = map.Map(str);

            Assert.Null(obj);
        }
Example #7
0
        public void MapString_WhenString_WildcardTail_ThenSuccess()
        {
            var map = new StringMap <string>("alfa/{*this}");

            var str = map.Map("alfa/charlie/delta/bravo.jpg");

            Assert.Equal(
                "charlie/delta/bravo.jpg",
                str);
        }
Example #8
0
        public void MapObject_WildcardTail_ThenSuccess()
        {
            var key = "charlie/delta/bravo.jpg";

            var map = new StringMap <string>("alfa/{*this}");

            var str = map.Map(key, allowPartialMap: false);

            Assert.Equal(
                $"alfa/{key}",
                str);
        }
Example #9
0
        public void MapDictionary_WhenString_WildcardTail_ThenSuccess()
        {
            var key = "charlie/delta/bravo.jpg";

            var map = new StringMap <string>("alfa/{*this}");

            var str = map.Map(new Dictionary <string, object>
            {
                ["this"] = key
            });

            Assert.Equal(
                $"alfa/{key}",
                str);
        }
Example #10
0
        public void MapString_WhenSlashInPattern_ThenProperMatch()
        {
            var map = new StringMap <ExchangeCurrencyPairTimeKey>(
                "order-books/{Exchange}/{CurrencyPair}/{Time:yyyy-MM-dd/HH-mm-ss}");

            var str = "order-books/bitstamp/btc-usd/2017-04-04/17-37-00";

            var obj = map.Map(str);

            Assert.Equal("bitstamp", obj.Exchange);

            Assert.Equal("btc-usd", obj.CurrencyPair);

            Assert.Equal(
                new DateTime(2017, 4, 4, 17, 37, 0, DateTimeKind.Utc),
                obj.Time);
        }
Example #11
0
        void MapDictionary_WhenSimpleType_ThenSuccess <TSimpleType>(
            IReadOnlyDictionary <string, object> dictionary,
            string stringValue,
            string format = null)
        {
            var map = new StringMap <TSimpleType>(string.IsNullOrWhiteSpace(format) ?
                                                  "alfa/{this}/bravo" :
                                                  $"alfa/{{this:{format}}}/bravo");

            var str = map.Map(dictionary);

            Assert.Equal(
                $"alfa/{stringValue}/bravo",
                str);

            _testOutputHelper.WriteLine($"map: {map}");

            _testOutputHelper.WriteLine($"str: {str}");
        }
Example #12
0
        void MapString_WhenImmutableType_ThenSuccess <TType>(
            string stringValue,
            TType value,
            string format = null)
        {
            var map = new StringMap <Immutable <TType> >(string.IsNullOrWhiteSpace(format) ?
                                                         "alfa/{Property}/bravo" :
                                                         $"alfa/{{Property:{format}}}/bravo");

            var str = $"alfa/{stringValue}/bravo";

            var obj = map.Map(str);

            Assert.Equal(
                value,
                obj.Property);

            _testOutputHelper.WriteLine($"map: {map}");

            _testOutputHelper.WriteLine($"str: {str}");
        }
Example #13
0
        void MapDictionary_WhenImmutableType_ThenSuccess <TType>(
            IReadOnlyDictionary <string, object> memberValues,
            string stringValue,
            string format = null)
        {
            var map = new StringMap <Immutable <TType> >(string.IsNullOrWhiteSpace(format) ?
                                                         "alfa/{Property}/bravo" :
                                                         $"alfa/{{Property:{format}}}/bravo");

            var str = map.Map(memberValues);

            _testOutputHelper.WriteLine($"str is {str}");

            Assert.Equal(
                $"alfa/{stringValue}/bravo",
                str);

            _testOutputHelper.WriteLine($"map: {map}");

            _testOutputHelper.WriteLine($"str: {str}");
        }
Example #14
0
        void MapString_WhenObjectType_ThenSuccess <TSimpleType>(
            string stringValue,
            TSimpleType value,
            string format = null)
        {
            var map = new StringMap <TSimpleType>(string.IsNullOrWhiteSpace(format) ?
                                                  "alfa/{this}/bravo" :
                                                  $"alfa/{{this:{format}}}/bravo");

            var str = $"alfa/{stringValue}/bravo";

            var obj = map.Map(str);

            Assert.Equal(
                JsonConvert.SerializeObject(value),
                JsonConvert.SerializeObject(obj));

            _testOutputHelper.WriteLine($"map: {map}");

            _testOutputHelper.WriteLine($"str: {str}");
        }
Example #15
0
        public void MapObject_Guid_SpeedTest()
        {
            var value = Guid.NewGuid();

            var map = new StringMap <Guid>("alfa/{this}/bravo");

            var time = Stopwatch.StartNew();

            var count = 0;

            while (time.Elapsed.TotalSeconds < 5)
            {
                var str = map.Map(value);

                count++;
            }

            _testOutputHelper.WriteLine($"Rate: {count / time.Elapsed.TotalSeconds} / s");

            _testOutputHelper.WriteLine($"Avg: {time.Elapsed.TotalMilliseconds / count} ms");
        }
Example #16
0
        public void MapObject_ImmutableDateTime_SpeedTest()
        {
            var value = new Immutable <DateTime>(new DateTime(
                                                     2016, 7, 11,
                                                     2, 3, 4,
                                                     DateTimeKind.Utc));

            var map = new StringMap <Immutable <DateTime> >("alfa/{Property:yyyy/MM/dd/hh/mm/ss}/bravo");

            var time = Stopwatch.StartNew();

            var count = 0;

            while (time.Elapsed.TotalSeconds < 5)
            {
                var str = map.Map(value);

                count++;
            }

            _testOutputHelper.WriteLine($"Rate: {count / time.Elapsed.TotalSeconds} / s");

            _testOutputHelper.WriteLine($"Avg: {time.Elapsed.TotalMilliseconds / count} ms");
        }
 string GetPath(TKey key) => $"{_keyMap.Map(key)}{_fileExtension}";