public void TestIncorrectPin() { var targetPin = new[] { '1', '2', '3', '4' }; var view = new PinView { PinLength = 4, Validator = (IList <char> arg) => Enumerable.SequenceEqual(targetPin, arg) }; PinItemView findButton(string arg) { return((PinItemView)(view).Children.First(c => c is PinItemView btn && btn.Text == arg)); } Assert.Raises <EventArgs>( (EventHandler <EventArgs> obj) => view.Error += obj, (EventHandler <EventArgs> obj) => view.Error -= obj, () => { foreach (char next in targetPin.Reverse()) { PinItemView btn = findButton(next.ToString()); btn.Command.Execute(btn.CommandParameter); } } ); }
public void TestCorrectPin_AllSymbolsFilled() { var targetPin = new[] { '1', '2', '3', '4' }; var view = new PinView { PinLength = 4, Validator = (IList <char> arg) => Enumerable.SequenceEqual(targetPin, arg), ClearAfterSuccess = false }; foreach (char next in targetPin) { PinItemView btn = FindButton(view, next.ToString()); btn.Command.Execute(btn.CommandParameter); } var sl = (StackLayout)(view).Children.First(c => c is StackLayout); foreach (View child in sl.Children) { var cv = (CircleView)child; Assert.NotNull(cv); Assert.True(cv.IsFilledUp); } }
public void TestCorrectPin() { var targetPin = new[] { '1', '2', '3', '4' }; var viewModel = new PinViewModel { TargetPinLength = 4, ValidatorFunc = (IList <char> arg) => Enumerable.SequenceEqual(targetPin, arg) }; var view = new PinView { BindingContext = viewModel }; Func <string, PinItemView> findButton = (string arg) => { return((PinItemView)((Grid)view.Content).Children.First(c => c is PinItemView btn && btn.Text == arg)); }; Assert.Raises <EventArgs>( (EventHandler <EventArgs> obj) => viewModel.Success += obj, (EventHandler <EventArgs> obj) => viewModel.Success -= obj, () => { foreach (char next in targetPin) { PinItemView btn = findButton(next.ToString()); btn.Command.Execute(btn.CommandParameter); } } ); }
public void TestCommandParameterProperty() { var view = new PinItemView(); string expectedValue = Guid.NewGuid().ToString(); Assert.PropertyChanged(view, PinItemView.CommandParameterProperty.PropertyName, () => view.CommandParameter = expectedValue); Assert.Same(expectedValue, view.CommandParameter); }
public void TestCommandProperty() { var view = new PinItemView(); Command expectedValue = new Command((obj) => {}); Assert.PropertyChanged(view, PinItemView.CommandProperty.PropertyName, () => view.Command = expectedValue); Assert.Same(expectedValue, view.Command); }
public void TestTextProperty() { var view = new PinItemView(); string expectedValue = Guid.NewGuid().ToString(); Assert.PropertyChanged(view, PinItemView.TextProperty.PropertyName, () => view.Text = expectedValue); Assert.Same(expectedValue, view.Text); }
public void TestRippleColorProperty() { var view = new PinItemView(); var expectedValue = Color.LightCyan; Assert.PropertyChanged(view, PinItemView.RippleColorProperty.PropertyName, () => view.RippleColor = expectedValue); Assert.Equal(expectedValue, view.RippleColor); }
public void TestBorderColorProperty() { var view = new PinItemView(); var expectedValue = Color.DarkRed; Assert.PropertyChanged(view, PinItemView.BorderColorProperty.PropertyName, () => view.BorderColor = expectedValue); Assert.Equal(expectedValue, view.BorderColor); }
public void TestColorProperty() { var view = new PinItemView(); var expectedValue = Color.Yellow; Assert.PropertyChanged(view, PinItemView.ColorProperty.PropertyName, () => view.Color = expectedValue); Assert.Equal(expectedValue, view.Color); }
public void TestSuccessCommand() { bool invoked = false; var targetPin = new[] { '1', '2', '3', '4' }; var view = new PinView { PinLength = 4, Validator = (IList <char> arg) => Enumerable.SequenceEqual(targetPin, arg), SuccessCommand = new Command(() => invoked = true) }; foreach (char next in targetPin) { PinItemView btn = FindButton(view, next.ToString()); btn.Command.Execute(btn.CommandParameter); } Assert.True(invoked); }
public void TestCorrectPin() { var targetPin = new[] { '1', '2', '3', '4' }; var view = new PinView { PinLength = 4, Validator = (IList <char> arg) => Enumerable.SequenceEqual(targetPin, arg) }; Assert.Raises <EventArgs>( (EventHandler <EventArgs> obj) => view.Success += obj, (EventHandler <EventArgs> obj) => view.Success -= obj, () => { foreach (char next in targetPin) { PinItemView btn = FindButton(view, next.ToString()); btn.Command.Execute(btn.CommandParameter); } } ); }