-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reviving validations lost during v2.0 rewriting.
- Loading branch information
Showing
8 changed files
with
266 additions
and
52 deletions.
There are no files selected for viewing
12 changes: 10 additions & 2 deletions
12
...tory/Core/Transforms/Guards/Specifications/ApplyTransformToFirstInstancesSpecification.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...ory.Tests/Core/Transforms/Guards/Specifications/AlwaysApplyTransformSpecificationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using FluentAssertions; | ||
using ForeverFactory.Core.Transforms.Guards.Specifications; | ||
using Xunit; | ||
|
||
namespace ForeverFactory.Tests.Core.Transforms.Guards.Specifications | ||
{ | ||
public class AlwaysApplyTransformSpecificationTests | ||
{ | ||
[Fact] | ||
public void It_should_apply_if_no_conditions_were_set() | ||
{ | ||
var guardSpecification = new AlwaysApplyTransformSpecification(); | ||
|
||
var canApply = guardSpecification.CanApply(0); | ||
|
||
canApply.Should().BeTrue(); | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...Core/Transforms/Guards/Specifications/ApplyTransformToFirstInstancesSpecificationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using FluentAssertions; | ||
using ForeverFactory.Core.Transforms.Guards.Specifications; | ||
using Xunit; | ||
|
||
namespace ForeverFactory.Tests.Core.Transforms.Guards.Specifications | ||
{ | ||
public class ApplyTransformToFirstInstancesSpecificationTests | ||
{ | ||
[Theory] | ||
[InlineData(0, 2, true)] | ||
[InlineData(1, 2, true)] | ||
[InlineData(2, 2, false)] | ||
public void It_should_apply_only_to_the_first_n_instances(int currentIndex, int countToApply, bool expected) | ||
{ | ||
var guardSpecification = new ApplyTransformToFirstInstancesSpecification(countToApply, targetCount: 2); | ||
|
||
var canApply = guardSpecification.CanApply(currentIndex); | ||
|
||
canApply.Should().Be(expected); | ||
} | ||
|
||
[Theory] | ||
[InlineData(2, 1)] | ||
[InlineData(3, 2)] | ||
public void It_should_throw_if_count_to_apply_to_first_n_instances_is_greater_than_target_count(int countToApply, int targetCount) | ||
{ | ||
Action invalidConfigurationBuild = | ||
() => new ApplyTransformToFirstInstancesSpecification(countToApply, targetCount); | ||
|
||
invalidConfigurationBuild.Should() | ||
.Throw<ArgumentException>("it is not possible to apply transformations beyond set size"); | ||
} | ||
|
||
[Theory] | ||
[InlineData(-10)] | ||
[InlineData(-1)] | ||
public void It_should_throw_if_count_to_apply_to_first_n_instances_is_negative(int countToApply) | ||
{ | ||
Action invalidConfigurationBuild = | ||
() => new ApplyTransformToFirstInstancesSpecification(countToApply, targetCount: 2); | ||
|
||
invalidConfigurationBuild.Should() | ||
.Throw<ArgumentException>("it is not possible to apply transformations to negative counts"); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
.../Core/Transforms/Guards/Specifications/ApplyTransformToLastInstancesSpecificationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using FluentAssertions; | ||
using ForeverFactory.Core.Transforms.Guards.Specifications; | ||
using Xunit; | ||
|
||
namespace ForeverFactory.Tests.Core.Transforms.Guards.Specifications | ||
{ | ||
public class ApplyTransformToLastInstancesSpecificationTests | ||
{ | ||
[Theory] | ||
[InlineData(0, 2, 4, false)] | ||
[InlineData(1, 2, 4, false)] | ||
[InlineData(2, 2, 4, true)] | ||
[InlineData(3, 2, 4, true)] | ||
public void It_should_apply_only_to_the_last_n_instances(int currentIndex, int countToApply, int targetCount, | ||
bool expected) | ||
{ | ||
var guardSpecification = new ApplyTransformToLastInstancesSpecification(countToApply, targetCount); | ||
|
||
var canApply = guardSpecification.CanApply(currentIndex); | ||
|
||
canApply.Should().Be(expected); | ||
} | ||
|
||
[Theory] | ||
[InlineData(2, 1)] | ||
[InlineData(3, 2)] | ||
public void It_should_throw_if_count_to_apply_to_last_n_instances_is_greater_than_target_count(int countToApply, int targetCount) | ||
{ | ||
Action invalidConfigurationBuild = | ||
() => new ApplyTransformToLastInstancesSpecification(countToApply, targetCount); | ||
|
||
invalidConfigurationBuild.Should() | ||
.Throw<ArgumentException>("it is not possible to apply transformations beyond set size"); | ||
} | ||
|
||
[Theory] | ||
[InlineData(-10)] | ||
[InlineData(-1)] | ||
public void It_should_throw_if_count_to_apply_to_last_n_instances_is_negative(int countToApply) | ||
{ | ||
Action invalidConfigurationBuild = | ||
() => new ApplyTransformToLastInstancesSpecification(countToApply, targetCount: 2); | ||
|
||
invalidConfigurationBuild.Should() | ||
.Throw<ArgumentException>("it is not possible to apply transformations to negative counts"); | ||
} | ||
} | ||
} |
47 changes: 0 additions & 47 deletions
47
...actory.Tests/Core/Transforms/Guards/Specifications/CanApplyTransformSpecificationTests.cs
This file was deleted.
Oops, something went wrong.
126 changes: 126 additions & 0 deletions
126
tests/ForeverFactory.Tests/MultipleInstanceBuildingTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using FluentAssertions; | ||
using ForeverFactory.Tests.CustomizedFactories.ExampleFactories; | ||
using Xunit; | ||
|
||
namespace ForeverFactory.Tests | ||
{ | ||
public class MultipleInstanceBuildingTests | ||
{ | ||
[Fact] | ||
public void Should_throw_an_argument_exception_for_first_count_bigger_than_total_size() | ||
{ | ||
Action invalidConfigurationBuild = () => new ProductFactory() | ||
.Many(10) | ||
.WithFirst(count: 11, x => x.Description = "xxx") | ||
.Build(); | ||
|
||
invalidConfigurationBuild.Should() | ||
.Throw<ArgumentException>("it is not possible to apply transformations beyond set size"); | ||
} | ||
|
||
[Fact] | ||
public void Should_throw_an_argument_exception_for_last_count_bigger_than_total_size() | ||
{ | ||
Action invalidConfigurationBuild = () => new ProductFactory() | ||
.Many(10) | ||
.WithLast(count: 11, x => x.Description = "xxx") | ||
.Build(); | ||
|
||
invalidConfigurationBuild.Should() | ||
.Throw<ArgumentException>("it is not possible to apply transformations beyond set size"); | ||
} | ||
|
||
[Fact] | ||
public void WithFirst_applies_transformation_only_over_the_first_n_instances_produced() | ||
{ | ||
var songs = new ProductFactory() | ||
.Many(10) | ||
.With(x => x.Description = "Dies Irae") | ||
.WithFirst(count: 2, x => x.Description = "Requiem II: Dies Irae") | ||
.Build() | ||
.ToList(); | ||
|
||
var firstTwo = songs.Take(2); | ||
foreach (var song in firstTwo) | ||
{ | ||
song.Description.Should().Be("Requiem II: Dies Irae"); | ||
} | ||
|
||
var lastEight = songs.Skip(2); | ||
foreach (var song in lastEight) | ||
{ | ||
song.Description.Should().Be("Dies Irae"); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void WithFirst_transforms_are_applied_in_order_overriding_previous_ones() | ||
{ | ||
var products = new ProductFactory() | ||
.Many(10) | ||
.With(x => x.Description = "Default description") | ||
.WithFirst(5, x => x.Description = "Original first five") | ||
.WithFirst(2, x => x.Description = "New first two") | ||
.Build() | ||
.ToArray(); | ||
|
||
var firstTwo = products.Take(2).Select(x => x.Description); | ||
firstTwo.Should().OnlyContain(x => x == "New first two"); | ||
|
||
var nextThree = products.Skip(2).Take(3).Select(x => x.Description); | ||
nextThree.Should().OnlyContain(x => x == "Original first five"); | ||
|
||
var lastFive = products.Skip(5).Select(x => x.Description); | ||
lastFive.Should().OnlyContain(x => x == "Default description"); | ||
} | ||
|
||
[Fact] | ||
public void WithLast_transforms_are_applied_in_order_overriding_previous_ones() | ||
{ | ||
var products = new ProductFactory() | ||
.Many(10) | ||
.With(x => x.Description = "Default description") | ||
.WithLast(5, x => x.Description = "Original last five") | ||
.WithLast(2, x => x.Description = "New last two") | ||
.Build() | ||
.ToArray(); | ||
|
||
var firstFive = products.Take(5).Select(x => x.Description); | ||
firstFive.Should().OnlyContain(x => x == "Default description"); | ||
|
||
var nextThree = products.Skip(5).Take(3).Select(x => x.Description); | ||
nextThree.Should().OnlyContain(x => x == "Original last five"); | ||
|
||
var lastTwo = products.Skip(8).Select(x => x.Description); | ||
lastTwo.Should().OnlyContain(x => x == "New last two"); | ||
} | ||
|
||
[Fact] | ||
public void WithLast_applies_transformation_only_over_the_last_x_instances_produced() | ||
{ | ||
var songs = new ProductFactory() | ||
.Many(10) | ||
.With(x => x.Description = "Dies Irae") | ||
.WithLast(count: 2, x => x.Description = "Requiem II: Dies Irae") | ||
.Build() | ||
.ToList(); | ||
|
||
songs.Should().HaveCount(10); | ||
|
||
var firstEight = songs.Take(8); | ||
foreach (var song in firstEight) | ||
{ | ||
song.Description.Should().Be("Dies Irae"); | ||
} | ||
|
||
var lastTwo = songs.Skip(8); | ||
foreach (var song in lastTwo) | ||
{ | ||
song.Description.Should().Be("Requiem II: Dies Irae"); | ||
} | ||
} | ||
} | ||
} |