public void StringConversionsDoNotUseExceptions() { var data = new ManyPropertiesEventData(); var initialCulture = CultureInfo.CurrentCulture; using (new Disposable(() => CultureInfo.CurrentCulture = initialCulture, () => CultureInfo.CurrentCulture = CultureInfo.InvariantCulture)) using (var fceCounter = new FirstChanceExceptionCounter(typeof(InvalidCastException))) { Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.BoolProperty, (string v) => Assert.Equal(ManyPropertiesEventData.ExpectedBoolValue.ToString(), v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.DateTimeProperty, (string v) => Assert.Equal(ManyPropertiesEventData.ExpectedDateTimeValue.ToString(), v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.DateTimeOffsetProperty, (string v) => Assert.Equal(ManyPropertiesEventData.ExpectedDateTimeOffsetValue.ToString(), v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.GuidProperty, (string v) => Assert.Equal(ManyPropertiesEventData.ExpectedGuidValue.ToString(), v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.TimeSpanProperty, (string v) => Assert.Equal(ManyPropertiesEventData.ExpectedTimeSpanValue.ToString(), v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.FloatProperty, (string v) => Assert.Equal(ManyPropertiesEventData.ExpectedFloatValue.ToString(), v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.DoubleProperty, (string v) => Assert.Equal(ManyPropertiesEventData.ExpectedDoubleValue.ToString(), v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.ByteProperty, (string v) => Assert.Equal(ManyPropertiesEventData.ExpectedByteValue.ToString(), v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.ShortProperty, (string v) => Assert.Equal(ManyPropertiesEventData.ExpectedShortValue.ToString(), v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.UShortProperty, (string v) => Assert.Equal(ManyPropertiesEventData.ExpectedUShortValue.ToString(), v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.IntProperty, (string v) => Assert.Equal(ManyPropertiesEventData.ExpectedIntValue.ToString(), v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.UIntProperty, (string v) => Assert.Equal(ManyPropertiesEventData.ExpectedUIntValue.ToString(), v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.LongProperty, (string v) => Assert.Equal(ManyPropertiesEventData.ExpectedLongValue.ToString(), v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.ULongProperty, (string v) => Assert.Equal(ManyPropertiesEventData.ExpectedULongValue.ToString(), v))); Assert.Equal(0, fceCounter.Count); } }
public void MatchingTypePropertyValueQueriesDoNotUseExceptions() { var data = new ManyPropertiesEventData(); using (var fceCounter = new FirstChanceExceptionCounter(typeof(InvalidCastException))) { Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.BoolProperty, (bool v) => Assert.Equal(ManyPropertiesEventData.ExpectedBoolValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.DateTimeProperty, (DateTime v) => Assert.Equal(ManyPropertiesEventData.ExpectedDateTimeValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.DateTimeOffsetProperty, (DateTimeOffset v) => Assert.Equal(ManyPropertiesEventData.ExpectedDateTimeOffsetValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.GuidProperty, (Guid v) => Assert.Equal(ManyPropertiesEventData.ExpectedGuidValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.TimeSpanProperty, (TimeSpan v) => Assert.Equal(ManyPropertiesEventData.ExpectedTimeSpanValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.FloatProperty, (float v) => Assert.Equal(ManyPropertiesEventData.ExpectedFloatValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.DoubleProperty, (double v) => Assert.Equal(ManyPropertiesEventData.ExpectedDoubleValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.ByteProperty, (byte v) => Assert.Equal(ManyPropertiesEventData.ExpectedByteValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.ShortProperty, (short v) => Assert.Equal(ManyPropertiesEventData.ExpectedShortValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.UShortProperty, (ushort v) => Assert.Equal(ManyPropertiesEventData.ExpectedUShortValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.IntProperty, (int v) => Assert.Equal(ManyPropertiesEventData.ExpectedIntValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.UIntProperty, (uint v) => Assert.Equal(ManyPropertiesEventData.ExpectedUIntValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.LongProperty, (long v) => Assert.Equal(ManyPropertiesEventData.ExpectedLongValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.ULongProperty, (ulong v) => Assert.Equal(ManyPropertiesEventData.ExpectedULongValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.StringProperty, (string v) => Assert.Equal(ManyPropertiesEventData.ExpectedStringValue, v))); Assert.Equal(0, fceCounter.Count); } }
public void ImplicitNumericConversionsDoNotUseExceptions() { var data = new ManyPropertiesEventData(); using (var fceCounter = new FirstChanceExceptionCounter(typeof(InvalidCastException))) { // Note: we don't handle ALL implicit numeric conversions (e.g. byte --> short still involves a failed cast), but the most commonly used types are covered. Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.FloatProperty, (double v) => Assert.Equal(ManyPropertiesEventData.ExpectedFloatValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.ByteProperty, (int v) => Assert.Equal(ManyPropertiesEventData.ExpectedByteValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.ByteProperty, (uint v) => Assert.Equal(ManyPropertiesEventData.ExpectedByteValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.ByteProperty, (long v) => Assert.Equal(ManyPropertiesEventData.ExpectedByteValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.ByteProperty, (ulong v) => Assert.Equal(ManyPropertiesEventData.ExpectedByteValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.ByteProperty, (float v) => Assert.Equal(ManyPropertiesEventData.ExpectedByteValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.ByteProperty, (double v) => Assert.Equal(ManyPropertiesEventData.ExpectedByteValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.ShortProperty, (int v) => Assert.Equal(ManyPropertiesEventData.ExpectedShortValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.ShortProperty, (long v) => Assert.Equal(ManyPropertiesEventData.ExpectedShortValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.ShortProperty, (float v) => Assert.Equal(ManyPropertiesEventData.ExpectedShortValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.ShortProperty, (double v) => Assert.Equal(ManyPropertiesEventData.ExpectedShortValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.UShortProperty, (int v) => Assert.Equal(ManyPropertiesEventData.ExpectedUShortValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.UShortProperty, (uint v) => Assert.Equal(ManyPropertiesEventData.ExpectedUShortValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.UShortProperty, (long v) => Assert.Equal(ManyPropertiesEventData.ExpectedUShortValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.UShortProperty, (ulong v) => Assert.Equal(ManyPropertiesEventData.ExpectedUShortValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.UShortProperty, (float v) => Assert.Equal(ManyPropertiesEventData.ExpectedUShortValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.UShortProperty, (double v) => Assert.Equal(ManyPropertiesEventData.ExpectedUShortValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.IntProperty, (long v) => Assert.Equal(ManyPropertiesEventData.ExpectedIntValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.IntProperty, (float v) => Assert.Equal(ManyPropertiesEventData.ExpectedIntValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.IntProperty, (double v) => Assert.Equal(ManyPropertiesEventData.ExpectedIntValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.UIntProperty, (long v) => Assert.Equal(ManyPropertiesEventData.ExpectedUIntValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.UIntProperty, (ulong v) => Assert.Equal(ManyPropertiesEventData.ExpectedUIntValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.UIntProperty, (float v) => Assert.Equal(ManyPropertiesEventData.ExpectedUIntValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.UIntProperty, (double v) => Assert.Equal(ManyPropertiesEventData.ExpectedUIntValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.LongProperty, (float v) => Assert.Equal(ManyPropertiesEventData.ExpectedLongValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.LongProperty, (double v) => Assert.Equal(ManyPropertiesEventData.ExpectedLongValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.ULongProperty, (float v) => Assert.Equal(ManyPropertiesEventData.ExpectedULongValue, v))); Assert.True(data.GetValueFromPayload(ManyPropertiesEventData.ULongProperty, (double v) => Assert.Equal(ManyPropertiesEventData.ExpectedULongValue, v))); Assert.Equal(0, fceCounter.Count); } }