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); }
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); }
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); }
public void MapString_NonFullMatch_ThenNull() { var map = new StringMap <ExchangeCurrencyPairTimeKey>("apples/{Exchange}/oranges"); var result = map.Map("/apples/bitstamp/oranges"); Assert.Null(result); }
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); }
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); }
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); }
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); }
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); }
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); }
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}"); }
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}"); }
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}"); }
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}"); }
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"); }
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}";