I am new for Classic API.I am working in MVC. but i have one project in classic asp(VB Script) and i want to create unit test for my project. after lots of R&D. I integrated given module in my project for unit test. http://ift.tt/25JfaeN. but i can not able to find help how to test my pages using integrated unittest.
Let's take one Example. I want to test my e-commerce site cart summary page.
Test Cases
- View Empty cart
- Add item to cart
- View cart with item
- Remove item from cart
- Empty cart
- Change quantity of a product already in a cart
class.cart.asp page code
Sub Summary(nID)
Dim OrderTotal
Dim OrderSubTotal
Dim OrderLineTotal
Dim OrderDelivery
Dim intCounter
Dim sItems : sItems = ""
OrderDelivery = 0
Call MergeCookie
Call GetCart
intCounter = 0
sFile = oBase.LoadView("cart","summary",1)
aParts = DoSplit(sFile)
sHeader = aParts(0)
sFooter = aParts(2)
If (C_LIVE) Then
sHeader = oBase.InsertValue(sHeader,"CRITEO_ACCOUNT_ID",C_CRITEO_ACCOUNT_ID)
sHeader = oBase.InsertValue(sHeader,"LOGGED_IN_EMAIL",Session("logged_in_user"))
Else
sHeader = oBase.InsertValue(sHeader,"CRITEO_ACCOUNT_ID",False)
sHeader = oBase.InsertValue(sHeader,"LOGGED_IN_EMAIL","")
End If
If IsObject(objCart) Then
If objCart.Count > 0 Then
sItems = sItems & "["
For Each Item in objCart
OrderLineTotal = 0
aProduct = Split(Item,"_")
If IsArray(aProduct) Then
If C_FRIENDLY Then
sQ = oDB.ExecuteQuery(oConn,"SELECT p.id, p.productName, p.productVariants, p.files_id, p.alias, c.alias, m.alias, p.categoryId FROM catalogue_products AS p LEFT OUTER JOIN catalogue_categories AS c ON c.id = p.categoryId LEFT OUTER JOIN catalogue_categories AS m ON m.id = c.parent_id WHERE p.id = " & aProduct(1))
Else
sQ = oDB.ExecuteQuery(oConn,"SELECT p.id, p.productName, p.productVariants, p.files_id, p.alias, c.alias, m.alias, p.categoryId FROM catalogue_products AS p INNER JOIN catalogue_categories AS c ON c.id = p.categoryId LEFT OUTER JOIN catalogue_categories AS m ON m.id = c.parent_id WHERE p.id = " & aProduct(1))
End If
If IsArray(sQ) Then
intQty = objCart(Item)
strPrice = Catalogue.GetVariantPrice(aProduct(1),aProduct(3))
strSpecialPrice = Catalogue.GetVariantSpecialPrice(aProduct(1),aProduct(3))
If IsNull(strSpecialPrice) = False AND strSpecialPrice > 0 Then
strPrice = strSpecialPrice
End If
If strPrice = "" Then
strPrice = 0
End If
sRepeat = sRepeat & aParts(1)
sRepeat = oBase.InsertValue(sRepeat,"ID",sQ(0,0))
sRepeat = oBase.InsertValue(sRepeat,"ITEM",Replace(Item,",","XPRJDURJFEYD"))
sRepeat = oBase.InsertValue(sRepeat,"COUNTER",intCounter)
If ((C_LIVE And sQ(7,0) = 99) Or (Not C_LIVE And sQ(7,0) = 81)) Then
strImage = Repository.GetFirstImageInFolder(sQ(3,0))
sRepeat = oBase.InsertValue(sRepeat,"COUNTER_READONLY","READONLY")
Else
If Not IsNull(Catalogue.GetProductColourID(aProduct(1),aProduct(2))) Then
strImage = Catalogue.GetProductColourID(aProduct(1),aProduct(2))
Else
strImage = Repository.GetFirstImageInFolder(sQ(3,0))
End If
sRepeat = oBase.InsertValue(sRepeat,"COUNTER_READONLY","")
End If
sRepeat = oBase.InsertValue(sRepeat,"IMG_SRC",URL2("repository","resize",strImage,"window=1&dimension=60"))
If (aProduct(1) = 305 And UBound(aProduct) > 4) Then
If (aProduct(4) = "Post") Then
sRepeat = oBase.InsertValue(sRepeat,"TITLE",sQ(1,0) & " for " & aProduct(5) & " (Courier)")
Else
sRepeat = oBase.InsertValue(sRepeat,"TITLE",sQ(1,0) & " for " & aProduct(5) & " (Email)")
End If
Else
sRepeat = oBase.InsertValue(sRepeat,"TITLE",sQ(1,0))
End If
sRepeat = oBase.InsertValue(sRepeat,"CODE",aProduct(3))
sRepeat = oBase.InsertValue(sRepeat,"COLOUR",Catalogue.GetColourName(aProduct(2)))
sRepeat = oBase.InsertValue(sRepeat,"UNIT_PRICE",FormatNumber(strPrice,2))
sRepeat = oBase.InsertValue(sRepeat,"QUANTITY",intQty)
OrderLineTotal = OrderLineTotal + (strPrice * intQty)
sRepeat = oBase.InsertValue(sRepeat,"LINE_TOTAL",FormatNumber(OrderLineTotal,2))
If aProduct(1) = 305 Then
sRepeat = oBase.InsertValue(sRepeat,"HREF",Params(Array("vouchers","buy-gift-vouchers")))
ElseIf ((C_LIVE And sQ(7,0) = 99) Or (Not C_LIVE And sQ(7,0) = 81)) Then
sRepeat = oBase.InsertValue(sRepeat,"HREF",Params(Array(sQ(5,0),sQ(4,0))))
Else
sRepeat = oBase.InsertValue(sRepeat,"HREF",Params(Array("products",sQ(6,0),sQ(5,0),sQ(4,0))))
End If
OrderSubTotal = OrderSubTotal + OrderLineTotal
OrderTotal = OrderSubTotal
If Len(sItems) > 1 Then
sItems = sItems & ","
End If
sItems = sItems & "{"
sItems = sItems & """id"": """ & sQ(0,i) & """"
sItems = sItems & ",""price"":""" & strPrice & """"
sItems = sItems & ",""quantity"":""" & intQty & """"
sItems = sItems & "}"
End If
End If
intCounter = intCounter + 1
Next
sItems = sItems & "]"
OrderDiscount = Discount.Calculate
OrderTotal = (OrderTotal + OrderDelivery) - OrderDiscount
If (C_LIVE) Then
sHeader = oBase.InsertValue(sHeader,"ITEMS",sItems)
Else
sHeader = oBase.InsertValue(sHeader,"ITEMS",False)
End If
sFooter = oBase.InsertValue(sFooter,"SUB_TOTAL",FormatNumber(OrderSubTotal,2))
sFooter = oBase.InsertValue(sFooter,"DELIVERY",FormatNumber(OrderDelivery,2))
sFooter = oBase.InsertValue(sFooter,"TOTAL",FormatNumber(OrderTotal,2))
sFooter = oBase.InsertValue(sFooter,"HREF_CHECKOUT",URL("cart","checkout",null))
sFooter = oBase.InsertValue(sFooter,"DISCOUNT",OrderDiscount)
sHeader = oBase.InsertValue(sHeader,"HASITEMS",True)
sFooter = oBase.InsertValue(sFooter,"HASITEMS",True)
sFooter = oBase.InsertValue(sFooter,"NOTHING",False)
Else
sHeader = oBase.InsertValue(sHeader,"HASITEMS",False)
sFooter = oBase.InsertValue(sFooter,"HASITEMS",False)
sFooter = oBase.InsertValue(sFooter,"NOTHING",True)
End If
Else
'sHeader = oBase.InsertValue(sHeader,"HASITEMS",False)
'sFooter = oBase.InsertValue(sFooter,"HASITEMS",False)
End If
Response.Write(sHeader & sRepeat & sFooter)
End Sub
skin.summary.asp
[IFNULL:CRITEO_ACCOUNT_ID]
<script type="text/javascript">
var items = JSON.parse('[ITEMS]');
window.criteo_q = window.criteo_q || [];
window.criteo_q.push(
{ event: "setAccount", account: "[CRITEO_ACCOUNT_ID]" },
{ event: "setEmail", email: "[LOGGED_IN_EMAIL]" },
{ event: "setSiteType", type: (/Mobi/i.test(navigator.userAgent)) ? "m" : "d" },
{
event: "viewBasket", item:
function () {
var pl = [];
for (var i = 0; i < items.length; ++i) {
pl.push({
id: items[i].id,
price: items[i].price,
quantity: items[i].quantity
});
}
return pl;
}
});
</script>
[/IFNULL:CRITEO_ACCOUNT_ID]
<!--<script type="text/javascript">
$(document).ready(function(){
$('.discount-code-apply').click(function(){
var v = $('.discount-code').val();
$(this).attr('href','discount/validatediscountCode/' + v);
});
});
</script>-->
[IFNULL:HASITEMS]
<div class="contact_bg">
<div class="contact_hold">
<div class="bread_crumbs">
<ul>
<li><a href="online.asp" title="Le Creuset Home">Home</a></li>
<li><a href="#" title="">Shopping Cart</a></li>
</ul>
</div>
<div class="clearall" style="height: 15px;"></div>
<h1>My Shopping Cart</h1>
<div class="product_padding">
<div class="clearall" style="height: 15px;"></div>
<div id="">
<div id="iis_cart_summary">
<div class="float-col" style="width: 55%">
[/IFNULL:HASITEMS]
[REPEAT]
<div class="cart-item">
<div class="float-col">
<a href="[HREF]">
<img style="width: 60px" src="[IMG_SRC]" alt="" /></a>
</div>
<div class="float-col right">
<a href="[HREF]">
<h1>[TITLE]</h1>
</a>
<h2>Code: [CODE]</h2>
<h2>Colour: [COLOUR]</h2>
<div>R <span id="unit_price_[COUNTER]">[UNIT_PRICE]</span></div>
</div>
<div class="float-col right" style="margin-top: 0px; width: 30px;">
<input class="inp_qty" onkeyup="$.changeQty([COUNTER],this.value,false)" [COUNTER_READONLY] onchange="$.changeQty([COUNTER],this.value,true)" id="inp_qty_[COUNTER]" type="number" style="width: 30px" value="[QUANTITY]" />
</div>
<div class="float-col right div-line-total">
<h3>R <span id="line_total_[COUNTER]" class="line_total">[LINE_TOTAL]</span></h3>
</div>
<div class="float-col right" style="width: 162px; line-height: 12px; margin-top: 8px;">
<a class="btn_outline" style="width: 154px; color: #000000; border: 1px solid #000000;" title="Remove this item from the shopping cart" onclick="$.removeItemFromCart('[ITEM]')">REMOVE FROM CART <i class="fa fa-times fa-fw" style="font-size: 14px;"></i></a>
</div>
<!--<div class="float-col right" style="width: 162px; line-height: 12px; margin-top: 8px;">
<a class="btn_outline" style="width: 154px;" title="Add this item to your wishlist">ADD TO WISHLIST <i class="fa fa-heart fa-fw" style="font-size: 14px;"></i></a>
</div>-->
<!-- <a class="icon-close" onclick="$.removeItemFromCart('[ITEM]')" title="Remove this item from the shopping cart">Remove</a>-->
<div class="clear"></div>
</div>
[/REPEAT]
[IFNULL:HASITEMS]
</div>
<div id="total" class="float-col right" style="width: 41%">
<div class="cart-checkout-labels">
<label>Sub Total:</label>
R <span class="sub_total">[SUB_TOTAL]</span>
</div>
<div class="cart-checkout-labels">
<label>Discount:</label>
R (<span class="delivery">[DISCOUNT]</span>)
</div>
<hr />
<br />
<div class="cart-checkout-labels green">
<label>Total:</label>
R <span class="total">[TOTAL]</span>
</div>
<hr />
<div>
Enter your discount code here: <input type="text" class="big discount-code" placeholder="Discount Code" style="width: 140px !important;" /> <a href="#" class="discount-code-apply btn_fill2" >Apply</a>
</div>
<hr />
<br />
<!-- <div style="text-align: center"><a id="checkout-btn" class="btn" href="[HREF_CHECKOUT]">Continue to Checkout</a> <strong>or</strong> <a onclick="$.deleteCart()">Empty the Cart</a> </div>-->
<div style="text-align: left"><a id="checkout-btn" class="btn" href="[HREF_CHECKOUT]">Continue to Checkout</a></div>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
</div>
[/IFNULL:HASITEMS]
[IFNULL:NOTHING]
<p><strong>You don't have any items in your shopping cart.</strong></p>
[/IFNULL:NOTHING]
<script type="text/javascript">
$(function () {
$.getDiscountCode();
});
</script>
so my URL is http://localhost:65138/cart/summary
Please help me how to i do unit test of my page.
Aucun commentaire:
Enregistrer un commentaire