Added tests for ThrowIf validation logic

This commit is contained in:
Philip Dimitratos 2017-10-18 10:53:58 -07:00
Родитель a9e270d361
Коммит 51bc8e8175
2 изменённых файлов: 65 добавлений и 2 удалений

Просмотреть файл

@ -8,8 +8,6 @@ using System.Text;
namespace Sia.Shared.Tests.Data
{
[TestClass]
public class PartialJsonResolverTests
{

Просмотреть файл

@ -0,0 +1,65 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sia.Shared.Validation;
using System;
using System.Collections.Generic;
using System.Text;
namespace Sia.Shared.Tests.Validation
{
[TestClass]
public class ThrowIfTests
{
[TestMethod]
public void Null_StaticMethod_WhenObjectIsNotNull_ReturnsObject()
{
var input = new Object();
var result = ThrowIf.Null(input, nameof(input));
Assert.AreSame(input, result);
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void Null_StaticMethod_WhenObjectIsNull_ThrowsArgumentNullException()
{
object input = null;
var result = ThrowIf.Null(input, nameof(input));
//expect exception
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void NullOrWhiteSpace_StaticMethod_WhenInputIsNull_ThrowsArgumentException()
{
string input = null;
var result = ThrowIf.NullOrWhiteSpace(input, nameof(input));
//Expect exception
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void NullOrWhiteSpace_StaticMethod_WhenInputIsOnlyWhitespace_ThrowsArgumentException()
{
string input = " ";
var result = ThrowIf.NullOrWhiteSpace(input, nameof(input));
//Expect exception
}
[TestMethod]
public void NullOrWhiteSpace_StaticMethod_WhenInputStringWithAnyNonWhitespace_ReturnsString()
{
string input = " . ";
var result = ThrowIf.NullOrWhiteSpace(input, nameof(input));
Assert.AreSame(input, result);
}
}
}