Question: Write a Junit test for the following source code: using System.Linq; using Xamarin.Forms; namespace Covid19Radar.Behaviors { public class NumberOnlyBehavior : Behavior { protected override void
Write a Junit test for the following source code: using System.Linq; using Xamarin.Forms; namespace Covid19Radar.Behaviors { public class NumberOnlyBehavior : Behavior { protected override void OnAttachedTo(Entry entry) { entry.TextChanged += OnEntryTextChanged; base.OnAttachedTo(entry); } protected override void OnDetachingFrom(Entry entry) { entry.TextChanged -= OnEntryTextChanged; base.OnDetachingFrom(entry); } private static void OnEntryTextChanged(object sender, TextChangedEventArgs args) { if (!string.IsNullOrWhiteSpace(args.NewTextValue)) { char[] newTextArray = args.NewTextValue.ToCharArray(); bool isNumberOnly = newTextArray.All(x => char.IsDigit(x)); if (isNumberOnly) { ((Entry)sender).Text = args.NewTextValue; } else { ((Entry)sender).Text = args.OldTextValue; } } } } }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
