Commit 8e7fb01d authored by datdiep's avatar datdiep

fix

parent 64b8275b
...@@ -20,11 +20,11 @@ namespace TestProject1 ...@@ -20,11 +20,11 @@ namespace TestProject1
var rq = new UF.AssessmentProject.Model.Transaction.RequestMessage() var rq = new UF.AssessmentProject.Model.Transaction.RequestMessage()
{ {
partnerkey = "FAKEGOOGLE", partnerkey = "FAKEGOOGLE",
partnerpassword = "FG-00001", partnerrefno = "FG-00001",
partnerrefno = "RkFLRVBBU1NXT1JEMTIzNA==", partnerpassword = "RkFLRVBBU1NXT1JEMTIzNA==",
sig = "24XYSmvKGH9I9Y5FLvSsId2MPtjkvog7U5JLhE3m30A=", sig = "24XYSmvKGH9I9Y5FLvSsId2MPtjkvog7U5JLhE3m30A=",
timestamp = "2013-11-22T02:11:22.0000000Z", timestamp = "2013-11-22T02:11:22.0000000Z",
totalamount = 1000, totalamount = 110,
items = new List<UF.AssessmentProject.Model.Transaction.itemdetail>() items = new List<UF.AssessmentProject.Model.Transaction.itemdetail>()
{ {
new UF.AssessmentProject.Model.Transaction.itemdetail() new UF.AssessmentProject.Model.Transaction.itemdetail()
...@@ -46,9 +46,90 @@ namespace TestProject1 ...@@ -46,9 +46,90 @@ namespace TestProject1
ActionResult<UF.AssessmentProject.Model.Transaction.ResponseMessage> rs = _controller.SubmitTRansaction(rq); ActionResult<UF.AssessmentProject.Model.Transaction.ResponseMessage> rs = _controller.SubmitTRansaction(rq);
var actual = (OkObjectResult)rs.Result; var actual = (OkObjectResult)rs.Result;
var resultmessage = actual.Value as UF.AssessmentProject.Model.Transaction.ResponseMessage; var resultmessage = actual.Value as UF.AssessmentProject.Model.Transaction.ResponseMessage;
Assert.Equal("Expired!", resultmessage.resultmessage); Assert.True(resultmessage.resultmessage == "Expired!");
} }
[Fact]
public void Partnerkey_isRequired()
{
var rq = new UF.AssessmentProject.Model.Transaction.RequestMessage()
{
partnerrefno = "FG-00001",
partnerpassword = "RkFLRVBBU1NXT1JEMTIzNA==",
totalamount = 110,
items = new List<UF.AssessmentProject.Model.Transaction.itemdetail>()
{
new UF.AssessmentProject.Model.Transaction.itemdetail()
{
name = "i-00001",
partneritemref = "Pen",
qty = 5,
unitprice = 2
},
new UF.AssessmentProject.Model.Transaction.itemdetail()
{
name = "i-00002",
partneritemref = "Ruler",
qty = 1,
unitprice = 100
}
}
};
rq.timestamp = DateTime.Now.ToString();
var rawsign = DateTime.Parse(rq.timestamp).ToString("yyyyMMddHHmmss") + rq.partnerkey + rq.partnerrefno + rq.totalamount + rq.partnerpassword;
string sig = CommonUtils.ComputeSha256Hash((CommonUtils.EncodeBase64(rawsign)));
rq.sig = sig;
ActionResult<UF.AssessmentProject.Model.Transaction.ResponseMessage> rs = _controller.SubmitTRansaction(rq);
var actual = (OkObjectResult)rs.Result;
var resultmessage = actual.Value as UF.AssessmentProject.Model.Transaction.ResponseMessage;
Assert.True(resultmessage.resultmessage == "partnerkey is required!");
}
[Fact]
public void Invalid_total()
{
var rq = new UF.AssessmentProject.Model.Transaction.RequestMessage()
{
partnerkey = "FAKEGOOGLE",
partnerrefno = "FG-00001",
partnerpassword = "RkFLRVBBU1NXT1JEMTIzNA==",
totalamount = 9999,
items = new List<UF.AssessmentProject.Model.Transaction.itemdetail>()
{
new UF.AssessmentProject.Model.Transaction.itemdetail()
{
name = "i-00001",
partneritemref = "Pen",
qty = 5,
unitprice = 2
},
new UF.AssessmentProject.Model.Transaction.itemdetail()
{
name = "i-00002",
partneritemref = "Ruler",
qty = 1,
unitprice = 100
}
}
};
rq.timestamp = DateTime.Now.ToString();
var rawsign = DateTime.Parse(rq.timestamp).ToString("yyyyMMddHHmmss") + rq.partnerkey + rq.partnerrefno + rq.totalamount + rq.partnerpassword;
string sig = CommonUtils.ComputeSha256Hash((CommonUtils.EncodeBase64(rawsign)));
rq.sig = sig;
ActionResult<UF.AssessmentProject.Model.Transaction.ResponseMessage> rs = _controller.SubmitTRansaction(rq);
var actual = (OkObjectResult)rs.Result;
var resultmessage = actual.Value as UF.AssessmentProject.Model.Transaction.ResponseMessage;
Assert.True(resultmessage.resultmessage == "Invalid Total Amount.");
}
[Fact] [Fact]
public void Access_denied() public void Access_denied()
{ {
...@@ -56,9 +137,9 @@ namespace TestProject1 ...@@ -56,9 +137,9 @@ namespace TestProject1
var rq = new UF.AssessmentProject.Model.Transaction.RequestMessage() var rq = new UF.AssessmentProject.Model.Transaction.RequestMessage()
{ {
partnerkey = "aaa", partnerkey = "aaa",
partnerpassword = "FG-00001", partnerrefno = "FG-00001",
partnerrefno = "RkFLRVBBU1NXT1JEMTIzNA==", partnerpassword = "RkFLRVBBU1NXT1JEMTIzNA==",
totalamount = 1000, totalamount = 110,
items = new List<UF.AssessmentProject.Model.Transaction.itemdetail>() items = new List<UF.AssessmentProject.Model.Transaction.itemdetail>()
{ {
new UF.AssessmentProject.Model.Transaction.itemdetail() new UF.AssessmentProject.Model.Transaction.itemdetail()
...@@ -85,7 +166,47 @@ namespace TestProject1 ...@@ -85,7 +166,47 @@ namespace TestProject1
ActionResult<UF.AssessmentProject.Model.Transaction.ResponseMessage> rs = _controller.SubmitTRansaction(rq); ActionResult<UF.AssessmentProject.Model.Transaction.ResponseMessage> rs = _controller.SubmitTRansaction(rq);
var actual = (OkObjectResult)rs.Result; var actual = (OkObjectResult)rs.Result;
var resultmessage = actual.Value as UF.AssessmentProject.Model.Transaction.ResponseMessage; var resultmessage = actual.Value as UF.AssessmentProject.Model.Transaction.ResponseMessage;
Assert.Equal("Access Denied!", resultmessage.resultmessage); Assert.True(resultmessage.resultmessage == "Access Denied!");
}
[Fact]
public void Unitprice_positive()
{
var rq = new UF.AssessmentProject.Model.Transaction.RequestMessage()
{
partnerkey = "FAKEGOOGLE",
partnerrefno = "FG-00001",
partnerpassword = "RkFLRVBBU1NXT1JEMTIzNA==",
totalamount = 110,
items = new List<UF.AssessmentProject.Model.Transaction.itemdetail>()
{
new UF.AssessmentProject.Model.Transaction.itemdetail()
{
name = "i-00001",
partneritemref = "Pen",
qty = 5,
unitprice = -10
},
new UF.AssessmentProject.Model.Transaction.itemdetail()
{
name = "i-00002",
partneritemref = "Ruler",
qty = 1,
unitprice = -100
}
}
};
rq.timestamp = DateTime.Now.ToString();
var rawsign = DateTime.Parse(rq.timestamp).ToString("yyyyMMddHHmmss") + rq.partnerkey + rq.partnerrefno + rq.totalamount + rq.partnerpassword;
string sig = CommonUtils.ComputeSha256Hash((CommonUtils.EncodeBase64(rawsign)));
rq.sig = sig;
ActionResult<UF.AssessmentProject.Model.Transaction.ResponseMessage> rs = _controller.SubmitTRansaction(rq);
var actual = (OkObjectResult)rs.Result;
var resultmessage = actual.Value as UF.AssessmentProject.Model.Transaction.ResponseMessage;
Assert.True(resultmessage.resultmessage == "unitprice only allow positive value!");
} }
} }
} }
...@@ -64,7 +64,7 @@ namespace UF.AssessmentProject.Providers ...@@ -64,7 +64,7 @@ namespace UF.AssessmentProject.Providers
string sig = CommonUtils.ComputeSha256Hash((CommonUtils.EncodeBase64(rawsig))); string sig = CommonUtils.ComputeSha256Hash((CommonUtils.EncodeBase64(rawsig)));
var partner = db.Partners.Where(c => c.partnerkey == req.partnerkey).FirstOrDefault(); var partner = db.Partners.Where(c => c.partnerkey == req.partnerkey).FirstOrDefault();
if (partner == null || (partner != null && CommonUtils.EncodeBase64(partner.partnerpassword) != req.partnerpassword) || sig != req.sig) if (partner == null || (partner != null && (CommonUtils.EncodeBase64(partner.partnerpassword) != req.partnerpassword)) || sig != req.sig)
{ {
return new Model.Transaction.ResponseMessage return new Model.Transaction.ResponseMessage
{ {
...@@ -94,7 +94,7 @@ namespace UF.AssessmentProject.Providers ...@@ -94,7 +94,7 @@ namespace UF.AssessmentProject.Providers
} }
var checkUnitPrice = req.items.Where(x => x.unitprice < 0 ).ToList().Count(); var checkUnitPrice = req.items.Where(x => x.unitprice < 0 ).ToList().Count();
if (checkNameNull > 0) if (checkUnitPrice > 0)
{ {
return new Model.Transaction.ResponseMessage return new Model.Transaction.ResponseMessage
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment