private void InitializeEngine() { String path = Assembly.GetEntryAssembly().Location.Substring(0, Assembly.GetEntryAssembly().Location.LastIndexOf('\\')) + Properties.Settings.Default.EnginesPath; var engines = new List<Engine>(); try { engines = Directory.GetFiles(path, "*.exe") .Select(s => new Engine(s)).ToList(); } catch { Directory.CreateDirectory("Engines"); } engines.Add(new Engine("zzz", "Browse...")); EnginesCategory.Items.SortDescriptions.Add(new SortDescription("Path", ListSortDirection.Ascending)); EnginesCategory.ItemsSource = engines; if (engines.Count > 1) EnginesGallery.SelectedItem = EnginesCategory.Items[0]; var b = new Binding("Depth"); var v = new ExceptionValidationRule(); Depth.DataContext = ChessEngine; b.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; b.ValidationRules.Add(v); Depth.SetBinding(TextBox.TextProperty, b); BestMove.DataContext = ChessEngine; BestMove.SetBinding(ContentProperty, "State"); }
public void ConverterTest() { ValidationErrorsConverter converter = ValidationErrorsConverter.Default; Assert.AreEqual(converter, ValidationErrorsConverter.Default); AssertHelper.ExpectedException<NotSupportedException>(() => converter.ConvertBack(null, (Type[])null, null, null)); Assert.AreEqual(DependencyProperty.UnsetValue, converter.Convert((object[])null, null, null, null)); Assert.AreEqual(DependencyProperty.UnsetValue, converter.Convert(new[] { "WrongType" }, null, null, null)); List<ValidationError> validationErrors = new List<ValidationError>(); Assert.AreEqual("", converter.Convert(new[] { validationErrors }, null, null, null)); ExceptionValidationRule rule = new ExceptionValidationRule(); validationErrors.Add(new ValidationError(rule, new object(), "First error message", null)); Assert.AreEqual("First error message", converter.Convert(new[] { validationErrors }, null, null, null)); validationErrors.Add(new ValidationError(rule, new object(), "Second error message", null)); Assert.AreEqual("First error message" + Environment.NewLine + "Second error message", converter.Convert(new[] { validationErrors }, null, null, null)); // Call the obsolete methods #pragma warning disable 618 AssertHelper.ExpectedException<NotSupportedException>(() => converter.ConvertBack(null, (Type)null, null, null)); validationErrors = new List<ValidationError>(); validationErrors.Add(new ValidationError(rule, new object(), "First error message", null)); Assert.AreEqual("First error message", converter.Convert(validationErrors, null, null, null)); #pragma warning restore 618 }
public void ConvertTest() { var converter = ValidationErrorsConverter.Default; Assert.AreEqual(DependencyProperty.UnsetValue, converter.Convert((object[])null, null, null, null)); Assert.AreEqual(DependencyProperty.UnsetValue, converter.Convert(new[] { "WrongType" }, null, null, null)); List<ValidationError> validationErrors = new List<ValidationError>(); Assert.AreEqual("", converter.Convert(new[] { validationErrors }, null, null, null)); ExceptionValidationRule rule = new ExceptionValidationRule(); validationErrors.Add(new ValidationError(rule, new object(), "First error message", null)); Assert.AreEqual("First error message", converter.Convert(new[] { validationErrors }, null, null, null)); validationErrors.Add(new ValidationError(rule, new object(), "Second error message", null)); Assert.AreEqual("First error message" + Environment.NewLine + "Second error message", converter.Convert(new[] { validationErrors }, null, null, null)); }
public void ConverterTest() { ValidationErrorsConverter converter = ValidationErrorsConverter.Default; Assert.AreEqual(converter, ValidationErrorsConverter.Default); AssertHelper.ExpectedException<NotSupportedException>(() => converter.ConvertBack(null, null, null, null)); Assert.AreEqual(DependencyProperty.UnsetValue, converter.Convert(null, null, null, null)); Assert.AreEqual(DependencyProperty.UnsetValue, converter.Convert("WrongType", null, null, null)); List<ValidationError> validationErrors = new List<ValidationError>(); Assert.AreEqual("", converter.Convert(validationErrors, null, null, null)); ExceptionValidationRule rule = new ExceptionValidationRule(); validationErrors.Add(new ValidationError(rule, new object(), "First error message", null)); Assert.AreEqual("First error message", converter.Convert(validationErrors, null, null, null)); validationErrors.Add(new ValidationError(rule, new object(), "Second error message", null)); Assert.AreEqual("First error message" + Environment.NewLine + "Second error message", converter.Convert(validationErrors, null, null, null)); }
private void SetBindingsSearch(Object context) { var b = new Binding("FEN"); var v = new ExceptionValidationRule(); b.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; b.ValidationRules.Add(v); FENSearch.DataContext = context; FENSearch.SetBinding(TextBox.TextProperty, b); }