public static OneWayUpdater <String> BindTextAsSource(this Control textBox, PropertyLink <String> destinationPropertyLink) { EventLink textChangeEventLinks = new EventLink(textBox, _ControlTextChangedEventInfo); OneWayUpdater <String> binding = new OneWayUpdater <String>(() => textBox.Text, destinationPropertyLink.Set, textChangeEventLinks); return(binding); }
public void ThenCheckSingleModelTransformation(SingleModelTransformationTestModel model) { Assert.AreEqual(1, model.Data); Assert.AreEqual(3, model.Value2); Assert.IsFalse(PropertyLink.From(() => model.Value3).Enabled); }
public void DisabledAttributeTest() { var model = new DisabledAttributeTestModel(); var property = PropertyLink.From(() => model.Value); Assert.IsFalse(property.Enabled); }
public MainWindowViewModel() { InventoryTotalItemView = new ObservableCollection <InventoryItemTotalQuantity>(); PropertyLink.OnObject(this) .Link(vm => vm.NewInventoryItemDescription, "CanExecuteCreateNewInventoryItem") .Link(vm => vm.NewInventoryItemSku, "CanExecuteCreateNewInventoryItem") .Link(vm => vm.SelectedInventoryTotalItemView, "CanExecuteAddQuantity") .Link(vm => vm.QuantityToAddToSelectedItem, "CanExecuteAddQuantity"); }
public void NameAttributeTest() { var model = new NameAttributeTestModel(); var property1 = PropertyLink.From(() => model.Data); var property2 = PropertyLink.From(() => model.Value2); Assert.AreEqual("value", property1.Name); Assert.AreEqual("Value2", property2.Name); }
/// <summary> /// Binds the <see cref="Control.Text"/> property to a given <paramref name="property2"/> in both directions (as a target and destination). /// </summary> /// <param name="textBox"></param> /// <param name="property2"></param> /// <param name="obj2ChangeEvent"></param> /// <returns></returns> public static UpdateLock <String> BindText(this Control textBox, PropertyLink <String> property2, EventLink obj2ChangeEvent) { PropertyLink <String> property1 = new PropertyLink <String>(() => textBox.Text, x => textBox.Text = x); EventLink textChangeEventLinks = new EventLink(textBox, _ControlTextChangedEventInfo); UpdateLock <String> binding = new UpdateLock <String>(property1, textChangeEventLinks, property2, obj2ChangeEvent); return(binding); }
public void NestedModelsTest() { var model = new NestedModelsTestTopModel(); var property1 = PropertyLink.From(() => model.Value1); var property2 = PropertyLink.From(() => model.NestedModel.Value2); Assert.AreEqual(1, property1.Value); Assert.AreEqual(2, property2.Value); }
public UpdateLock(PropertyLink <T> obj1PropertyLink , EventLink obj1EventLink , PropertyLink <T> obj2PropertyLink , EventLink obj2EventLink ) { _Obj1PropertyLink = obj1PropertyLink; _Obj1EventLink = obj1EventLink; _Obj2PropertyLink = obj2PropertyLink; _Obj2EventLink = obj2EventLink; _Obj1EventProxy = _Obj1EventLink?.AddHandler(this.UpdateObj1To2); _Obj2EventProxy = _Obj2EventLink?.AddHandler(this.UpdateObj2To1); }
public BasicMultiplayerMainVM(CommandContainer commandContainer, IEndTurn mainGame, IViewModelData viewModel, BasicData basicData, TestOptions test, IGamePackageResolver resolver ) { CommandContainer = commandContainer; CommandContainer.IsExecuting = true; //has to be proven false. CommandContainer.ManuelFinish = true; _mainGame = mainGame; _viewModel = viewModel; _basicData = basicData; _test = test; _resolver = resolver; _viewModel.PropertyChanged += ViewModelPropertyChange; if (_basicData.MultiPlayer) { _network = Resolve <INetworkMessages>(); } Type type = GetType(); var ourProperties = type.GetPropertiesWithAttribute <VMAttribute>().ToCustomBasicList(); if (ourProperties.Count == 0) { throw new BasicBlankException("There has to be at least one property on the list. Rethink"); } type = _viewModel.GetType(); var vmProperties = type.GetPropertiesWithAttribute <VMAttribute>().ToCustomBasicList(); vmProperties.ForEach(p => { var o = ourProperties.Where(x => x.Name == p.Name).SingleOrDefault(); var v = p; if (o != null) { PropertyLink link = new PropertyLink(); link.VMProperty = v; link.OurProperty = o; _properties.Add(link); //set the values as well. o.SetValue(this, v.GetValue(_viewModel)); } }); }
public void EnabledDisableAttributeTest() { var model = new EnabledDisableAttributeTestModel(); var property = PropertyLink.From(() => model.Value); property.Enabled = true; Assert.IsTrue(property.Enabled); property.Enabled = true; Assert.IsTrue(property.Enabled); property.Enabled = false; Assert.IsFalse(property.Enabled); property.Enabled = false; Assert.IsFalse(property.Enabled); }
public void TestDisable() { //---------------Set up test pack------------------- MyBO.LoadDefaultClassDef(); MyBO bo = new MyBO(); string testValue = TestUtil.GetRandomString(); PropertyLink <string, string> link = new PropertyLink <string, string>(bo, "TestProp", "TestProp2", delegate(string input) { return(input); }); bo.TestProp = testValue; //---------------Assert PreConditions--------------- Assert.AreEqual(testValue, bo.TestProp2); //---------------Execute Test ---------------------- link.Disable(); bo.TestProp = TestUtil.GetRandomString(); //---------------Test Result ----------------------- Assert.AreEqual(testValue, bo.TestProp2); }
public void ComparatorModelArrayNegativeTest() { var modelComparator = new ModelComparator(); var expected = new ModelComparatorTestModel() { Value1 = 1, Value2 = "2" }; var actual = new ModelComparatorTestModel() { Value1 = 2, Value2 = "3" }; PropertyLink.From(() => expected.Value2).Enabled = false; Assert.IsFalse(modelComparator.Compare(new[] { expected }, new[] { actual })); }
public void ComparatorNegativeTest() { var modelComparator = new ModelComparator(); var expected = new ModelComparatorTestModel() { Value1 = 1, Value2 = "2" }; var actual = new ModelComparatorTestModel() { Value1 = 1, Value2 = "3" }; PropertyLink.From(() => expected.Value1).Enabled = false; Assert.IsFalse(modelComparator.Compare(expected, actual)); }
public void SelectProperty() { Actions actions = new Actions(_driver); actions.MoveToElement(PropertyDropDown); actions.Click(); actions.Build().Perform(); System.Threading.Thread.Sleep(200); PropertyLink.Click(); System.Threading.Thread.Sleep(200); // actions.MoveToElement(PropertyLink); // actions.Click(); // actions.Build().Perform(); // actions.SendKeys("247A Great North Road Henderson Auckland"); }
public static OneWayUpdater <String> BindTextAsDestination(this Control textBox, PropertyLink <String> property2, EventLink obj2ChangeEvent) { OneWayUpdater <String> binding = new OneWayUpdater <String>(property2.Get, x => textBox.Text = x, obj2ChangeEvent); return(binding); }
public static UpdateLock <T> Bind <T>(PropertyLink <T> property1, EventLink obj1ChangeEvent, PropertyLink <T> property2, EventLink obj2ChangeEvent) { UpdateLock <T> binding = new UpdateLock <T>(property1, obj1ChangeEvent, property2, obj2ChangeEvent); return(binding); }
public void TestEnable() { //---------------Set up test pack------------------- MyBO.LoadDefaultClassDef(); MyBO bo = new MyBO(); string testValue = TestUtil.GetRandomString(); string testValue2 = TestUtil.GetRandomString(); PropertyLink<string, string> link = new PropertyLink<string, string>(bo, "TestProp", "TestProp2", delegate(string input) { return input; }); link.Disable(); bo.TestProp = testValue; //---------------Assert PreConditions--------------- Assert.AreNotEqual(testValue, bo.TestProp2); //---------------Execute Test ---------------------- bo.TestProp2 = testValue; link.Enable(); bo.TestProp = testValue2; //---------------Test Result ----------------------- Assert.AreEqual(testValue2, bo.TestProp2); }
void AddEventHandlers() { //Binding to Encoding converter core: EncodingConverterCore ECC = Program.ECC; //Bind 'ECC.AutoDetectInputEncoding' to 'chkAutoDetect.Checked': WinFormsHelpers.Bind(new PropertyLink <bool>(() => chkAutoDetect.Checked, x => chkAutoDetect.Checked = x) , new EventLink(chkAutoDetect, nameof(CheckBox.CheckedChanged)) , new PropertyLink <bool>(() => ECC.AutoDetectInputEncoding, x => ECC.AutoDetectInputEncoding = x) , new EventLink(ECC, nameof(ECC.AutoDetectInputEncodingChanged))) .UpdateObj2To1(); //Bind 'ECC.PreferredInputEncoding' to 'txtPreferredInputEncoding': txtPreferredInputEncoding.BindText(new PropertyLink <string>(() => ECC.PreferredInputEncoding, x => ECC.PreferredInputEncoding = x) , new EventLink(ECC, nameof(ECC.PreferredInputEncodingChanged))) .UpdateObj2To1(); //Bind 'ECC.InputFilePath' to 'txtInputPath': txtInputPath.BindText(new PropertyLink <string>(() => ECC.InputFilePath, x => ECC.InputFilePath = x) , new EventLink(ECC, nameof(ECC.InputFilePathChanged))) .UpdateObj2To1(); //Bind 'ECC.OutputFilePath' to 'txtOutputPath': txtOutputPath.BindText(new PropertyLink <string>(() => ECC.OutputFilePath, x => ECC.OutputFilePath = x) , new EventLink(ECC, nameof(ECC.OutputFilePathChanged))) .UpdateObj2To1(); //Bind 'ECC.InputText' to 'tbInputText': _InputTextLink = tbInputText.BindTextAsDestination( () => (!splitContainer1.Panel2Collapsed && File.Exists(ECC.InputFilePath)) ? ECC.InputText : null , new EventLink(ECC, nameof(ECC.InputTextChanged))); _InputTextLink.Update(); //ECC.InputTextChanged += ECC_InputTextChanged; //One way update. //if (File.Exists(ECC.InputFilePath)) //{ // tbInputText.Text = ECC.InputText; //} var text = File.Exists(ECC.InputFilePath) ? ECC.InputText : null; var inputEncodingEventLink = new EventLink(ECC, nameof(ECC.InputEncodingChanged)); //Bind 'ECC.InputEncoding' to 'evInputEncoding.SelectedEncodingInfo': WinFormsHelpers.Bind(new PropertyLink <EncodingInfo>(() => evInputEncoding.SelectedEncodingInfo, x => evInputEncoding.SelectedEncodingInfo = x) , new EventLink(evInputEncoding, nameof(evInputEncoding.SelectedEncodingInfoChanged)) , new PropertyLink <EncodingInfo>(() => encodingInfos?.FirstOrDefault(x => x.CodePage == ECC.InputEncoding.CodePage), x => ECC.InputEncoding = x?.GetEncoding()) , inputEncodingEventLink) .UpdateObj2To1(); //Bind 'ECC.InputEncoding' to 'lblInputEncoding': tsddInputEncoding.BindTextAsDestination(() => ECC.InputEncoding?.EncodingName, inputEncodingEventLink).Update(); //Bind 'ECC.OutputEncoding' to 'evOutputEncoding.SelectedEncodingInfo': var outputEncodingEventLink = new EventLink(ECC, nameof(ECC.OutputEncodingChanged)); WinFormsHelpers.Bind(new PropertyLink <EncodingInfo>(() => evOutputEncoding.SelectedEncodingInfo, x => evOutputEncoding.SelectedEncodingInfo = x) , new EventLink(evOutputEncoding, nameof(evOutputEncoding.SelectedEncodingInfoChanged)) , new PropertyLink <EncodingInfo>(() => encodingInfos?.FirstOrDefault(x => x.CodePage == ECC.OutputEncoding.CodePage), x => ECC.OutputEncoding = x?.GetEncoding()) , outputEncodingEventLink) .UpdateObj2To1(); //Bind 'ECC.OutputEncoding' to 'lblOutputEncoding': tsddOutputEncoding.BindTextAsDestination(() => ECC.OutputEncoding?.EncodingName, outputEncodingEventLink).Update(); txtOutputPathFormat.BindText(new PropertyLink <string>(() => _OFF.FormatString, x => _OFF.FormatString = x) , new EventLink(_OFF, nameof(_OFF.FormatStringChanged))).UpdateObj2To1(); txtCompanionFileSearchPattern.BindText(new PropertyLink <string>(() => _OFF.CompanionFileSearchPattern, x => _OFF.CompanionFileSearchPattern = x) , new EventLink(_OFF, nameof(_OFF.CompanionFileSearchPatternChanged))).UpdateObj2To1(); txtCompanionFile.BindText(new PropertyLink <string>(() => _OFF.CompanionFile, x => _OFF.CompanionFile = x) , new EventLink(_OFF, nameof(_OFF.CompanionFileChanged))).UpdateObj2To1(); //Bind favorite encoding of OutputEncodingsViewer to favorite encoding of InputEncodingsViewer var OutputEncodingFavsPropLink = new PropertyLink <EncodingInfo[]>(() => evOutputEncoding.FavoriteEncodingInfos, x => evOutputEncoding.FavoriteEncodingInfos = x); var evLink = new EventLink(evOutputEncoding, nameof(evOutputEncoding.FavoriteEncodingInfosChanged)); WinFormsHelpers.Bind(OutputEncodingFavsPropLink , evLink , new PropertyLink <EncodingInfo[]>(() => evInputEncoding.FavoriteEncodingInfos, x => evInputEncoding.FavoriteEncodingInfos = x) , new EventLink(evInputEncoding, nameof(evInputEncoding.FavoriteEncodingInfosChanged))) ; //WinFormsHelpers.Bind(OutputEncodingFavsPropLink // , evLink // , new PropertyLink<EncodingsCollection>(() => evInputEncoding.FavoriteEncodingInfos, x => evInputEncoding.FavoriteEncodingInfos = x) // , new EventLink(evInputEncoding, nameof(evInputEncoding.FavoriteEncodingInfosChanged))) // ; //this.gbInput.DragEnter += InputControl_DragEnter; //this.gbInput.DragDrop += InputControl_DragDrop; this.splitContainer1.DragEnter += InputControl_DragEnter; this.splitContainer1.DragDrop += InputControl_DragDrop; this.linkAbout.LinkClicked += this.linkAbout_LinkClicked; this.btnChangeOutputFile.Click += this.btnChangeOutputFile_Click; this.linkLabel1.LinkClicked += this.linkLabel1_LinkClicked; this.btnSave.Click += this.btnSave_Click; this.btnOpen.Click += BtnOpen_Click; this.btnApplyOutputFormatting.Click += BtnApplyOutputFormatting_Click; this.splitContainer1.SplitterMoved += SplitContainer1_SplitterMoved; this.btnTogleSidePanel.Click += BtnTogleSidePanel_Click; this.splitContainer1.Resize += SplitContainer1_Resize; this.Load += MainForm3_Load; this.FormClosed += FormMain_FormClosed; }
void AddEventHandlers() { EncodingConverterCore ECC = Program.ECC; #region Bindings //Binding to Encoding converter core: //Bind 'ECC.AutoDetectInputEncoding' to 'chkAutoDetect.Checked': WinFormsHelpers.Bind(new PropertyLink <bool>(() => chkAutoDetect.Checked, x => chkAutoDetect.Checked = x) , new EventLink(chkAutoDetect, nameof(CheckBox.CheckedChanged)) , new PropertyLink <bool>(() => ECC.AutoDetectInputEncoding, x => ECC.AutoDetectInputEncoding = x) , new EventLink(ECC, nameof(ECC.AutoDetectInputEncodingChanged))) .UpdateObj2To1(); //Bind 'ECC.PreferredInputEncoding' to 'txtPreferredInputEncoding': txtPreferredInputEncoding.BindText(new PropertyLink <string>(() => ECC.PreferredInputEncoding, x => ECC.PreferredInputEncoding = x) , new EventLink(ECC, nameof(ECC.PreferredInputEncodingChanged))) .UpdateObj2To1(); //Bind 'ECC.InputFilePath' to 'txtInputPath': txtInputPath.BindText(new PropertyLink <string>(() => ECC.InputFilePath, x => ECC.InputFilePath = x) , new EventLink(ECC, nameof(ECC.InputFilePathChanged))) .UpdateObj2To1(); //Bind 'ECC.OutputFilePath' to 'txtOutputPath': txtOutputPath.BindText(new PropertyLink <string>(() => ECC.OutputFilePath, (x) => { ECC.OutputFilePath = x; }) , new EventLink(ECC, nameof(ECC.OutputFilePathChanged))) .UpdateObj2To1(); //Bind 'ECC.InputText' to 'tbInputText': _InputTextLink = tbInputText.BindTextAsDestination( () => (!splitContainer1.Panel2Collapsed && File.Exists(ECC.InputFilePath)) ? ECC.InputText : null , new EventLink(ECC, nameof(ECC.InputTextChanged))); _InputTextLink.Update(); //ECC.InputTextChanged += ECC_InputTextChanged; //One way update. //if (File.Exists(ECC.InputFilePath)) //{ // tbInputText.Text = ECC.InputText; //} var text = File.Exists(ECC.InputFilePath) ? ECC.InputText : null; var inputEncodingEventLink = new EventLink(ECC, nameof(ECC.InputEncodingChanged)); //Bind 'ECC.InputEncoding' to 'evInputEncoding.SelectedEncodingInfo': WinFormsHelpers.Bind(new PropertyLink <EncodingInfo>(() => evInputEncoding.SelectedEncodingInfo, x => evInputEncoding.SelectedEncodingInfo = x) , new EventLink(evInputEncoding, nameof(evInputEncoding.SelectedEncodingInfoChanged)) , new PropertyLink <EncodingInfo>(() => encodingInfos?.FirstOrDefault(x => x.CodePage == ECC.InputEncoding?.CodePage), x => ECC.InputEncoding = x?.GetEncoding()) , inputEncodingEventLink) .UpdateObj2To1(); //Bind 'ECC.InputEncoding' to 'lblInputEncoding': tsddInputEncoding.BindTextAsDestination(() => ECC.InputEncoding?.EncodingName, inputEncodingEventLink).Update(); //Bind 'ECC.OutputEncoding' to 'evOutputEncoding.SelectedEncodingInfo' and 'Settings.LastOutputEncoding': Properties.Settings defSet = Properties.Settings.Default; //1- Setup PropertyLink to 'ECC.OutputEncoding': var ECCOutputEncodingPropertyLink = new PropertyLink <Encoding> (() => ECC.OutputEncoding //getter , x => ECC.OutputEncoding = x); //setter //2- Setup EventLink of 'OutputEncodingChanged': var ECCOutputEncodingEventLink = new EventLink(ECC, nameof(ECC.OutputEncodingChanged)); //3- Now make the Bindings: // Bind 'ECC.OutputEncoding' to 'Settings.LastOutputEncoding': WinFormsHelpers.Bind(new PropertyLink <Encoding> (() => encodingInfos?.FirstOrDefault(x => x.CodePage == defSet.LastOutputEncoding)?.GetEncoding() , x => defSet.LastOutputEncoding = x.CodePage) , new EventLink(evOutputEncoding, nameof(evOutputEncoding.SelectedEncodingInfoChanged)) , ECCOutputEncodingPropertyLink , ECCOutputEncodingEventLink) .UpdateObj1To2(); //Update Settings to ECC. // Bind 'ECC.OutputEncoding' to 'evOutputEncoding.SelectedEncodingInfo': //WinFormsHelpers.Bind(new PropertyLink<EncodingInfo>(() => evOutputEncoding.SelectedEncodingInfo, x => evOutputEncoding.SelectedEncodingInfo = x) // , new EventLink(evOutputEncoding, nameof(evOutputEncoding.SelectedEncodingInfoChanged)) // , new PropertyLink<EncodingInfo>(() => encodingInfos?.FirstOrDefault(x => x.CodePage == ECC.OutputEncoding.CodePage), x => ECC.OutputEncoding = x?.GetEncoding()) // , ECCOutputEncodingEventLink) // .UpdateObj2To1(); WinFormsHelpers.Bind(new PropertyLink <Encoding>( () => evOutputEncoding.SelectedEncodingInfo.GetEncoding() , x => evOutputEncoding.SelectedEncodingInfo = encodingInfos?.FirstOrDefault(ei => x?.CodePage == ei.CodePage)) , new EventLink(evOutputEncoding, nameof(evOutputEncoding.SelectedEncodingInfoChanged)) , ECCOutputEncodingPropertyLink , ECCOutputEncodingEventLink) .UpdateObj2To1(); // Bind 'ECC.OutputEncoding' to 'lblOutputEncoding': tsddOutputEncoding.BindTextAsDestination(() => ECC.OutputEncoding?.EncodingName, ECCOutputEncodingEventLink).Update(); txtOutputPathFormat.BindText(new PropertyLink <string>(() => _OPF.FormatString, x => _OPF.FormatString = x) , new EventLink(_OPF, nameof(_OPF.FormatStringChanged))).UpdateObj2To1(); txtCompanionFileSearchPattern.BindText(new PropertyLink <string>(() => _OPF.CompanionFileSearchPattern, x => _OPF.CompanionFileSearchPattern = x) , new EventLink(_OPF, nameof(_OPF.CompanionFileSearchPatternChanged))).UpdateObj2To1(); txtCompanionFile.BindText(new PropertyLink <string>(() => _OPF.CompanionFile, x => _OPF.CompanionFile = x) , new EventLink(_OPF, nameof(_OPF.CompanionFileChanged))).UpdateObj2To1(); //Bind favorite encoding of OutputEncodingsViewer to favorite encoding of InputEncodingsViewer var OutputEncodingFavsPropLink = new PropertyLink <EncodingInfo[]>(() => evOutputEncoding.FavoriteEncodingInfos, x => evOutputEncoding.FavoriteEncodingInfos = x); var evLink = new EventLink(evOutputEncoding, nameof(evOutputEncoding.FavoriteEncodingInfosChanged)); WinFormsHelpers.Bind(OutputEncodingFavsPropLink , evLink , new PropertyLink <EncodingInfo[]>(() => evInputEncoding.FavoriteEncodingInfos, x => evInputEncoding.FavoriteEncodingInfos = x) , new EventLink(evInputEncoding, nameof(evInputEncoding.FavoriteEncodingInfosChanged))) ; //WinFormsHelpers.Bind(OutputEncodingFavsPropLink // , evLink // , new PropertyLink<EncodingsCollection>(() => evInputEncoding.FavoriteEncodingInfos, x => evInputEncoding.FavoriteEncodingInfos = x) // , new EventLink(evInputEncoding, nameof(evInputEncoding.FavoriteEncodingInfosChanged))) // ; #endregion//Bindings ECC.OutputFilePathChanged += ECC_OutputFilePathChanged; this.splitContainer1.AllowDrop = true; this.splitContainer1.DragEnter += InputControl_DragEnter; this.splitContainer1.DragDrop += InputControl_DragDrop; this.linkAbout.LinkClicked += this.linkAbout_LinkClicked; this.btnChangeOutputFile.Click += this.btnChangeOutputFile_Click; this.linkLabelDetectInputEncoding.LinkClicked += this.linkLabelDetectInputEncoding_LinkClicked; this.btnSave.Click += this.btnSave_Click; this.btnOpen.Click += BtnOpen_Click; this.btnApplyOutputFormatting.Click += BtnApplyOutputFormatting_Click; this.Load += MainForm_Load; this.FormClosed += FormMain_FormClosed; this.txtInputPath.TextChanged += TxtPath_TextChanged; this.txtOutputPath.TextChanged += TxtPath_TextChanged; this.txtCompanionFile.TextChanged += TxtPath_TextChanged; ECC.DetectedEncodingsChanged += ECC_DetectedEncodingsChanged; ECC.InputEncodingChanged += ECC_InputEncodingChanged; }