Skip to content

Commit

Permalink
Desing improvments
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrzajac committed Nov 16, 2023
1 parent 4434ede commit 6d45cbd
Show file tree
Hide file tree
Showing 15 changed files with 452 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,16 @@ public void GivenUninitializedType_WhenConstructorIsInvoked_ThenExceptionIsThrow
Assert.Throws<ArgumentNullException>(() => new CustomizeWithAttribute(customizationType));
}

[Fact(DisplayName = "GIVEN unsupported type WHEN GetCustomization is invoked THEN exception is thrown")]
public void GivenUnsupportedType_WhenGetCustomizationIsInvoked_ThenExceptionIsThrown()
[Fact(DisplayName = "GIVEN unsupported type WHEN constructor is invoked THEN exception is thrown")]
public void GivenUnsupportedType_WhenConstructorIsInvoked_ThenExceptionIsThrown()
{
// Arrange
var customizationType = typeof(string);
var customizeAttribute = new CustomizeWithAttribute(customizationType);
var parameter = typeof(CustomizeWithAttributeTests)
.GetMethod(nameof(this.MethodUnderTest), BindingFlags.Instance | BindingFlags.NonPublic)
.GetParameters()
.First();

// Act
// Assert
Assert.Throws<InvalidOperationException>(() => customizeAttribute.GetCustomization(parameter));
var exception = Assert.Throws<ArgumentException>(() => new CustomizeWithAttribute(customizationType));
exception.Message.Should().NotBeNullOrEmpty().And.Contain(nameof(ICustomization));
}

[Fact(DisplayName = "GIVEN CustomizeWith attribute with IncludeParameterType set WHEN GetCustomization is invoked THEN customization with expected type is returned")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public void GivenValidParameters_WhenConstructorIsInvoked_ThenParametersArePrope
public void GivenRengeSpecified_WhenBytePopulated_ThenTheValueFromRangeIsGenerated(
[FromRange(Ranges.ByteRange.Min, Ranges.ByteRange.Max)] byte rangeValue)
{
// Arrange
// Act
// Assert
rangeValue.Should().BeInRange(Ranges.ByteRange.Min, Ranges.ByteRange.Max);
}

Expand All @@ -63,6 +66,9 @@ public void GivenRengeSpecified_WhenBytePopulated_ThenTheValueFromRangeIsGenerat
public void GivenRengeSpecified_WhenUShortPopulated_ThenTheValueFromRangeIsGenerated(
[FromRange(Ranges.UShortRange.Min, Ranges.UShortRange.Max)] ushort rangeValue)
{
// Arrange
// Act
// Assert
rangeValue.Should().BeInRange(Ranges.UShortRange.Min, Ranges.UShortRange.Max);
}

Expand All @@ -71,6 +77,9 @@ public void GivenRengeSpecified_WhenUShortPopulated_ThenTheValueFromRangeIsGener
public void GivenRengeSpecified_WhenUIntPopulated_ThenTheValueFromRangeIsGenerated(
[FromRange(Ranges.UIntRange.Min, Ranges.UIntRange.Max)] uint rangeValue)
{
// Arrange
// Act
// Assert
rangeValue.Should().BeInRange(Ranges.UIntRange.Min, Ranges.UIntRange.Max);
}

Expand All @@ -79,6 +88,9 @@ public void GivenRengeSpecified_WhenUIntPopulated_ThenTheValueFromRangeIsGenerat
public void GivenRengeSpecified_WhenULongPopulated_ThenTheValueFromRangeIsGenerated(
[FromRange(Ranges.ULongRange.Min, Ranges.ULongRange.Max)] ulong rangeValue)
{
// Arrange
// Act
// Assert
rangeValue.Should().BeInRange(Ranges.ULongRange.Min, Ranges.ULongRange.Max);
}

Expand All @@ -87,6 +99,9 @@ public void GivenRengeSpecified_WhenULongPopulated_ThenTheValueFromRangeIsGenera
public void GivenRengeSpecified_WhenSBytePopulated_ThenTheValueFromRangeIsGenerated(
[FromRange(Ranges.SByteRange.Min, Ranges.SByteRange.Max)] sbyte rangeValue)
{
// Arrange
// Act
// Assert
rangeValue.Should().BeInRange(Ranges.SByteRange.Min, Ranges.SByteRange.Max);
}

Expand All @@ -96,6 +111,9 @@ public void GivenRengeSpecified_WhenShortPopulated_ThenOnlyDecoratedParameterHas
[FromRange(Ranges.ShortRange.Min, Ranges.ShortRange.Max)] short rangeValue,
short unrestrictedValue)
{
// Arrange
// Act
// Assert
rangeValue.Should().BeInRange(Ranges.ShortRange.Min, Ranges.ShortRange.Max);
unrestrictedValue.Should().BeGreaterThanOrEqualTo(0);
}
Expand All @@ -106,6 +124,9 @@ public void GivenRengeSpecified_WhenIntPopulated_ThenOnlyDecoratedParameterHasVa
[FromRange(Ranges.IntRange.Min, Ranges.IntRange.Max)] int rangeValue,
int unrestrictedValue)
{
// Arrange
// Act
// Assert
rangeValue.Should().BeInRange(Ranges.IntRange.Min, Ranges.IntRange.Max);
unrestrictedValue.Should().BeGreaterThanOrEqualTo(0);
}
Expand All @@ -116,6 +137,9 @@ public void GivenRengeSpecified_WhenLongPopulated_ThenOnlyDecoratedParameterHasV
[FromRange(Ranges.LongRange.Min, Ranges.LongRange.Max)] long rangeValue,
long unrestrictedValue)
{
// Arrange
// Act
// Assert
rangeValue.Should().BeInRange(Ranges.LongRange.Min, Ranges.LongRange.Max);
unrestrictedValue.Should().BeGreaterThanOrEqualTo(0);
}
Expand All @@ -126,6 +150,9 @@ public void GivenRengeSpecified_WhenFloatPopulated_ThenOnlyDecoratedParameterHas
[FromRange(Ranges.FloatRange.Min, Ranges.FloatRange.Max)] float rangeValue,
float unrestrictedValue)
{
// Arrange
// Act
// Assert
rangeValue.Should().BeInRange(Ranges.FloatRange.Min, Ranges.FloatRange.Max);
unrestrictedValue.Should().BeGreaterThanOrEqualTo(0);
}
Expand All @@ -136,6 +163,9 @@ public void GivenRengeSpecified_WhenDoublePopulated_ThenOnlyDecoratedParameterHa
[FromRange(Ranges.DoubleRange.Min, Ranges.DoubleRange.Max)] double rangeValue,
double unrestrictedValue)
{
// Arrange
// Act
// Assert
rangeValue.Should().BeInRange(Ranges.DoubleRange.Min, Ranges.DoubleRange.Max);
unrestrictedValue.Should().BeGreaterThanOrEqualTo(0);
}
Expand All @@ -146,6 +176,9 @@ public void GivenRengeSpecified_WhenDecimalPopulated_ThenOnlyDecoratedParameterH
[FromRange((double)Ranges.DecimalRange.Min, (double)Ranges.DecimalRange.Max)] decimal rangeValue,
decimal unrestrictedValue)
{
// Arrange
// Act
// Assert
rangeValue.Should().BeInRange(Ranges.DecimalRange.Min, Ranges.DecimalRange.Max);
unrestrictedValue.Should().BeGreaterThanOrEqualTo(0);
}
Expand All @@ -156,6 +189,9 @@ public void GivenRengeSpecified_WhenDecimalPopulated_ThenOnlyDecoratedParameterH
public void GivenRengeSpecifiedAndInlineValueOutsideRange_WhenDataPopulated_ThenValuesFromRangeAreIgnoredAndInlineOneIsUsed(
[FromRange(Ranges.IntRange.Min, Ranges.IntRange.Max)] int value, int expectedResult)
{
// Arrange
// Act
// Assert
value.Should().Be(expectedResult).And.NotBeInRange(Ranges.IntRange.Min, Ranges.IntRange.Max);
}

Expand All @@ -164,6 +200,9 @@ public void GivenRengeSpecifiedAndInlineValueOutsideRange_WhenDataPopulated_Then
public void GivenRengeSpecifiedAndMemberDataValueOutsideRange_WhenDataPopulated_ThenValuesFromRangeAreIgnoredAndMemberDataIsUsed(
[FromRange(Ranges.IntRange.Min, Ranges.IntRange.Max)] int value, int expectedResult)
{
// Arrange
// Act
// Assert
value.Should().Be(expectedResult).And.NotBeInRange(Ranges.IntRange.Min, Ranges.IntRange.Max);
}

Expand All @@ -173,6 +212,9 @@ public void GivenRengeSpecified_WhenArraysPopulated_ThenOnlyDecoratedParameterHa
[FromRange(Ranges.IntRange.Min, Ranges.IntRange.Max)] int[] rangeValues,
int[] unrestrictedValues)
{
// Arrange
// Act
// Assert
rangeValues.Should().AllSatisfy(x => x.Should().BeInRange(Ranges.IntRange.Min, Ranges.IntRange.Max));
unrestrictedValues.Should().AllSatisfy(x => x.Should().BeGreaterThanOrEqualTo(0));
}
Expand All @@ -183,6 +225,9 @@ public void GivenRengeSpecified_WhenEnumerablesPopulated_ThenOnlyDecoratedParame
[FromRange(Ranges.IntRange.Min, Ranges.IntRange.Max)] IEnumerable<int> rangeValues,
IEnumerable<int> unrestrictedValues)
{
// Arrange
// Act
// Assert
rangeValues.Should().AllSatisfy(x => x.Should().BeInRange(Ranges.IntRange.Min, Ranges.IntRange.Max));
unrestrictedValues.Should().AllSatisfy(x => x.Should().BeGreaterThanOrEqualTo(0));
}
Expand All @@ -194,6 +239,9 @@ public void GivenRengeSpecified_WhenListPopulated_ThenOnlyDecoratedParameterHasV
[FromRange(Ranges.IntRange.Min, Ranges.IntRange.Max)] List<int> rangeValues,
List<int> unrestrictedValues)
{
// Arrange
// Act
// Assert
rangeValues.Should().AllSatisfy(x => x.Should().BeInRange(Ranges.IntRange.Min, Ranges.IntRange.Max));
unrestrictedValues.Should().AllSatisfy(x => x.Should().BeGreaterThanOrEqualTo(0));
}
Expand All @@ -205,6 +253,9 @@ public void GivenRengeSpecified_WhenSetsPopulated_ThenOnlyDecoratedParameterHasV
[FromRange(Ranges.IntRange.Min, Ranges.IntRange.Max)] HashSet<int> rangeValues,
HashSet<int> unrestrictedValues)
{
// Arrange
// Act
// Assert
rangeValues.Should().AllSatisfy(x => x.Should().BeInRange(Ranges.IntRange.Min, Ranges.IntRange.Max));
unrestrictedValues.Should().AllSatisfy(x => x.Should().BeGreaterThanOrEqualTo(0));
}
Expand All @@ -216,6 +267,9 @@ public void GivenRengeSpecified_WhenCollectionsPopulated_ThenOnlyDecoratedParame
[FromRange(Ranges.IntRange.Min, Ranges.IntRange.Max)] Collection<int> rangeValues,
Collection<int> unrestrictedValues)
{
// Arrange
// Act
// Assert
rangeValues.Should().AllSatisfy(x => x.Should().BeInRange(Ranges.IntRange.Min, Ranges.IntRange.Max));
unrestrictedValues.Should().AllSatisfy(x => x.Should().BeGreaterThanOrEqualTo(0));
}
Expand All @@ -227,6 +281,9 @@ public void GivenRengeSpecified_WhenReadOnlyCollectionsPopulated_ThenOnlyDecorat
[FromRange(Ranges.IntRange.Min, Ranges.IntRange.Max)] ReadOnlyCollection<int> rangeValues,
ReadOnlyCollection<int> unrestrictedValues)
{
// Arrange
// Act
// Assert
rangeValues.Should().AllSatisfy(x => x.Should().BeInRange(Ranges.IntRange.Min, Ranges.IntRange.Max));
unrestrictedValues.Should().AllSatisfy(x => x.Should().BeGreaterThanOrEqualTo(0));
}
Expand All @@ -236,6 +293,9 @@ public void GivenRengeSpecified_WhenReadOnlyCollectionsPopulated_ThenOnlyDecorat
public void GivenRengeWithSingleValue_WhenArrayPopulated_ThenAllValuesEqualSpecifiedOne(
[FromRange(Ranges.IntRange.Min, Ranges.IntRange.Min)] int[] rangeValues)
{
// Arrange
// Act
// Assert
rangeValues.Should().HaveCountGreaterThan(1).And.AllSatisfy(x => x.Should().Be(Ranges.IntRange.Min));
}

Expand Down
Loading

0 comments on commit 6d45cbd

Please sign in to comment.