public void SingleParameterGetReturnsCorrectResult(int number) { // Fixture setup var fixture = new Fixture(); fixture.Inject(number); var builder = fixture.Compose(); // Exercise system var actual = builder.Get((int x) => -1 * x); // Verify outcome Assert.Equal(-1 * number, actual); // Teardown }
public void DoubleParameterGetReturnsCorrectResult( int number, string text) { // Fixture setup var fixture = new Fixture(); fixture.Inject(number); fixture.Inject(text); var builder = fixture.Compose(); // Exercise system var actual = builder.Get((int x, string y) => x + y); // Verify outcome Assert.Equal(number + text, actual); // Teardown }
public void DoubleParameterDoWillInvokeMethodWithCorrectParameters( int expectedNumber, string expectedText) { // Fixture setup var fixture = new Fixture(); fixture.Inject(expectedNumber); fixture.Inject(expectedText); var builder = fixture.Compose(); var verified = false; var mock = new CommandMock<int, string>(); mock.OnCommand = (x, y) => verified = expectedNumber == x && expectedText == y; // Exercise system builder.Do((int x, string y) => mock.Command(x, y)); // Verify outcome Assert.True(verified, "Mock wasn't verified."); // Teardown }
public void QuadrupleParameterDoWillInvokeMethodWithCorrectParameters( int expectedNumber, string expectedText, Type expectedType, bool expectedBool) { // Fixture setup var fixture = new Fixture(); fixture.Inject(expectedNumber); fixture.Inject(expectedText); fixture.Inject(expectedType); fixture.Inject(expectedBool); var builder = fixture.Compose(); var verified = false; var mock = new CommandMock<int, string, Type, bool>(); mock.OnCommand = (x, y, z, æ) => verified = expectedNumber == x && expectedText == y && expectedType == z && expectedBool == æ; // Exercise system builder.Do( (int x, string y, Type z, bool æ) => mock.Command(x, y, z, æ)); // Verify outcome Assert.True(verified, "Mock wasn't verified."); // Teardown }
public void TripleParameterDoWillInvokeMethodWithCorrectParameters( string expectedText, int expectedNumber, bool expectedBool) { // Fixture setup var fixture = new Fixture(); fixture.Inject(expectedText); fixture.Inject(expectedNumber); fixture.Inject(expectedBool); var builder = fixture.Compose(); var verified = false; var mock = new CommandMock<string, int, bool>(); mock.OnCommand = (x, y, z) => verified = expectedText == x && expectedNumber == y && expectedBool == z; // Exercise system builder.Do((string x, int y, bool z) => mock.Command(x, y, z)); // Verify outcome Assert.True(verified, "Mock wasn't verified."); // Teardown }
public void FixtureDoesNotHijackCollectionInterfacesIfAnotherCustomizationExistsForThem(Type collectionInterface) { // Fixture setup var fixture = new Fixture().Customize(new MultipleCustomization()).Customize(new AutoNSubstituteCustomization()); var context = new SpecimenContext(fixture.Compose()); // Exercise system var result = context.Resolve(new SeededRequest(collectionInterface, null)); // Verify outcome Assert.NotEmpty((IEnumerable)result); }
public void ComposeWhenAutoPropertiesAreEnabledReturnsCorrectResult() { // Fixture setup var sut = new Fixture(); // Exercise system var result = sut.Compose(); // Verify outcome var guard = Assert.IsAssignableFrom<RecursionGuard>(result); var composedBuilders = Assert.IsAssignableFrom<CompositeSpecimenBuilder>(guard.Builder).ToList(); var customizer = Assert.IsAssignableFrom<CompositeSpecimenBuilder>(composedBuilders[0]); Assert.True(sut.Customizations.SequenceEqual(customizer)); var postprocessor = Assert.IsAssignableFrom<Postprocessor>(composedBuilders[1]); var engineAndMultiple = Assert.IsAssignableFrom<CompositeSpecimenBuilder>(postprocessor.Builder); Assert.Same(sut.Engine, engineAndMultiple.First()); Assert.IsAssignableFrom<AnyTypeSpecification>(postprocessor.Specification); var residueCollector = Assert.IsAssignableFrom<CompositeSpecimenBuilder>(composedBuilders[2]); Assert.True(sut.ResidueCollectors.SequenceEqual(residueCollector)); Assert.IsAssignableFrom<TerminatingSpecimenBuilder>(composedBuilders[3]); // Teardown }
public void ComposeCorrectlyAppliesBehaviors() { // Fixture setup var sut = new Fixture(); var comparer = new TaggedNodeComparer(new TrueComparer<ISpecimenBuilder>()); sut.Behaviors.Clear(); sut.Behaviors.Add(new DelegatingSpecimenBuilderTransformation { OnTransform = b => new TaggedNode(1, b) }); sut.Behaviors.Add(new DelegatingSpecimenBuilderTransformation { OnTransform = b => comparer.Equals(new TaggedNode(1), b) ? new TaggedNode(2, b) : new TaggedNode(3, b) }); // Exercise system var result = sut.Compose(); // Verify outcome Assert.Equal(new TaggedNode(2), result, comparer); // Teardown }
public void ComposeReturnsInstance() { // Fixture setup var sut = new Fixture(); // Exercise system var result = sut.Compose(); // Verify outcome Assert.NotNull(result); // Teardown }
public void ComposeWhenAutoPropertiesAreOmittedReturnsCorrectResult() { // Fixture setup var sut = new Fixture { OmitAutoProperties = true }; // Exercise system var result = sut.Compose(); // Verify outcome var guard = Assert.IsAssignableFrom<RecursionGuard>(result); var composedBuilders = Assert.IsAssignableFrom<CompositeSpecimenBuilder>(guard.Builder).Builders.ToList(); var customizer = Assert.IsAssignableFrom<CompositeSpecimenBuilder>(composedBuilders[0]); Assert.Equal(sut.Customizations, customizer.Builders); Assert.Equal(sut.Engine, composedBuilders[1]); var residueCollector = Assert.IsAssignableFrom<CompositeSpecimenBuilder>(composedBuilders[2]); Assert.Equal(sut.ResidueCollectors, residueCollector.Builders); Assert.IsAssignableFrom<TerminatingSpecimenBuilder>(composedBuilders[3]); // Teardown }
public void ComposeCorrectlyAppliesBehaviors() { // Fixture setup var sut = new Fixture(); var builder1 = new DelegatingSpecimenBuilder(); var builder2 = new DelegatingSpecimenBuilder(); sut.Behaviors.Clear(); sut.Behaviors.Add(new DelegatingSpecimenBuilderTransformation { OnTransform = b => builder1 }); sut.Behaviors.Add(new DelegatingSpecimenBuilderTransformation { OnTransform = b => b == builder1 ? builder2 : new DelegatingSpecimenBuilder() }); // Exercise system var result = sut.Compose(); // Verify outcome Assert.Equal(builder2, result); // Teardown }
public void TripleParameterGetReturnsCorrectResult( string text, bool logical, long number) { // Fixture setup var fixture = new Fixture(); fixture.Inject(text); fixture.Inject(logical); fixture.Inject(number); var builder = fixture.Compose(); // Exercise system var actual = builder.Get((string x, bool y, long z) => x + y + z); // Verify outcome Assert.Equal(text + logical + number, actual); // Teardown }
public void QuadrupleParameterGetReturnsCorrectResult( Type type, bool logical, int number, string text) { // Fixture setup var fixture = new Fixture(); fixture.Inject(type); fixture.Inject(logical); fixture.Inject(number); fixture.Inject(text); var builder = fixture.Compose(); // Exercise system var actual = builder.Get((Type x, bool y, int z, string æ) => x.ToString() + y + z + æ); // Verify outcome Assert.Equal( type.ToString() + logical + number + text, actual); // Teardown }