Skip to content

Commit 67ec195

Browse files
committed
Added more error handling
1 parent 613b938 commit 67ec195

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

Src/DbQueryUtility/DbQueryUtilityService.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ public DbQueryUtilityService(IDbQueryRepository dbQueryRepository)
2323

2424
public XPathNavigator Query(string query, string configurationKey)
2525
{
26+
if(string.IsNullOrWhiteSpace(query))
27+
{
28+
throw new ArgumentNullException("query");
29+
}
30+
31+
if(string.IsNullOrWhiteSpace(configurationKey))
32+
{
33+
throw new ArgumentNullException("configurationKey");
34+
}
35+
2636
var doc = _dbQueryRepository.Query(query, configurationKey);
2737
var nav = doc.CreateNavigator();
2838

Src/DbQueryUtility/SqlDbQueryApplicationService.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using BizTalkComponents.Utilities.DbQueryUtility.Repository;
22
using System;
33
using System.Collections.Generic;
4+
using System.Diagnostics;
45
using System.Linq;
56
using System.Text;
67
using System.Threading.Tasks;
@@ -14,7 +15,18 @@ public XPathNavigator Query(string query, string configurationKey)
1415
{
1516
var util = new DbQueryUtilityService(new SqlDbQueryRepository());
1617

17-
return util.Query(query, configurationKey);
18+
XPathNavigator nav;
19+
20+
try
21+
{
22+
nav = util.Query(query, configurationKey);
23+
}
24+
catch(Exception ex)
25+
{
26+
Trace.WriteLine(String.Format("An exception was thrown in DbQueryUtity. {0}", ex.ToString()));
27+
throw ex;
28+
}
29+
return nav;
1830
}
1931
}
2032
}

Test/UnitTest/DbQueryServiceTest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,20 @@ public void TestHappyPath()
3838
Assert.AreEqual(3, result.Select("/result/node()").Count);
3939
Assert.AreEqual("param2value", result.SelectSingleNode("/result/param2").Value);
4040
}
41+
42+
[TestMethod]
43+
[ExpectedException(typeof(ArgumentNullException))]
44+
public void TestNoConfigurationKey()
45+
{
46+
var result = util.Query("SELECT * FROM Test", "");
47+
}
48+
49+
[TestMethod]
50+
[ExpectedException(typeof(ArgumentNullException))]
51+
public void TestNoQuery()
52+
{
53+
var result = util.Query("", "Key");
54+
}
55+
4156
}
4257
}

0 commit comments

Comments
 (0)