Skip to content

Commit

Permalink
#28: Synergy.Contracts: Extracted dedicated test classes for DateTime…
Browse files Browse the repository at this point in the history
… failures.
  • Loading branch information
MarcinCelej committed Feb 6, 2024
1 parent 382351f commit f1a1423
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 120 deletions.
Original file line number Diff line number Diff line change
@@ -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<DesignByContractViolationException>(
() => 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<DesignByContractViolationException>(
() => 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);
}
}
48 changes: 48 additions & 0 deletions Contracts/Synergy.Contracts.Test/Failures/Dates/var.FailIfEmpty.cs
Original file line number Diff line number Diff line change
@@ -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<DesignByContractViolationException>(
() => 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<DesignByContractViolationException>(
() => 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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -44,5 +43,4 @@ public void FailIfNotDateSuccess(DateTime date)
// ASSERT
Assert.Equal(date, returned);
}

}
118 changes: 0 additions & 118 deletions Contracts/Synergy.Contracts.Test/Failures/FailDateTimeTest.cs

This file was deleted.

0 comments on commit f1a1423

Please sign in to comment.