Skip to content

Commit 550b633

Browse files
committed
Refactor
1 parent cf2bced commit 550b633

File tree

2 files changed

+92
-17
lines changed

2 files changed

+92
-17
lines changed

MockASP.vbs

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Class Mock
66
Private domStr
77
Private vbStr
88
Private filePath
9-
9+
Private Parameters
10+
Private fileName
1011
'Constructor
1112
Private Sub Class_Initialize( )
1213
HTML = 0
@@ -19,12 +20,21 @@ Class Mock
1920
'On Nothingd
2021
End Sub
2122

22-
'
23+
' - Set the ASP Page to use
24+
Function SetPage(fn)
25+
fileName = fn
26+
End Function
27+
28+
' - Process User Input State Parameters
29+
Function ProcessInput()
30+
31+
End Function
32+
2333
' Separate Frontend from backend
2434
' Insert variables into inline <%={var}%>
2535
' Move Response.Writes to the Dom
2636
'
27-
Function LoadFile(fileName)
37+
Function LoadFile()
2838
Dim line : line = ""
2939
Dim vbPos : vbPos = 0
3040
Dim vbNeg : vbNeg = 0
@@ -86,7 +96,10 @@ Class Mock
8696
Set fSys = Nothing
8797
End Sub
8898
End Class
99+
' -
100+
89101

102+
' -
90103
Class ResponseMock
91104
Private fileName
92105
Private filePath
@@ -154,13 +167,39 @@ Class Request
154167

155168
'body
156169
End Function
170+
171+
Private Requests
172+
Function ToMethodVal(V)
173+
If V=vbYes Then : ToMethodVal="GET" : Else : ToMethodVal="POST"
174+
End Function
175+
176+
Function GetParameters(Ps, P)
177+
Set Requests = CreateObject("Scripting.Dictionary")
178+
Dim Key, K
179+
' Santitize Fill into Dictionary
180+
For Each K IN Ps
181+
If Requests.Exists(K)=False Then Requests.add K, "Empty"
182+
Next
183+
184+
For Each Key in Requests
185+
Requests(Key) = InputBox("Enter value for " & Key & ": ", "Request Builder", Requests(Key))
186+
Next
187+
Requests.add "_METHOD", ToMethodVal(MsgBox("IS METHOD TYPE GET(Yes) OR POST(No): ", vbYesNo))
188+
' Print That Back
189+
Dim reqStr : reqStr = ""
190+
For Each Key in Requests
191+
reqStr = reqStr & "[" & Key & " := " & Requests(Key) & "]" & vbCrLf
192+
Next
193+
MsgBox reqStr, " Request Parameters "
194+
Set P = Requests
195+
GetParameters = reqStr
196+
End Function
157197
End Class
158198

159199
' ----- END Request CLASS -----'
160200
MsgBox " Mocking..."
161201
Set Response = new ResponseMock
162202
' Play Data '
163-
' TODO: Load via asp File'
164203
Dim HTML
165204
HTML = "<!DOCTYPE html>" & VbCrLf &_
166205
"<html>" & VbCrLf &_
@@ -170,11 +209,25 @@ Dim HTML
170209
"<body>MokMokMok</body>" & VbCrLf &_
171210
"</html>"
172211

173-
' The Action'
212+
' Sample Action'
174213
'Response.Write HTML
175214
'Response.Mock
215+
' ======================================================'
216+
' ======================== MAIN ========================'
217+
' ======================================================'
218+
' Processing Steps:
219+
' 1 Load ASP File
220+
' 2 Read Through For Form/QueryString/Session Variables Expected
221+
' 3 Prompt User For values or use file(save to file after prompt for next time)
222+
' 4 Parse File Replace Input Params with last steps
223+
' 5 Get Mock DB Input
224+
' Generate HTML+Execute VB
225+
' Write HTML
226+
' OPEN in Browser
176227

177228
' Wrap ASP
178-
Set MockASP = new Mock
179-
MockASP.LoadFile("Page.ASP")
180-
MockASP.WriteToFile
229+
Set MockASP = new Mock '| - Initialize a Mock ASP Object
230+
MockASP.SetPage("Page.ASP")
231+
MockASP.ProcessInput '| - Process User Input State Parameters
232+
MockASP.LoadFile '| - Load the ASP File
233+
MockASP.WriteToFile '| -

VBSExtras.vbs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,45 @@ C str , " Hello"
118118
C str , " Hi"
119119
C str , " Hiya"
120120

121-
Dim o1(3,1)
122-
Dim a : a = UBound(o1,1)
123-
Dim b : b = UBound(o1,2)
124-
Dim c1 : c1 = LBound(o1,3)
125-
MsgBox "a " & a
126-
MsgBox "b " & b
127-
MsgBox "c1 " & c1
128-
MsgBox "E " & TypeName(o1(0,0))
121+
' Dim o1(3,1)
122+
' Dim a : a = UBound(o1,1)
123+
' Dim b : b = UBound(o1,2)
124+
' Dim c1 : c1 = LBound(o1,3)
125+
' MsgBox "a " & a
126+
' MsgBox "b " & b
127+
' MsgBox "c1 " & c1
128+
' MsgBox "E " & TypeName(o1(0,0))
129129

130130

131131
' Would Break v2(6) = 60
132-
Call puts(v2,60)
132+
' Call puts(v2,60)
133133
Dim iV2
134134
' For iV2=0 To UBound(v2)
135135
' MsgBox "v("&iV2&"): " & v2(iV2)
136136
' Next
137137

138+
Function ToMethodVal(V)
139+
If V=vbYes Then : ToMethodVal="GET" : Else : ToMethodVal="POST"
140+
End Function
141+
142+
Dim Requests : Set Requests = CreateObject("Scripting.Dictionary")
143+
Dim Key
144+
Requests.add "username", "Empty"
145+
Requests.add "age", "Empty"
146+
Requests.add "x", "Empty"
147+
Requests.add "y", "Empty"
148+
For Each Key in Requests
149+
Requests(Key) = InputBox("Enter value for " & Key & ": ", "Request Builder", Requests(Key))
150+
Next
151+
Requests.add "_METHOD", ToMethodVal(MsgBox("IS METHOD TYPE GET(Yes) OR POST(No): ", vbYesNo))
152+
' Print That Back
153+
Dim reqStr : reqStr = ""
154+
For Each Key in Requests
155+
reqStr = reqStr & "[" & Key & " := " & Requests(Key) & "]" & vbCrLf
156+
Next
157+
MsgBox reqStr, " Request Parameters "
138158
'###############################################'
139159
' ############### MAIN TEST ################### '
140160
'###############################################'
161+
162+

0 commit comments

Comments
 (0)