public void Binding_OnBindingComplete_Invoke_CallsBindingComplete(BindingCompleteEventArgs eventArgs) { var binding = new SubBinding("propertyName", new object(), "dataMember"); // No handler. binding.OnBindingComplete(eventArgs); // Handler. int callCount = 0; BindingCompleteEventHandler handler = (sender, e) => { Assert.Equal(binding, sender); Assert.Same(eventArgs, e); callCount++; }; binding.BindingComplete += handler; binding.OnBindingComplete(eventArgs); Assert.Equal(1, callCount); // Should not call if the handler is removed. binding.BindingComplete -= handler; binding.OnBindingComplete(eventArgs); Assert.Equal(1, callCount); }
public void Binding_OnBindingComplete_InvokeInsideBindingComplete_DoesNotCallBindingComplete(BindingCompleteEventArgs eventArgs) { var binding = new SubBinding("propertyName", new object(), "dataMember"); int callCount = 0; BindingCompleteEventHandler handler = (sender, e) => { Assert.Equal(binding, sender); Assert.Same(eventArgs, e); callCount++; binding.OnBindingComplete(e); }; binding.BindingComplete += handler; binding.OnBindingComplete(eventArgs); Assert.Equal(1, callCount); }
public void Binding_OnParse_Invoke_CallsParse(bool formattingEnabled, ConvertEventArgs eventArgs, object expectedValue) { var binding = new SubBinding("propertyName", new object(), "dataMember") { FormattingEnabled = formattingEnabled }; // No handler. object oldValue = eventArgs?.Value; binding.OnParse(eventArgs); Assert.Equal(expectedValue, eventArgs?.Value); // Handler. int callCount = 0; ConvertEventHandler handler = (sender, e) => { Assert.Equal(binding, sender); Assert.Same(eventArgs, e); callCount++; }; binding.Parse += handler; if (eventArgs != null) { eventArgs.Value = oldValue; } binding.OnParse(eventArgs); Assert.Equal(expectedValue, eventArgs?.Value); Assert.Equal(1, callCount); // Should not call if the handler is removed. binding.Parse -= handler; if (eventArgs != null) { eventArgs.Value = oldValue; } binding.OnParse(eventArgs); Assert.Equal(expectedValue, eventArgs?.Value); Assert.Equal(1, callCount); }
public void Binding_OnBindingComplete_ThrowsNonCriticalException_SetsCancelToTrue(BindingCompleteEventArgs eventArgs, Exception exception) { var binding = new SubBinding("propertyName", new object(), "dataMember"); int callCount = 0; BindingCompleteEventHandler handler = (sender, e) => { Assert.Equal(binding, sender); Assert.Same(eventArgs, e); callCount++; throw exception; }; binding.BindingComplete += handler; binding.OnBindingComplete(eventArgs); if (eventArgs != null) { Assert.True(eventArgs.Cancel); } Assert.Equal(1, callCount); }