Skip to content

Commit 9635c78

Browse files
committed
Add units tests
1 parent 3994d5c commit 9635c78

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

FakeApiTest/FakeHttpRequesterTests.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public void ShouldThrowCustomException()
290290
public void ShouldThrowExceptionWhenRequestIsNull()
291291
{
292292
//Arrange
293-
var requester = new FakeHttpRequester("");
293+
var requester = new FakeHttpRequester("DownloadFile.txt");
294294

295295
//Act
296296
var exception = Assert.ThrowsException<ArgumentNullException>(() =>
@@ -301,5 +301,31 @@ public void ShouldThrowExceptionWhenRequestIsNull()
301301
//Assert
302302
Assert.AreEqual("request", exception.ParamName);
303303
}
304+
305+
[TestMethod]
306+
public void ShouldThrowExceptionWhenConfigSourceIsNull()
307+
{
308+
//Act
309+
var exception = Assert.ThrowsException<ArgumentNullException>(() =>
310+
{
311+
new FakeHttpRequester(null);
312+
});
313+
314+
//Assert
315+
Assert.AreEqual("configSource", exception.ParamName);
316+
}
317+
318+
[TestMethod]
319+
public void ShouldThrowExceptionWhenFileNotExists()
320+
{
321+
//Act
322+
var exception = Assert.ThrowsException<FileLoadException>(() =>
323+
{
324+
new FakeHttpRequester("FakePath");
325+
});
326+
327+
//Assert
328+
Assert.AreEqual("File FakePath nor exists", exception.Message);
329+
}
304330
}
305331
}

Src/FakeApi/FakeHttpRequester.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public class FakeHttpRequester: IHttpRequester
2121
public FakeHttpRequester(string configSource)
2222
{
2323
_configSource = configSource ?? throw new ArgumentNullException(nameof(configSource));
24+
if(!File.Exists(configSource))
25+
{
26+
throw new FileLoadException($"File {configSource} nor exists");
27+
}
2428
}
2529

2630
/// <summary>

0 commit comments

Comments
 (0)