Skip to content

Commit 03c07fb

Browse files
committed
DsmViewer: IAction constructors and tests
Add IActionContext parameter to Iaction implementing constructors. Use argument list instead of object[] for IAction constructor arguments. Implement not yet implemented IAction tests. Tests construct IActions using Activator.CreateInstance instead of new where the viewer does so.
1 parent 442dd42 commit 03c07fb

25 files changed

+235
-215
lines changed

DsmSuite.DsmViewer.Application.Test/Actions/Element/ElementChangeNameActionTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Moq;
44
using System.Collections.Generic;
55
using DsmSuite.DsmViewer.Application.Actions.Element;
6+
using System;
67

78
namespace DsmSuite.DsmViewer.Application.Test.Actions.Element
89
{
@@ -59,8 +60,8 @@ public void WhenUndoActionThenElementNameIsRevertedDataModel()
5960
[TestMethod]
6061
public void GivenLoadedActionWhenGettingDataThenActionAttributesMatch()
6162
{
62-
object[] args = { _model.Object, _data };
63-
ElementChangeNameAction action = new ElementChangeNameAction(args);
63+
object[] args = { _model.Object, null, _data };
64+
ElementChangeNameAction action = Activator.CreateInstance(typeof(ElementChangeNameAction), args) as ElementChangeNameAction;
6465

6566
Assert.AreEqual(3, action.Data.Count);
6667
Assert.AreEqual(ElementId.ToString(), _data["element"]);

DsmSuite.DsmViewer.Application.Test/Actions/Element/ElementChangeParentActionTest.cs

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Moq;
44
using System.Collections.Generic;
55
using DsmSuite.DsmViewer.Application.Actions.Element;
6+
using System;
67

78
namespace DsmSuite.DsmViewer.Application.Test.Actions.Element
89
{
@@ -24,7 +25,7 @@ public class ElementChangeParentActionTest
2425
private const int NewIndex = 5;
2526

2627
private const string OldName = "OldName";
27-
private const string NewName = "NewName";
28+
private const string NewName = "OldName (duplicate)";
2829

2930
[TestInitialize()]
3031
public void Setup()
@@ -48,17 +49,17 @@ public void Setup()
4849
_data = new Dictionary<string, string>
4950
{
5051
["element"] = ElementId.ToString(),
51-
["old"] = OldParentId.ToString(),
52+
["oldParent"] = OldParentId.ToString(),
5253
["oldIndex"] = OldIndex.ToString(),
5354
["oldName"] = OldName,
54-
["new"] = NewParentId.ToString(),
55+
["newParent"] = NewParentId.ToString(),
5556
["newIndex"] = NewIndex.ToString(),
5657
["newName"] = NewName,
5758
};
5859
}
5960

6061
[TestMethod]
61-
public void WhenDoActionThenElementParentIsChangedDataModel()
62+
public void WhenDoActionThenElementParentIsChangedDataModelNoNameChange()
6263
{
6364
_newParent.Setup(x => x.ContainsChildWithName(OldName)).Returns(false);
6465

@@ -68,6 +69,21 @@ public void WhenDoActionThenElementParentIsChangedDataModel()
6869
Assert.IsTrue(action.IsValid());
6970

7071
_model.Verify(x => x.ChangeElementParent(_element.Object, _newParent.Object, NewIndex), Times.Once());
72+
_model.Verify(x => x.ChangeElementName(It.IsAny<IDsmElement>(), It.IsAny<string>()), Times.Never());
73+
}
74+
75+
[TestMethod]
76+
public void WhenDoActionThenElementParentIsChangedDataModelNameChange()
77+
{
78+
_newParent.Setup(x => x.ContainsChildWithName(OldName)).Returns(true);
79+
80+
ElementChangeParentAction action =
81+
new ElementChangeParentAction(_model.Object, _element.Object, _newParent.Object, NewIndex);
82+
action.Do();
83+
Assert.IsTrue(action.IsValid());
84+
85+
_model.Verify(x => x.ChangeElementParent(_element.Object, _newParent.Object, NewIndex), Times.Once());
86+
_model.Verify(x => x.ChangeElementName(_element.Object, NewName), Times.Once());
7187
}
7288

7389
[TestMethod]
@@ -81,34 +97,45 @@ public void WhenUndoActionThenElementParentIsRevertedDataModelNoNameChange()
8197
Assert.IsTrue(action.IsValid());
8298

8399
_model.Verify(x => x.ChangeElementParent(_element.Object, _oldParent.Object, OldIndex), Times.Once());
100+
_model.Verify(x => x.ChangeElementName(It.IsAny<IDsmElement>(), It.IsAny<string>()), Times.Never());
84101
}
85102

86103
[TestMethod]
87104
public void WhenUndoActionThenElementParentIsRevertedDataModelNameChange()
88105
{
89-
Assert.Inconclusive("To be implemented");
106+
string elementName = null;
107+
108+
_newParent.Setup(x => x.ContainsChildWithName(OldName)).Returns(true);
109+
_model.Setup(x => x.ChangeElementName(It.IsAny<IDsmElement>(), It.IsAny<string>()))
110+
.Callback((IDsmElement e, string name) => { elementName = name; });
111+
112+
ElementChangeParentAction action =
113+
new ElementChangeParentAction(_model.Object, _element.Object, _newParent.Object, NewIndex);
114+
// Do saves state in Data so we cannot test Undo() without calling Do
115+
action.Do();
116+
action.Undo();
117+
Assert.IsTrue(action.IsValid());
118+
119+
_model.Verify(x => x.ChangeElementParent(_element.Object, _oldParent.Object, OldIndex), Times.Once());
120+
_model.Verify(x => x.ChangeElementName(_element.Object, OldName), Times.Once());
121+
Assert.AreEqual(elementName, OldName);
90122
}
91123

92124
[TestMethod]
93-
public void GivenLoadedActionWhenGettingDataThenActionAttributesMatchNoNameChange()
125+
public void GivenLoadedActionWhenGettingDataThenActionAttributesMatch()
94126
{
95-
object[] args = {_model.Object, _data};
96-
ElementChangeParentAction action = new ElementChangeParentAction(args);
127+
object[] args = {_model.Object, null, _data};
128+
ElementChangeParentAction action =
129+
Activator.CreateInstance(typeof(ElementChangeParentAction), args) as ElementChangeParentAction;
97130

98131
Assert.AreEqual(7, action.Data.Count);
99132
Assert.AreEqual(ElementId.ToString(), _data["element"]);
100-
Assert.AreEqual(OldParentId.ToString(), _data["old"]);
133+
Assert.AreEqual(OldParentId.ToString(), _data["oldParent"]);
101134
Assert.AreEqual(OldIndex.ToString(), _data["oldIndex"]);
102135
Assert.AreEqual(OldName, _data["oldName"]);
103-
Assert.AreEqual(NewParentId.ToString(), _data["new"]);
136+
Assert.AreEqual(NewParentId.ToString(), _data["newParent"]);
104137
Assert.AreEqual(NewIndex.ToString(), _data["newIndex"]);
105138
Assert.AreEqual(NewName, _data["newName"]);
106139
}
107-
108-
[TestMethod]
109-
public void GivenLoadedActionWhenGettingDataThenActionAttributesMatchNameChange()
110-
{
111-
Assert.Inconclusive("To be implemented");
112-
}
113140
}
114141
}

DsmSuite.DsmViewer.Application.Test/Actions/Element/ElementChangeTypeActionTest.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Moq;
44
using System.Collections.Generic;
55
using DsmSuite.DsmViewer.Application.Actions.Element;
6+
using System;
67

78
namespace DsmSuite.DsmViewer.Application.Test.Actions.Element
89
{
@@ -59,8 +60,9 @@ public void WhenUndoActionThenElementTypeIsRevertedDataModel()
5960
[TestMethod]
6061
public void GivenLoadedActionWhenGettingDataThenActionAttributesMatch()
6162
{
62-
object[] args = { _model.Object, _data };
63-
ElementChangeTypeAction action = new ElementChangeTypeAction(args);
63+
object[] args = { _model.Object, null, _data };
64+
ElementChangeTypeAction action =
65+
Activator.CreateInstance(typeof(ElementChangeTypeAction), args) as ElementChangeTypeAction;
6466

6567
Assert.AreEqual(3, action.Data.Count);
6668
Assert.AreEqual(ElementId.ToString(), _data["element"]);

DsmSuite.DsmViewer.Application.Test/Actions/Element/ElementCreateActionTest.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Moq;
44
using System.Collections.Generic;
55
using DsmSuite.DsmViewer.Application.Actions.Element;
6+
using System;
67

78
namespace DsmSuite.DsmViewer.Application.Test.Actions.Element
89
{
@@ -58,8 +59,8 @@ public void WhenDoActionThenElementIsAddedToDataModel()
5859
[TestMethod]
5960
public void WhenUndoActionThenElementIsRemovedFromDataModel()
6061
{
61-
object[] args = { _model.Object, _data };
62-
ElementCreateAction action = new ElementCreateAction(args);
62+
object[] args = { _model.Object, null, _data };
63+
ElementCreateAction action = Activator.CreateInstance(typeof(ElementCreateAction), args) as ElementCreateAction;
6364
action.Undo();
6465
Assert.IsTrue(action.IsValid());
6566

@@ -69,8 +70,8 @@ public void WhenUndoActionThenElementIsRemovedFromDataModel()
6970
[TestMethod]
7071
public void GivenLoadedActionWhenGettingDataThenActionAttributesMatch()
7172
{
72-
object[] args = { _model.Object, _data };
73-
ElementCreateAction action = new ElementCreateAction(args);
73+
object[] args = { _model.Object, null, _data };
74+
ElementCreateAction action = Activator.CreateInstance(typeof(ElementCreateAction), args) as ElementCreateAction;
7475

7576
Assert.AreEqual(5, action.Data.Count);
7677
Assert.AreEqual(ElementId.ToString(), _data["element"]);

DsmSuite.DsmViewer.Application.Test/Actions/Element/ElementDeleteActionTest.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using DsmSuite.DsmViewer.Model.Interfaces;
44
using DsmSuite.DsmViewer.Application.Actions.Element;
55
using System.Collections.Generic;
6+
using System;
67

78
namespace DsmSuite.DsmViewer.Application.Test.Actions.Element
89
{
@@ -53,8 +54,9 @@ public void WhenUndoActionThenElementIsRestoredInDataModel()
5354
[TestMethod]
5455
public void GivenLoadedActionWhenGettingDataThenActionAttributesMatch()
5556
{
56-
object[] args = { _model.Object, _data };
57-
ElementDeleteAction action = new ElementDeleteAction(args);
57+
object[] args = { _model.Object, null, _data };
58+
ElementDeleteAction action =
59+
Activator.CreateInstance(typeof(ElementDeleteAction), args) as ElementDeleteAction;
5860

5961
Assert.AreEqual(1, action.Data.Count);
6062
Assert.AreEqual(ElementId.ToString(), _data["element"]);

DsmSuite.DsmViewer.Application.Test/Actions/Element/ElementMoveDownActionTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Moq;
44
using DsmSuite.DsmViewer.Application.Actions.Element;
55
using System.Collections.Generic;
6+
using System;
67

78
namespace DsmSuite.DsmViewer.Application.Test.Actions.Element
89
{
@@ -59,8 +60,8 @@ public void WhenUndoActionThenElementIsRestoredInDataModel()
5960
[TestMethod]
6061
public void GivenLoadedActionWhenGettingDataThenActionAttributesMatch()
6162
{
62-
object[] args = { _model.Object, _data };
63-
ElementMoveDownAction action = new ElementMoveDownAction(args);
63+
object[] args = { _model.Object, null, _data };
64+
ElementMoveDownAction action = Activator.CreateInstance(typeof(ElementMoveDownAction), args) as ElementMoveDownAction;
6465

6566
Assert.AreEqual(1, action.Data.Count);
6667
Assert.AreEqual(ElementId.ToString(), _data["element"]);

DsmSuite.DsmViewer.Application.Test/Actions/Element/ElementMoveUpActionTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Moq;
44
using DsmSuite.DsmViewer.Application.Actions.Element;
55
using System.Collections.Generic;
6+
using System;
67

78
namespace DsmSuite.DsmViewer.Application.Test.Actions.Element
89
{
@@ -59,8 +60,8 @@ public void WhenUndoActionThenElementIsRestoredInDataModel()
5960
[TestMethod]
6061
public void GivenLoadedActionWhenGettingDataThenActionAttributesMatch()
6162
{
62-
object[] args = { _model.Object, _data };
63-
ElementMoveUpAction action = new ElementMoveUpAction(args);
63+
object[] args = { _model.Object, null, _data };
64+
ElementMoveUpAction action = Activator.CreateInstance(typeof(ElementMoveUpAction), args) as ElementMoveUpAction;
6465

6566
Assert.AreEqual(1, action.Data.Count);
6667
Assert.AreEqual(ElementId.ToString(), _data["element"]);

DsmSuite.DsmViewer.Application.Test/Actions/Element/ElementSortActionTest.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using DsmSuite.DsmViewer.Application.Sorting;
77
using DsmSuite.DsmViewer.Application.Test.Stubs;
8+
using System;
89

910
namespace DsmSuite.DsmViewer.Application.Test.Actions.Element
1011
{
@@ -53,8 +54,8 @@ public void WhenDoActionThenElementsChildrenAreSorted()
5354
[TestMethod]
5455
public void WhenUndoActionThenElementsChildrenAreSortIsReverted()
5556
{
56-
object[] args = { _model.Object, _data };
57-
ElementSortAction action = new ElementSortAction(args);
57+
object[] args = { _model.Object, null, _data };
58+
ElementSortAction action = Activator.CreateInstance(typeof(ElementSortAction), args) as ElementSortAction;
5859
action.Undo();
5960
Assert.IsTrue(action.IsValid());
6061

@@ -64,8 +65,8 @@ public void WhenUndoActionThenElementsChildrenAreSortIsReverted()
6465
[TestMethod]
6566
public void GivenLoadedActionWhenGettingDataThenActionAttributesMatch()
6667
{
67-
object[] args = { _model.Object, _data };
68-
ElementSortAction action = new ElementSortAction(args);
68+
object[] args = { _model.Object, null, _data };
69+
ElementSortAction action = Activator.CreateInstance(typeof(ElementSortAction), args) as ElementSortAction;
6970

7071
Assert.AreEqual(3, action.Data.Count);
7172
Assert.AreEqual(ElementId.ToString(), _data["element"]);

DsmSuite.DsmViewer.Application.Test/Actions/Relation/RelationChangeTypeActionTest.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Moq;
44
using DsmSuite.DsmViewer.Application.Actions.Relation;
55
using System.Collections.Generic;
6+
using System;
67

78
namespace DsmSuite.DsmViewer.Application.Test.Actions.Relation
89
{
@@ -68,8 +69,9 @@ public void GivenLoadedActionWhenGettingDataThenActionAttributesMatch()
6869
{
6970
_model.Setup(x => x.GetRelationById(RelationId)).Returns(_relation.Object);
7071

71-
object[] args = { _model.Object, _data };
72-
RelationChangeTypeAction action = new RelationChangeTypeAction(args);
72+
object[] args = { _model.Object, null, _data };
73+
RelationChangeTypeAction action =
74+
Activator.CreateInstance(typeof(RelationChangeTypeAction), args) as RelationChangeTypeAction;
7375

7476
Assert.AreEqual(3, action.Data.Count);
7577
Assert.AreEqual(RelationId.ToString(), _data["relation"]);

DsmSuite.DsmViewer.Application.Test/Actions/Relation/RelationChangeWeightActionTest.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Moq;
44
using DsmSuite.DsmViewer.Application.Actions.Relation;
55
using System.Collections.Generic;
6+
using System;
67

78
namespace DsmSuite.DsmViewer.Application.Test.Actions.Relation
89
{
@@ -68,8 +69,9 @@ public void GivenLoadedActionWhenGettingDataThenActionAttributesMatch()
6869
{
6970
_model.Setup(x => x.GetRelationById(RelationId)).Returns(_relation.Object);
7071

71-
object[] args = { _model.Object, _data };
72-
RelationChangeWeightAction action = new RelationChangeWeightAction(args);
72+
object[] args = { _model.Object, null, _data };
73+
RelationChangeWeightAction action =
74+
Activator.CreateInstance(typeof(RelationChangeWeightAction), args) as RelationChangeWeightAction;
7375

7476
Assert.AreEqual(3, action.Data.Count);
7577
Assert.AreEqual(RelationId.ToString(), _data["relation"]);

0 commit comments

Comments
 (0)