forked from gdlprj/duscusys
/
TestEventOrchestrater.cs
119 lines (94 loc) · 3.23 KB
/
TestEventOrchestrater.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using System;
using System.Windows.Controls;
using System.Windows.Threading;
using Discussions.view;
namespace Discussions
{
public class TestEventOrchestrater
{
private enum TestAction
{
FocusedAndEdited,
Submitted,
Removed,
None
};
private static TestEventOrchestrater _inst;
public static TestEventOrchestrater Inst
{
get
{
if (_inst == null)
_inst = new TestEventOrchestrater();
return _inst;
}
}
private DispatcherTimer _timer;
private EditableBadge _editBadge;
private PrivateCenter3 _privCenter;
private TestAction _prevAction;
public void Start(EditableBadge editBadge, PrivateCenter3 privCenter)
{
_editBadge = editBadge;
_privCenter = privCenter;
_timer = new DispatcherTimer {Interval = TimeSpan.FromSeconds(2)};
_timer.Tick += TimerOnTick;
_timer.Start();
}
private void TimerOnTick(object sender, EventArgs eventArgs)
{
switch (_prevAction)
{
case TestAction.FocusedAndEdited:
Submit();
break;
case TestAction.Submitted:
Remove();
break;
case TestAction.None:
FocusAndEnter();
break;
case TestAction.Removed:
FocusAndEnter();
break;
default:
throw new ArgumentOutOfRangeException();
}
}
void Submit()
{
_privCenter.btnSave_Click(null,null);
_prevAction = TestAction.Submitted;
}
void FocusAndEnter()
{
var comment = GetCommentTextBox();
if (comment == null)
return;
comment.Focus();
var rnd = new Random();
comment.Text = "comment" + rnd.Next(100);
_prevAction = TestAction.FocusedAndEdited;
}
void Remove()
{
var lastContainer = _editBadge.TestGetCommentsControl().ItemContainerGenerator.ContainerFromIndex(
_editBadge.TestGetCommentsControl().Items.Count - 3);
if (lastContainer == null)
return;
var commentUc = Utils.FindChild<CommentUC>(lastContainer);
commentUc.btnRemoveComment_Click(null, null);
_privCenter.btnSave_Click(null, null);
_prevAction = TestAction.Removed;
}
TextBox GetCommentTextBox()
{
var lastContainer = _editBadge.TestGetCommentsControl().ItemContainerGenerator.ContainerFromIndex(
_editBadge.TestGetCommentsControl().Items.Count - 1);
if (lastContainer == null)
return null;
var txtBox = Utils.FindChild<TextBox>(lastContainer);
return txtBox;
}
}
}