public void CanConvertOnlyWhenTypeIsDateTimeOffset() { DateTimeOffsetConverter converter = new DateTimeOffsetConverter(); Assert.False(converter.CanConvert(typeof(int))); Assert.False(converter.CanConvert(typeof(string))); Assert.False(converter.CanConvert(typeof(bool))); Assert.True(converter.CanConvert(typeof(DateTimeOffset))); }
public void ConvertToDateTimeOffset_Success() { settings.DateHandling = DateValueHandling.Default; var date = new DateTimeOffset(2000, 1, 2, 3, 4, 5, 6, TimeSpan.FromMinutes(7)); Assert.True(converter.CanConvert(date.GetType())); var dict = converter.ToDictionary(date, settings); Assert.Equal(expected, dict); dict.Remove(nameof(DateTime.Ticks)); ((IDictionary)dict[nameof(DateTimeOffset.Offset)]).Remove(nameof(TimeSpan.Ticks)); var result = converter.ToInstance(dict, settings); Assert.Equal(date, result); }