1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Threading . Tasks ;
4+ using Microsoft . Extensions . DependencyInjection ;
5+ using NUnit . Framework ;
6+ using Parser ;
7+ using Parser . ExpressionParser ;
8+ using Parser . FlowParser ;
9+ using Parser . FlowParser . ActionExecutors ;
10+
11+ namespace Test
12+ {
13+ [ TestFixture ]
14+ public class FullFlowTestV2
15+ {
16+ private static readonly string TestFlowPath = System . IO . Path . GetFullPath ( @"FlowSamples" ) ;
17+
18+ [ Test ]
19+ public async Task TestFlowFalse ( )
20+ {
21+ var path = @$ "{ TestFlowPath } \PowerAutomateMockUpSampleFlow.json";
22+
23+ var services = new ServiceCollection ( ) ;
24+ services . AddFlowRunner ( ) ;
25+
26+ services . AddFlowActionByName < UpdateAccountInvalidId > ( UpdateAccountInvalidId . FlowActionName ) ;
27+ services . AddFlowActionByApiIdAndOperationsName < SendEmailNotification > ( SendEmailNotification . ApiId ,
28+ SendEmailNotification . SupportedOperations ) ;
29+ services . AddFlowActionByName < GetRecordValidId > ( GetRecordValidId . FlowActionName ) ;
30+ services . AddFlowActionByName < UpdateAccountValidId > ( UpdateAccountValidId . FlowActionName ) ;
31+ services . AddFlowActionByName < SendOutWarning > ( SendOutWarning . FlowActionName ) ;
32+
33+
34+ var sp = services . BuildServiceProvider ( ) ;
35+ var flowRunner = sp . GetRequiredService < IFlowRunner > ( ) ;
36+
37+ flowRunner . InitializeFlowRunner ( path ) ;
38+
39+ var flowResult = await flowRunner . Trigger ( new ValueContainer (
40+ new Dictionary < string , ValueContainer >
41+ {
42+ { "body/name" , new ValueContainer ( "Alice Bob" ) } ,
43+ { "body/accountid" , new ValueContainer ( Guid . NewGuid ( ) . ToString ( ) ) }
44+ } ) ) ;
45+
46+ Assert . AreEqual ( 7 , flowResult . NumberOfExecutedActions ) ;
47+
48+ const string actionName = "Send_me_an_email_notification" ;
49+ Assert . IsTrue ( flowResult . ActionStates . ContainsKey ( actionName ) , "Action is expected to be triggered." ) ;
50+ Assert . NotNull ( flowResult . ActionStates [ actionName ] . ActionParameters , "Action input is expected." ) ;
51+ var actionInput = flowResult . ActionStates [ actionName ] . ActionParameters . AsDict ( ) ;
52+ Assert . IsTrue ( actionInput . ContainsKey ( "NotificationEmailDefinition" ) , "Action input should contain this object." ) ;
53+ var notification = actionInput [ "NotificationEmailDefinition" ] . AsDict ( ) ;
54+ Assert . AreEqual ( "A new Account have been added" , notification [ "notificationSubject" ] . GetValue < string > ( ) , "Asserting the input" ) ;
55+
56+ Assert . IsFalse ( flowResult . ActionStates . ContainsKey ( SendOutWarning . FlowActionName ) , "Action is not expected to be triggered." ) ;
57+ }
58+
59+ private class UpdateAccountInvalidId : OpenApiConnectionActionExecutorBase
60+ {
61+ public const string FlowActionName = "Update_Account_-_Invalid_Id" ;
62+
63+ public UpdateAccountInvalidId ( IExpressionEngine expressionEngine ) : base ( expressionEngine )
64+ {
65+ }
66+
67+ public override Task < ActionResult > Execute ( )
68+ {
69+ return Task . FromResult ( new ActionResult
70+ {
71+ ActionStatus = ActionStatus . Failed ,
72+ ActionOutput = new ValueContainer ( true )
73+ } ) ;
74+ }
75+ }
76+
77+ private class SendEmailNotification : OpenApiConnectionActionExecutorBase
78+ {
79+ public const string ApiId = "/providers/Microsoft.PowerApps/apis/shared_flowpush" ;
80+ public static readonly string [ ] SupportedOperations = { "SendEmailNotification" } ;
81+
82+ public SendEmailNotification ( IExpressionEngine expressionEngine ) : base ( expressionEngine )
83+ {
84+ }
85+
86+ public override Task < ActionResult > Execute ( )
87+ {
88+ Console . WriteLine ( $ "Email Title: { Parameters [ "NotificationEmailDefinition/notificationSubject" ] } ") ;
89+ Console . WriteLine ( $ "Email Content: { Parameters [ "NotificationEmailDefinition/notificationBody" ] } ") ;
90+
91+ return Task . FromResult ( new ActionResult { ActionOutput = new ValueContainer ( true ) } ) ;
92+ }
93+ }
94+
95+ private class GetRecordValidId : OpenApiConnectionActionExecutorBase
96+ {
97+ public const string FlowActionName = "Get_a_record_-_Valid_Id" ;
98+
99+ public GetRecordValidId ( IExpressionEngine expressionEngine ) : base ( expressionEngine )
100+ {
101+ }
102+
103+ public override Task < ActionResult > Execute ( )
104+ {
105+ return Task . FromResult ( new ActionResult { ActionOutput = new ValueContainer ( true ) } ) ;
106+ }
107+ }
108+
109+ private class UpdateAccountValidId : OpenApiConnectionActionExecutorBase
110+ {
111+ public const string FlowActionName = "Update_Account_-_Valid_Id" ;
112+
113+ public override Task < ActionResult > Execute ( )
114+ {
115+ return Task . FromResult ( new ActionResult ( ) ) ;
116+ }
117+
118+ public UpdateAccountValidId ( IExpressionEngine expressionEngine ) : base ( expressionEngine )
119+ {
120+ }
121+ }
122+
123+ private class SendOutWarning : OpenApiConnectionActionExecutorBase
124+ {
125+ public const string FlowActionName = "Send_an_error_message_to_owner" ;
126+
127+ public SendOutWarning ( IExpressionEngine expressionEngine ) : base ( expressionEngine )
128+ {
129+ }
130+
131+ public override Task < ActionResult > Execute ( )
132+ {
133+ return Task . FromResult ( new ActionResult ( ) ) ;
134+ }
135+ }
136+ }
137+ }
0 commit comments