From 5aab2368cae6f59bfc21922d518ed0d84d96068b Mon Sep 17 00:00:00 2001 From: bicijinlian Date: Fri, 3 Aug 2018 17:40:49 +0800 Subject: [PATCH] =?UTF-8?q?Assert=20=E5=9F=BA=E6=9C=AC=E5=AD=A6=E5=AE=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xUnitStudy.WebApi.Test/UseXUnitAssertTest.cs | 56 ++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/xUnitStudy.WebApi.Test/UseXUnitAssertTest.cs b/xUnitStudy.WebApi.Test/UseXUnitAssertTest.cs index 03a6086..31870d9 100644 --- a/xUnitStudy.WebApi.Test/UseXUnitAssertTest.cs +++ b/xUnitStudy.WebApi.Test/UseXUnitAssertTest.cs @@ -1042,6 +1042,9 @@ namespace xUnitStudy.WebApi.Test } #endregion + #region DoesNotContain 类似Contain 略过 + #endregion + #region InRange [Fact] @@ -1062,6 +1065,59 @@ namespace xUnitStudy.WebApi.Test Assert.InRange(person2, person1, person3, comparer); } + + #endregion + + #region NotInRange + [Fact] + public void NotInRange_Test() + { + Assert.NotInRange(5, 10, 100); + Assert.NotInRange(20, 100, 2000); + Assert.NotInRange("a", "b", "d"); + Assert.NotInRange("z", "b", "d"); + } + + [Fact] + public void NotInRange_IComparable_Test() + { + IComparer comparer = new Person(); + + Person person1 = new Person() { Id = 1 }; + Person person2 = new Person() { Id = 2 }; + Person person3 = new Person() { Id = 3 }; + + Assert.NotInRange(person1, person2, person3, comparer); + } + #endregion + + #region Throws + [Fact] + public void Throw_Exception_Test() + { + Assert.ThrowsAsync(()=> { throw new ArgumentNullException("message"); }); + } + + [Fact] + public void NotThrow_Exception_Test() + { + //2.0及更高版本,移除了 NotThrow断言 + //使用TryCatch替代或自定断言扩展 + + Exception exception = null; + try + { + //dosomething + exception = null; + } + catch (Exception ex) + { + exception = ex; + } + + Assert.Null(exception); + + } #endregion [Fact]