Skip to content

Commit

Permalink
Fix smells and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillGutyrchik committed Aug 5, 2024
1 parent d3d1b66 commit ca1e170
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
4 changes: 2 additions & 2 deletions EasyEplanner.Tests/Editor.Test/ObjectProperty.Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ public void IsDrawOnEplanPage_EmptyObject_ReturnsFalse()
}

[Test]
public void GetObjectToDrawOnEplanPage_EmptyObject_ReturnsNull()
public void GetObjectToDrawOnEplanPage_EmptyObject_ReturnEmty()
{
Assert.IsNull(GetEmptyProperty().GetObjectToDrawOnEplanPage());
CollectionAssert.IsEmpty(GetEmptyProperty().GetObjectToDrawOnEplanPage());
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Editor;
using EplanDevice;
using Moq;
using NUnit.Framework;
Expand Down Expand Up @@ -109,5 +110,40 @@ public void ModifyDevName()
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)
.SetValue(null, DeviceManager.GetInstance());
}

[Test]
public void IsDrawToEplanPage_True()
{
Assert.IsTrue(new ActionParameter("", "").IsDrawOnEplanPage);
}

public void IsDrawToEplanPage_False()
{
var actionParameter = new ActionParameter("ap", "ap");

var dev = new V("OBJ1V1", "+OBJ1-V1", "", 1, "OBJ", 1, "");

var deviceManager = Mock.Of<IDeviceManager>(m =>
m.GetDeviceByEplanName("OBJ1V1") == dev &&
m.GetDeviceIndex("OBJ1V1") == 1 &&
m.GetDeviceByIndex(1) == dev);

typeof(BaseParameter).GetField("deviceManager",
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)
.SetValue(null, deviceManager);

actionParameter.SetNewValue("OBJ1V1");
var res = actionParameter.GetObjectToDrawOnEplanPage();

Assert.Multiple(() =>
{
Assert.AreEqual(dev, res.FirstOrDefault().DrawingDevice);
Assert.AreEqual(DrawInfo.Style.GREEN_BOX, res.FirstOrDefault().DrawingStyle);
});

typeof(BaseParameter).GetField("deviceManager",
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)
.SetValue(null, DeviceManager.GetInstance());
}
}
}
10 changes: 5 additions & 5 deletions src/Editor/ObjectProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Editor
/// </summary>
public class ObjectProperty : ITreeViewItem, IHelperItem
{
public ImageIndexEnum ImageIndex { get; set; } =
public ImageIndexEnum ImageIndex { get; set; } =
ImageIndexEnum.NONE;

/// <param name="name">Имя свойства.</param>
Expand Down Expand Up @@ -108,7 +108,7 @@ public virtual string[] DisplayText
{
if (value.ToString() == defaultValue.ToString())
{
return new string[] { name,
return new string[] { name,
StaticHelper.CommonConst.StubForCells };
}
else
Expand All @@ -128,7 +128,7 @@ public virtual string[] EditText
provider.NumberDecimalSeparator = ".";

double v = (double)value;
return new string[] { "",
return new string[] { "",
string.Format( provider, "{0:0.##}", v ) };
}

Expand Down Expand Up @@ -164,7 +164,7 @@ public virtual bool IsCopyable

public virtual object Copy()
{
if(IsCopyable)
if (IsCopyable)
{
return this;
}
Expand Down Expand Up @@ -335,7 +335,7 @@ public bool IsLocalRestrictionUse

public virtual bool IsDrawOnEplanPage => false;

public virtual List<DrawInfo> GetObjectToDrawOnEplanPage() => null;
public virtual List<DrawInfo> GetObjectToDrawOnEplanPage() => new List<DrawInfo>() { };

public virtual void GetDisplayObjects(out EplanDevice.DeviceType[] devTypes,
out EplanDevice.DeviceSubType[] devSubTypes, out bool displayParameters)
Expand Down
2 changes: 1 addition & 1 deletion src/TechObject/Base/Properties/ActionParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override bool SetNewValue(string newValue)
Parameter = null;

// В случае привязки нескольких устройств (с ФСА) оставляем последнее
newValue = newValue.Trim().Split(' ').Last();
newValue = newValue.Trim().Split(' ').LastOrDefault();
newValue = string.IsNullOrEmpty(newValue) ? "-1" : newValue;

return base.SetNewValue(newValue);
Expand Down

0 comments on commit ca1e170

Please sign in to comment.