Mercurial > pub > bltoolkit
view UnitTests/Fluent/AssertExceptionEx.cs @ 9:1e85f66cf767 default tip
update bltoolkit
author | nickolay |
---|---|
date | Thu, 05 Apr 2018 20:53:26 +0300 |
parents | f990fcb411a9 |
children |
line wrap: on
line source
using System; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace BLToolkit.Fluent.Test { /// <summary> /// Класс для работы с асертами обладающий дополнительными методами /// </summary> public static class AssertExceptionEx { /// <summary> /// Проверка на обязательность исключения /// </summary> /// <typeparam name="T"></typeparam> /// <param name="action"></param> /// <param name="message"></param> public static void AreException<T>(Action action, string message) { bool isOk = false; try { action(); } catch (Exception e) { if (e is T) { isOk = true; } } if (!isOk) { Assert.Fail(message); } } /// <summary> /// Проверка на обязательность отсутсвия исключения /// </summary> /// <typeparam name="T"></typeparam> /// <param name="action"></param> /// <param name="message"></param> public static void AreNotException<T>(Action action, string message) { bool isOk = true; try { action(); } catch (Exception e) { if (e is T) { isOk = false; } } if (!isOk) { Assert.Fail(message); } } } }