Skip to content

Commit

Permalink
Added type to control
Browse files Browse the repository at this point in the history
  • Loading branch information
anpetroc committed Jan 22, 2024
1 parent 123b84e commit ba33231
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
9 changes: 3 additions & 6 deletions src/PAModel/Model/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Licensed under the MIT License.

using System.Diagnostics;
using System.Text.Json.Serialization;
using Microsoft.PowerPlatform.Formulas.Tools.JsonConverters;
using YamlDotNet.Serialization;

namespace Microsoft.PowerPlatform.Formulas.Tools.Model;
Expand All @@ -20,6 +18,7 @@ public Control(ControlEditorState editorState)
{
EditorState = editorState ?? throw new ArgumentNullException(nameof(editorState));
Name = editorState.Name;
Type = editorState.Type;

if (editorState.Children != null)
{
Expand All @@ -38,10 +37,8 @@ public Control(ControlEditorState editorState)

public string Name { get; init; }

public string Type { get; set; }

[JsonConverter(typeof(JsonDoubleToIntConverter))]
public int Index { get; set; }
[YamlMember(Alias = "Control")]
public string Type { get; init; }

public IList<Control> Controls { get; init; }

Expand Down
8 changes: 8 additions & 0 deletions src/PAModel/Model/ControlEditorState.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Text.Json.Serialization;
using Microsoft.PowerPlatform.Formulas.Tools.JsonConverters;

namespace Microsoft.PowerPlatform.Formulas.Tools.Model;

public record ControlEditorState
{
public string Name { get; init; }

public string Type { get; set; }

[JsonConverter(typeof(JsonDoubleToIntConverter))]
public int Index { get; set; }

public ControlEditorState[] Children { get; set; }

public IList<RuleEditorState> Rules { get; init; }
Expand Down
9 changes: 6 additions & 3 deletions src/PAModelTests/MsApp/MsappArchiveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ public void AddEntryTests(string[] entries)
}

[TestMethod]
[DataRow(@"Apps/WithYaml/HelloWorld.msapp", 14, 2, "HelloScreen", 8)]
[DataRow(@"Apps/AppWithLabel.msapp", 11, 2, "Screen1", 8)]
public void GetTopLevelControlsTests(string testFile, int allEntriesCount, int controlsCount, string topLevelControlName, int topLevelRulesCount)
[DataRow(@"Apps/WithYaml/HelloWorld.msapp", 14, 2, "HelloScreen", "screen", 8)]
[DataRow(@"Apps/AppWithLabel.msapp", 11, 2, "Screen1", "ControlInfo", 8)]
public void GetTopLevelControlsTests(string testFile, int allEntriesCount, int controlsCount,
string topLevelControlName, string topLevelControlType,
int topLevelRulesCount)
{
// Arrange: Create new ZipArchive in memory
using var msappArchive = new MsappArchive(testFile);
Expand All @@ -88,5 +90,6 @@ public void GetTopLevelControlsTests(string testFile, int allEntriesCount, int c

var topLevelControl = msappArchive.TopLevelControls.Single(c => c.Name == topLevelControlName);
topLevelControl.EditorState.Rules.Count.Should().Be(topLevelRulesCount);
topLevelControl.Type.Should().Be(topLevelControlType);
}
}

0 comments on commit ba33231

Please sign in to comment.