From f1a1423d4875edf7e4cab994d2e9bd19911110c7 Mon Sep 17 00:00:00 2001 From: Marcin Celej Date: Tue, 6 Feb 2024 16:23:16 +0100 Subject: [PATCH] #28: Synergy.Contracts: Extracted dedicated test classes for DateTime failures. --- .../Failures/Dates/Fail.IfDateEmpty.cs | 45 +++++++ .../Failures/Dates/var.FailIfEmpty.cs | 48 +++++++ .../Failures/Dates/var.FailIfNotDateTest.cs | 2 - .../Failures/FailDateTimeTest.cs | 118 ------------------ 4 files changed, 93 insertions(+), 120 deletions(-) create mode 100644 Contracts/Synergy.Contracts.Test/Failures/Dates/Fail.IfDateEmpty.cs create mode 100644 Contracts/Synergy.Contracts.Test/Failures/Dates/var.FailIfEmpty.cs delete mode 100644 Contracts/Synergy.Contracts.Test/Failures/FailDateTimeTest.cs diff --git a/Contracts/Synergy.Contracts.Test/Failures/Dates/Fail.IfDateEmpty.cs b/Contracts/Synergy.Contracts.Test/Failures/Dates/Fail.IfDateEmpty.cs new file mode 100644 index 0000000..dc77dc1 --- /dev/null +++ b/Contracts/Synergy.Contracts.Test/Failures/Dates/Fail.IfDateEmpty.cs @@ -0,0 +1,45 @@ +using System; +using Xunit; + +namespace Synergy.Contracts.Test.Failures.Dates; + +public class IfDateEmptyTest +{ + [Fact] + public void IfDateEmptyWithName() + { + // ARRANGE + DateTime minDate = DateTime.MinValue; + + // ACT + var exception = Assert.Throws( + () => Fail.IfEmpty(minDate, nameof(minDate)) + ); + + // ASSERT + Assert.Equal("'minDate' is empty = 01/01/0001 00:00:00", exception.Message); + } + + [Fact] + public void IfDateEmptyWithCallerArgumentExpression() + { + // ARRANGE + DateTime minDate = DateTime.MinValue; + + // ACT + var exception = Assert.Throws( + () => Fail.IfEmpty(minDate) + ); + + // ASSERT + Assert.Equal("'minDate' is empty = 01/01/0001 00:00:00", exception.Message); + } + + [Fact] + public void IfDateEmptySuccess() + { + // ACT + Fail.IfEmpty(DateTime.Today, nameof(DateTime.Today)); + Fail.IfEmpty(DateTime.Today); + } +} \ No newline at end of file diff --git a/Contracts/Synergy.Contracts.Test/Failures/Dates/var.FailIfEmpty.cs b/Contracts/Synergy.Contracts.Test/Failures/Dates/var.FailIfEmpty.cs new file mode 100644 index 0000000..56b72f8 --- /dev/null +++ b/Contracts/Synergy.Contracts.Test/Failures/Dates/var.FailIfEmpty.cs @@ -0,0 +1,48 @@ +using System; +using Xunit; + +namespace Synergy.Contracts.Test.Failures.Dates; + +public class FailIfEmptyTest +{ + [Fact] + public void FailIfDateEmpty() + { + // ARRANGE + DateTime minDate = DateTime.MinValue; + + // ACT + var exception = Assert.Throws( + () => minDate.FailIfEmpty(nameof(minDate)) + ); + + // ASSERT + Assert.Equal("'minDate' is empty = 01/01/0001 00:00:00", exception.Message); + } + + [Fact] + public void FailIfDateEmptyCallerArgumentExpression() + { + // ARRANGE + DateTime minDate = DateTime.MinValue; + + // ACT + var exception = Assert.Throws( + () => minDate.FailIfEmpty() + ); + + // ASSERT + Assert.Equal("'minDate' is empty = 01/01/0001 00:00:00", exception.Message); + } + + [Fact] + public void FailIfDateEmptySuccess() + { + // ACT + // ReSharper disable once UnusedVariable + var date1 = DateTime.Today.FailIfEmpty(nameof(DateTime.Today)); + // ReSharper disable once UnusedVariable + var date2 = DateTime.Today.FailIfEmpty(); + } + +} \ No newline at end of file diff --git a/Contracts/Synergy.Contracts.Test/Failures/Dates/var.FailIfNotDateTest.cs b/Contracts/Synergy.Contracts.Test/Failures/Dates/var.FailIfNotDateTest.cs index 9685a17..a7ca160 100644 --- a/Contracts/Synergy.Contracts.Test/Failures/Dates/var.FailIfNotDateTest.cs +++ b/Contracts/Synergy.Contracts.Test/Failures/Dates/var.FailIfNotDateTest.cs @@ -5,7 +5,6 @@ namespace Synergy.Contracts.Test.Failures.Dates; public class FailIfNotDateTest { - [Theory] [MemberData(nameof(DateTimeTestData.GetDatesWithTime), MemberType = typeof(DateTimeTestData))] public void FailIfNotDate(DateTime dateTime) @@ -44,5 +43,4 @@ public void FailIfNotDateSuccess(DateTime date) // ASSERT Assert.Equal(date, returned); } - } \ No newline at end of file diff --git a/Contracts/Synergy.Contracts.Test/Failures/FailDateTimeTest.cs b/Contracts/Synergy.Contracts.Test/Failures/FailDateTimeTest.cs deleted file mode 100644 index 662fd27..0000000 --- a/Contracts/Synergy.Contracts.Test/Failures/FailDateTimeTest.cs +++ /dev/null @@ -1,118 +0,0 @@ -using System; -using System.Collections.Generic; -using JetBrains.Annotations; -using NUnit.Framework; -using Synergy.Contracts.Samples; - -namespace Synergy.Contracts.Test.Failures -{ - [TestFixture] - public class FailDateTimeTest - { - - #region Fail.IfDateEmpty - - [Test] - public void IfDateEmpty() - { - // ARRANGE - DateTime minDate = DateTime.MinValue; - - // ACT - var exception = Assert.Throws( - () => Fail.IfEmpty(minDate, nameof(minDate)) - ); - - // ASSERT - Assert.That(exception.Message, Is.EqualTo("'minDate' is empty = 01/01/0001 00:00:00")); - } - - [Test] - public void IfDateEmptyCallerArgumentExpression() - { - // ARRANGE - DateTime minDate = DateTime.MinValue; - - // ACT - var exception = Assert.Throws( - () => Fail.IfEmpty(minDate) - ); - - // ASSERT - Assert.That(exception.Message, Is.EqualTo("'minDate' is empty = 01/01/0001 00:00:00")); - } - - [Test] - public void IfDateEmptySuccess() - { - // ACT - Fail.IfEmpty(DateTime.Today, nameof(DateTime.Today)); - Fail.IfEmpty(DateTime.Today); - } - - #endregion - - #region Fail.FailIfDateEmpty - - [Test] - public void FailIfDateEmpty() - { - // ARRANGE - DateTime minDate = DateTime.MinValue; - - // ACT - var exception = Assert.Throws( - () => minDate.FailIfEmpty(nameof(minDate)) - ); - - // ASSERT - Assert.That(exception.Message, Is.EqualTo("'minDate' is empty = 01/01/0001 00:00:00")); - } - - [Test] - public void FailIfDateEmptyCallerArgumentExpression() - { - // ARRANGE - DateTime minDate = DateTime.MinValue; - - // ACT - var exception = Assert.Throws( - () => minDate.FailIfEmpty() - ); - - // ASSERT - Assert.That(exception.Message, Is.EqualTo("'minDate' is empty = 01/01/0001 00:00:00")); - } - - [Test] - public void FailIfDateEmptySuccess() - { - // ACT - // ReSharper disable once UnusedVariable - var date1 = DateTime.Today.FailIfEmpty(nameof(DateTime.Today)); - // ReSharper disable once UnusedVariable - var date2 = DateTime.Today.FailIfEmpty(); - } - - #endregion - - [ItemCanBeNull] - private static IEnumerable GetDates() - { - yield return null; - yield return DateTime.Today; - yield return DateTime.MinValue; - //yield return DateTime.MaxValue; - yield return new DateTime(2019,03,26); - - } - - private static IEnumerable GetDatesWithTime() - { - yield return DateTime.MaxValue; - yield return new DateTime(2019,03,26).AddMilliseconds(1); - - } - - } -} \ No newline at end of file