public void GeneratePageObject_WhenHavingUiObjectWithOptimalThatHaveParent_ShouldGenerateCorrectAssignStatement() { var parentNode = new Node(new XElement("node", new XAttribute("class", "myClass"), new XAttribute("package", "package")), null); var mainNode = new Node(new XElement("node", new XAttribute("class", "myClass"), new XAttribute("resource-id", "myResourceId")), parentNode); var pageObjectInfo = new UiObjectInfo { Name = "myObject", Node = mainNode, AutoSelectedWith = new AutoSelectedWith { Node = mainNode, Withs = new List <AttributeTags> { AttributeTags.Class, AttributeTags.ResourceId }, Parent = new AutoSelectedWith { Node = parentNode, Withs = new List <AttributeTags> { AttributeTags.Package } } } }; var code = _codeService.GeneratePageObject("test", "test", new List <UiObjectInfo> { pageObjectInfo }, false); Assert.IsTrue(code.Contains("n => n.Parent?.Package == \"package\" && n.Class == \"myClass\" && n.ResourceId == \"myResourceId\"")); }
private IEnumerable <IArgument> GenerateWithArgument(UiObjectInfo uiObjectInfo) { var arguments = new List <IArgument>(); IList <AttributeTags> withs; if (uiObjectInfo.AutoSelectedWith != null) { if (uiObjectInfo.AutoSelectedWith.Parent == null) { withs = uiObjectInfo.AutoSelectedWith.Withs; } else { return(GenerateAutoSelectedWiths(uiObjectInfo.AutoSelectedWith)); } } else { withs = uiObjectInfo.FindWith; } foreach (var with in withs) { var value = GetNodeValue(uiObjectInfo.Node, with); var valueArgument = with == AttributeTags.Index ? new ValueArgument(int.Parse(value)) : new ValueArgument(value); arguments.Add(new ReferenceArgument(new VariableReference("With", new MethodReference(with.ToString(), new[] { valueArgument })))); } return(arguments); }
public WithDialog(UiObjectInfo uiObjectInfo, IList <Node> nodes) { InitializeComponent(); var viewModel = DataContext as WithViewModel; viewModel.SetCurrentUiObjectInfo(uiObjectInfo, nodes); viewModel.CloseWindow += CloseWindow; }
private void DeleteUiObjectInfo(UiObjectInfo uiObjectInfo) { PageObject.UiObjectInfos.Remove(uiObjectInfo); MessengerInstance.Send(new UiObjectInfoRemovedMessage { UiObjectInfo = uiObjectInfo }); SendPageObjectChanged(); }
public void SetCurrentUiObjectInfo(UiObjectInfo uiObjectInfo, IList <Node> allNodes) { _allNodes = new List <Node>(allNodes); UiObjectInfo = uiObjectInfo; UseUniqueWiths = uiObjectInfo.AutoSelectedWith != null; NotUsedWiths.Clear(); UsedWiths.Clear(); LoadWiths(); LoadAttributes(); }
private Attribute GenerateAttribute(UiObjectInfo pageObjectUiNode) { var with = pageObjectUiNode.AutoSelectedWith?.Withs[0] ?? pageObjectUiNode.FindWith[0]; var name = Enum.GetName(typeof(AttributeTags), with); var arguments = new List <IArgument> { new VariableArgument($"AttributeTags.{name}", "with"), new ValueArgument(GetNodeValue(pageObjectUiNode.Node, with), StringType.Normal, "value") }; return(new Attribute("Create", arguments)); }
public void GeneratePageObject_WhenHavingUiObjectWithOneAttribueAndShouldGenerateWithAttributes_ShouldGenerateCorrectAssignStatement() { var pageObjectInfo = new UiObjectInfo { Name = "myObject", Node = new Node(new XElement("node", new XAttribute("class", "myClass")), null), FindWith = new List <AttributeTags> { AttributeTags.Class, } }; var code = _codeService.GeneratePageObject("test", "test", new List <UiObjectInfo> { pageObjectInfo }, true); Assert.IsTrue(code.Contains("[Create(with: AttributeTags.Class, value: \"myClass\")]")); }
public void GeneratePageObject_WhenHavingUiObjectWithTwoAttributes_ShouldGenerateCorrectAssignStatement() { var pageObjectInfo = new UiObjectInfo { Name = "myObject", Node = new Node(new XElement("node", new XAttribute("class", "myClass"), new XAttribute("resource-id", "myResourceId")), null), FindWith = new List <AttributeTags> { AttributeTags.Class, AttributeTags.ResourceId } }; var code = _codeService.GeneratePageObject("test", "test", new List <UiObjectInfo> { pageObjectInfo }, false); Assert.IsTrue(code.Contains("CreateUiObject(With.Class(\"myClass\"), With.ResourceId(\"myResourceId\"));")); }
private void Save() { UiObjectInfo.FindWith.Clear(); foreach (var with in UsedWiths) { UiObjectInfo.FindWith.Add(with); } if (UseUniqueWiths) { UiObjectInfo.AutoSelectedWith = _uniqueWithFinderService.GetUniqueWiths(UiObjectInfo.Node, _allNodes, false); } else { UiObjectInfo.AutoSelectedWith = null; } UiObjectInfo.UpdateDisplayName(); Close(); }
private (Field field, StatementSyntax statement) GenerateUiObject(UiObjectInfo pageObjectUiNode, bool useAttribute) { var attributes = new List <Attribute>(); StatementSyntax statement = null; if (useAttribute && ((pageObjectUiNode.AutoSelectedWith != null && pageObjectUiNode.AutoSelectedWith.Withs.Count == 1) || pageObjectUiNode.FindWith.Count == 1)) { attributes.Add(GenerateAttribute(pageObjectUiNode)); } else { statement = Statement.Declaration.Assign( pageObjectUiNode.Name, new VariableReference(DeviceName, new MemberReference("Ui", new MethodReference("CreateUiObject", GenerateWithArgument(pageObjectUiNode))))); } var field = new Field(pageObjectUiNode.Name, typeof(UiObject), new[] { Modifiers.Private }, attributes); return(field, statement); }
public bool AddNode(Node node) { var name = _dialogService.ShowNameDialog(); if (!string.IsNullOrEmpty(name)) { var uiNodeInfo = new UiObjectInfo { Name = name, Node = node, FindWith = new List <AttributeTags>(), AutoSelectedWith = _uniqueWithFinderService.GetUniqueWiths(node, _topNode.AllNodes(), false), DisplayName = "Automatic" }; MessengerInstance.Send(new AddUiObjectInfoMessage { UiNodeInfo = uiNodeInfo }); return(true); } return(false); }
public void SetUp() { _uiObjectInfo = new UiObjectInfo(); _withDialog = new WithDialog(_uiObjectInfo, new List <Node>()); }
private void EditWiths(UiObjectInfo obj) { _dialogService.ShowWithDialog(obj, _topNode.AllNodes()); SendPageObjectChanged(); }
/// <summary> /// Show the edit with dialog /// </summary> /// <param name="uiObjectInfo">UiObjected to edit withs for</param> public void ShowWithDialog(UiObjectInfo uiObjectInfo, IList <Node> nodes) { var dialog = new WithDialog(uiObjectInfo, nodes); dialog.ShowDialog(); }
public void SetUp() { _uiObjectInfo = new UiObjectInfo(); }