using System; using NUnit.Framework; namespace Chernobyl { [TestFixture, Description("Tests for the Validation type.")] public class ValidationTests { #region IfNull Tests [Test, Description("Ensures IfNull throws if value is null.")] public void IfNullThrowsWhenValueIsNull() => Assert.Throws(() => ((object)null).Throw("value").IfNull()); [Test, Description("Ensures IfNull does not throw if value is not null.")] public void IfNullDoesNotThrowWhenValueIsNotNull() => Assert.DoesNotThrow(() => "not null".Throw("value").IfNull()); #endregion #region IfLessThan Tests [Test, Description("Ensures IfLessThan throws if value is less than provided value.")] public void ThrowIfLessThanThrowsWhenValueIsLess() { Assert.Throws(() => 3.Throw("value").IfLessThan(4)); } [Test, Description("Ensures IfLessThan does not throw if value is equal to provided value.")] public void ThrowIfLessThanDoesNotThrowWhenValuesAreEqual() { Assert.DoesNotThrow(() => 3.Throw("value").IfLessThan(3)); } [Test, Description("Ensures IfLessThan does not throw if value is greater than to provided value.")] public void ThrowIfLessThanDoesNotThrowWhenValueIsGreaterThan() { Assert.DoesNotThrow(() => 3.Throw("value").IfLessThan(2)); } #endregion #region IfLessThanOrEqualTo Tests [Test, Description("Ensures IfLessThanOrEqualTo throws if value is less than provided value.")] public void ThrowIfLessThanOrEqualToThrowsWhenValueIsLess() { Assert.Throws(() => 3.Throw("value").IfLessThanOrEqualTo(4)); } [Test, Description("Ensures IfLessThanOrEqualTo does not throw if value is equal to provided value.")] public void ThrowIfLessThanOrEqualToDoesNotThrowWhenValuesAreEqual() { Assert.Throws(() => 3.Throw("value").IfLessThanOrEqualTo(3)); } [Test, Description("Ensures IfLessThanOrEqualTo does not throw if value is greater than to provided value.")] public void ThrowIfLessThanOrEqualToDoesNotThrowWhenValueIsGreaterThan() { Assert.DoesNotThrow(() => 3.Throw("value").IfLessThanOrEqualTo(2)); } #endregion #region IfGreaterThan Tests [Test, Description("Ensures IfGreaterThan throws if value is greater than provided value.")] public void ThrowIfGreaterThanThrowsWhenValueIsGreater() { Assert.Throws(() => 3.Throw("value").IfGreaterThan(2)); } [Test, Description("Ensures IfGreaterThan does not throw if value is equal to provided value.")] public void ThrowIfGreaterThanDoesNotThrowWhenValuesAreEqual() { Assert.DoesNotThrow(() => 3.Throw("value").IfGreaterThan(3)); } [Test, Description("Ensures IfGreaterThan does not throw if value is less than provided value.")] public void ThrowIfGreaterThanDoesNotThrowWhenValueIsLessThan() { Assert.DoesNotThrow(() => 3.Throw("value").IfGreaterThan(4)); } #endregion #region IfGreaterThanOrEqualTo Tests [Test, Description("Ensures ThrowIfGreaterThanEqualTo throws if value is greater than provided value.")] public void ThrowIfGreaterThanOrEqualToWhenValueIsGreater() { Assert.Throws(() => 3.Throw("value").IfGreaterThanOrEqualTo(2)); } [Test, Description("Ensures IfGreaterThanOrEqualTo throws if value is equal to provided value.")] public void ThrowIfGreaterThanOrEqualToThrowsWhenValuesAreEqual() { Assert.Throws(() => 3.Throw("value").IfGreaterThanOrEqualTo(3)); } [Test, Description("Ensures IfGreaterThanOrEqualTo does not throw if value is less than provided value.")] public void ThrowIfGreaterThanOrEqualToDoesNotThrowWhenValueIsLessThan() { Assert.DoesNotThrow(() => 3.Throw("value").IfGreaterThanOrEqualTo(4)); } #endregion #region IfEmpty Tests [Test, Description("Ensures IfEmpty throws when collection is empty.")] public void ThrowIfEmptyThrowsWhenCollectionIsEmpty() { Assert.Throws(() => "".Throw("value").IfEmpty()); } [Test, Description("Ensures IfEmpty throws when collection is empty.")] public void ThrowIfEmptyDoesNotThrowIfCollectionNotEmpty() { Assert.DoesNotThrow(() => "hello".Throw("value").IfEmpty()); } #endregion } }