Skip to content

Commit

Permalink
renamed component class to component definition (#634)
Browse files Browse the repository at this point in the history
Only rename
  • Loading branch information
mizrael authored Apr 12, 2024
1 parent 5aa975a commit bd3b001
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/Persistence.Tests/Templates/ControlFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void CreateComponent_ShouldCreateValidInstance(string componentType, stri
var sut = new ControlFactory(ControlTemplateStore);

var result = sut.Create("MyComponent1", componentType);
result.Should().NotBeNull().And.BeAssignableTo<Component>();
result.Should().NotBeNull().And.BeAssignableTo<ComponentDefinition>();
result.Name.Should().Be("MyComponent1");
result.Template.Should().NotBeNull();
result.Template.Id.Should().Be(expectedTemplateId);
Expand Down
2 changes: 1 addition & 1 deletion src/Persistence.Tests/Yaml/DeserializeComponentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void Deserialize_Component_Should_Succeed(string path, bool isControlIden
using var yamlReader = new StreamReader(yamlStream);

// Act
var component = deserializer.Deserialize<Control>(yamlReader) as Component;
var component = deserializer.Deserialize<Control>(yamlReader) as ComponentDefinition;
if (component == null)
throw new InvalidOperationException("Failed to deserialize component");

Expand Down
4 changes: 2 additions & 2 deletions src/Persistence.Tests/Yaml/DeserializerValidTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public void Deserialize_Component_ShouldSucceed(
using var yamlReader = new StreamReader(yamlStream);

// Act
var component = deserializer.Deserialize<Component>(yamlReader);
var component = deserializer.Deserialize<ComponentDefinition>(yamlReader);

// Assert
component.Name.Should().Be(expectedName);
Expand Down Expand Up @@ -442,7 +442,7 @@ public void Deserialize_ShouldParseYamlForComponentCustomProperties(CustomProper
var expectedYaml = File.ReadAllText(GetTestFilePath(yamlFile, isControlIdentifiers));
var deserializer = CreateDeserializer(isControlIdentifiers);

var component = deserializer.Deserialize<Component>(expectedYaml);
var component = deserializer.Deserialize<ComponentDefinition>(expectedYaml);
component.Should().NotBeNull();
component!.CustomProperties.Should().NotBeNull()
.And.HaveCount(expectedCustomProperties.Length);
Expand Down
4 changes: 2 additions & 2 deletions src/Persistence.Tests/Yaml/ValidSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public void Should_Serialize_List_Of_Controls(string expectedPath, bool isContro
[DynamicData(nameof(ComponentCustomProperties_Data), typeof(TestBase))]
public void Serialize_ShouldCreateValidYamlForComponentCustomProperties(CustomProperty[] customProperties, string expectedYamlFile, bool isControlIdentifiers)
{
var component = ControlFactory.Create("Component1", "Component") as Component;
var component = ControlFactory.Create("Component1", "Component") as ComponentDefinition;
component.Should().NotBeNull();
component!.CustomProperties.Should().NotBeNull();
foreach (var prop in customProperties)
Expand All @@ -301,7 +301,7 @@ public void Serialize_ShouldCreateValidYamlForComponentCustomProperties(CustomPr
[DataRow("", true, "Control: Component\nName: Component1\nAccessAppScope: true\n")]
public void Serialize_ShouldCreateValidYamlForComponent(string description, bool accessAppScope, string expectedYaml)
{
var component = (Component)ControlFactory.Create("Component1", "Component");
var component = (ComponentDefinition)ControlFactory.Create("Component1", "Component");
component.Should().NotBeNull();
component.Description = description;
component.AccessAppScope = accessAppScope;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace Microsoft.PowerPlatform.PowerApps.Persistence.Models;

[FirstClass(templateName: BuiltInTemplates.CommandComponent)]
[YamlSerializable]
public record CommandComponent : Component
public record CommandComponentDefinition : ComponentDefinition
{
[SetsRequiredMembers]
public CommandComponent(string name, string variant, IControlTemplateStore controlTemplateStore)
public CommandComponentDefinition(string name, string variant, IControlTemplateStore controlTemplateStore)
{
Name = name;
Variant = variant;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ namespace Microsoft.PowerPlatform.PowerApps.Persistence.Models;
/// </summary>
[FirstClass(templateName: BuiltInTemplates.Component)]
[YamlSerializable]
public record Component : Control, IConvertible
public record ComponentDefinition : Control, IConvertible
{
protected Component() { }
protected ComponentDefinition() { }

/// <summary>
/// Default constructor.
/// </summary>
[SetsRequiredMembers]
public Component(string name, string variant, IControlTemplateStore controlTemplateStore)
public ComponentDefinition(string name, string variant, IControlTemplateStore controlTemplateStore)
{
Name = name;
Variant = variant;
Expand Down Expand Up @@ -69,57 +69,57 @@ public TypeCode GetTypeCode()

public bool ToBoolean(IFormatProvider? provider)
{
throw new NotSupportedException($"Cannot covert {typeof(Component)} to {typeof(bool)}");
throw new NotSupportedException($"Cannot covert {typeof(ComponentDefinition)} to {typeof(bool)}");
}

public byte ToByte(IFormatProvider? provider)
{
throw new NotSupportedException($"Cannot covert {typeof(Component)} to {typeof(byte)}");
throw new NotSupportedException($"Cannot covert {typeof(ComponentDefinition)} to {typeof(byte)}");
}

public char ToChar(IFormatProvider? provider)
{
throw new NotSupportedException($"Cannot covert {typeof(Component)} to {typeof(char)}");
throw new NotSupportedException($"Cannot covert {typeof(ComponentDefinition)} to {typeof(char)}");
}

public DateTime ToDateTime(IFormatProvider? provider)
{
throw new NotSupportedException($"Cannot covert {typeof(Component)} to {typeof(DateTime)}");
throw new NotSupportedException($"Cannot covert {typeof(ComponentDefinition)} to {typeof(DateTime)}");
}

public decimal ToDecimal(IFormatProvider? provider)
{
throw new NotSupportedException($"Cannot covert {typeof(Component)} to {typeof(decimal)}");
throw new NotSupportedException($"Cannot covert {typeof(ComponentDefinition)} to {typeof(decimal)}");
}

public double ToDouble(IFormatProvider? provider)
{
throw new NotSupportedException($"Cannot covert {typeof(Component)} to {typeof(double)}");
throw new NotSupportedException($"Cannot covert {typeof(ComponentDefinition)} to {typeof(double)}");
}

public short ToInt16(IFormatProvider? provider)
{
throw new NotSupportedException($"Cannot covert {typeof(Component)} to {typeof(short)}");
throw new NotSupportedException($"Cannot covert {typeof(ComponentDefinition)} to {typeof(short)}");
}

public int ToInt32(IFormatProvider? provider)
{
throw new NotSupportedException($"Cannot covert {typeof(Component)} to {typeof(int)}");
throw new NotSupportedException($"Cannot covert {typeof(ComponentDefinition)} to {typeof(int)}");
}

public long ToInt64(IFormatProvider? provider)
{
throw new NotSupportedException($"Cannot covert {typeof(Component)} to {typeof(long)}");
throw new NotSupportedException($"Cannot covert {typeof(ComponentDefinition)} to {typeof(long)}");
}

public sbyte ToSByte(IFormatProvider? provider)
{
throw new NotSupportedException($"Cannot covert {typeof(Component)} to {typeof(sbyte)}");
throw new NotSupportedException($"Cannot covert {typeof(ComponentDefinition)} to {typeof(sbyte)}");
}

public float ToSingle(IFormatProvider? provider)
{
throw new NotSupportedException($"Cannot covert {typeof(Component)} to {typeof(float)}");
throw new NotSupportedException($"Cannot covert {typeof(ComponentDefinition)} to {typeof(float)}");
}

public string ToString(IFormatProvider? provider)
Expand All @@ -129,22 +129,22 @@ public string ToString(IFormatProvider? provider)

public object ToType(Type conversionType, IFormatProvider? provider)
{
throw new NotSupportedException($"Cannot covert {typeof(Component)} to {conversionType.Name}");
throw new NotSupportedException($"Cannot covert {typeof(ComponentDefinition)} to {conversionType.Name}");
}

public ushort ToUInt16(IFormatProvider? provider)
{
throw new NotSupportedException($"Cannot covert {typeof(Component)} to {typeof(ushort)}");
throw new NotSupportedException($"Cannot covert {typeof(ComponentDefinition)} to {typeof(ushort)}");
}

public uint ToUInt32(IFormatProvider? provider)
{
throw new NotSupportedException($"Cannot covert {typeof(Component)} to {typeof(uint)}");
throw new NotSupportedException($"Cannot covert {typeof(ComponentDefinition)} to {typeof(uint)}");
}

public ulong ToUInt64(IFormatProvider? provider)
{
throw new NotSupportedException($"Cannot covert {typeof(Component)} to {typeof(ulong)}");
throw new NotSupportedException($"Cannot covert {typeof(ComponentDefinition)} to {typeof(ulong)}");
}

#endregion
Expand Down
4 changes: 2 additions & 2 deletions src/Persistence/Yaml/AppConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ void IYamlTypeConverter.WriteYaml(IEmitter emitter, object? value, Type type)
if (value == null)
return;

var component = ((Component)value).BeforeSerialize<Component>();
var component = ((ComponentDefinition)value).BeforeSerialize<ComponentDefinition>();
WriteYamlInternal(emitter, component, type);

if (component.CustomProperties != null && component.CustomProperties.Count > 0)
{
emitter.Emit(new YamlDotNet.Core.Events.Scalar(nameof(Component.CustomProperties)));
emitter.Emit(new YamlDotNet.Core.Events.Scalar(nameof(ComponentDefinition.CustomProperties)));
ValueSerializer!.SerializeValue(emitter, component.CustomProperties, typeof(CustomPropertiesCollection));
}

Expand Down
12 changes: 6 additions & 6 deletions src/Persistence/Yaml/ComponentConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public ComponentConverter(IControlFactory controlFactory) : base(controlFactory)

bool IYamlTypeConverter.Accepts(Type type)
{
return type == typeof(Component);
return type == typeof(ComponentDefinition);
}

object? IYamlTypeConverter.ReadYaml(IParser parser, Type type)
Expand All @@ -29,7 +29,7 @@ bool IYamlTypeConverter.Accepts(Type type)

public override object? ReadKey(IParser parser, string key)
{
if (key == nameof(Component.CustomProperties))
if (key == nameof(ComponentDefinition.CustomProperties))
{
using var serializerState = new SerializerState();
return ValueDeserializer!.DeserializeValue(parser, typeof(List<CustomProperty>), serializerState, ValueDeserializer);
Expand All @@ -43,20 +43,20 @@ void IYamlTypeConverter.WriteYaml(IEmitter emitter, object? value, Type type)
if (value == null)
return;

var component = ((Component)value).BeforeSerialize();
var component = ((ComponentDefinition)value).BeforeSerialize();
WriteYamlInternal(emitter, component, type);

emitter.Emit(nameof(Component.Description), component.Description);
emitter.Emit(nameof(ComponentDefinition.Description), component.Description);

if (component.AccessAppScope)
{
emitter.Emit(new Scalar(nameof(Component.AccessAppScope)));
emitter.Emit(new Scalar(nameof(ComponentDefinition.AccessAppScope)));
ValueSerializer!.SerializeValue(emitter, component.AccessAppScope, typeof(bool));
}

if (component.CustomProperties != null && component.CustomProperties.Count > 0)
{
emitter.Emit(new Scalar(nameof(Component.CustomProperties)));
emitter.Emit(new Scalar(nameof(ComponentDefinition.CustomProperties)));
ValueSerializer!.SerializeValue(emitter, component.CustomProperties, typeof(IList<CustomProperty>));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Persistence/Yaml/ControlConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public bool Accepts(Type type)
using var serializerState = new SerializerState();
value = ValueDeserializer!.DeserializeValue(parser, typeof(List<Control>), serializerState, ValueDeserializer);
}
else if (key.Value == nameof(Component.CustomProperties))
else if (key.Value == nameof(ComponentDefinition.CustomProperties))
{
using var serializerState = new SerializerState();
value = ValueDeserializer!.DeserializeValue(parser, typeof(List<CustomProperty>), serializerState, ValueDeserializer);
Expand Down

0 comments on commit bd3b001

Please sign in to comment.