protected InitializedBase() { var initializer = new PropertyInitializer(); //Initialize all strings initializer.Initialize <string>(this, "Juan"); //Initialize all integers initializer.Initialize <int>(this, 31); }
public void ItPassesThroughReplay(string testMethodName, string?expectedReplay) { var testClassType = typeof(Properties); var testMethodInfo = GetMethod(testMethodName); var result = PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, new DefaultPropertyFactory()); result.Parameters.Replay.Should().Be(expectedReplay); }
public void ItPassesThroughShrinkLimit(string testMethodName, int expectedShrinkLimit) { var testClassType = typeof(Properties); var testMethodInfo = GetMethod(testMethodName); var result = PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, new DefaultPropertyFactory()); result.Parameters.ShrinkLimit.Should().Be(expectedShrinkLimit); }
public void ItDoesNotPassThroughSize(string testMethodName) { var testClassType = typeof(Properties); var testMethodInfo = GetMethod(testMethodName); var result = PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, new DefaultPropertyFactory()); result.Parameters.Size.Should().Be(null); }
public void AMethodLevelFactoryIsPreferredOverAClassLevelFactory(string testMethodName) { var mockPropertyFactory = MockPropertyFactory(); var testClassType = typeof(PropertiesWithFactoryConfig); var testMethodInfo = GetMethod(testMethodName); PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, mockPropertyFactory.Object); VerifyFactoryPassedThrough(mockPropertyFactory, typeof(GenFactory1)); }
public void ItPassesThroughTheFactoryFromTheClass(string testMethodName) { var mockPropertyFactory = MockPropertyFactory(); var testClassType = typeof(PropertiesWithFactoryConfig); var testMethodInfo = GetMethod(testMethodName); PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, mockPropertyFactory.Object); VerifyFactoryPassedThrough(mockPropertyFactory, typeof(GenFactory2)); }
public void WhenClassNorMethodHasFactoryConfig_ItPassesThroughNull(string testMethodName) { var mockPropertyFactory = MockPropertyFactory(); var testClassType = typeof(PropertiesWithoutFactoryConfig); var testMethodInfo = GetMethod(testMethodName); PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, mockPropertyFactory.Object); VerifyFactoryNotPassedThrough(mockPropertyFactory); }
public void ItPassesThroughGenKeyedToCorrectIndex(string testMethodName, int expectedIndex) { var mockPropertyFactory = MockPropertyFactory(); var testClassType = typeof(Properties); var testMethodInfo = GetMethod(testMethodName); PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, mockPropertyFactory.Object); VerifyGenPassedThrough(mockPropertyFactory, Gen, expectedIndex); }
public void ItErrorsWhenReferencePropertyIsNotAGen(string testMethodName) { var testClassType = typeof(Properties); var testMethodInfo = GetMethod(testMethodName); Action test = () => PropertyInitializer.Initialize(testClassType, testMethodInfo, new object[] { }, new DefaultPropertyFactory()); test.Should() .Throw <Exception>() .WithMessage("Expected member 'NotAGen' to be an instance of 'GalaxyCheck.IGen', but it had a value of type 'System.Object'"); }
public override Task <RunSummary> RunAsync( IMessageSink diagnosticMessageSink, IMessageBus messageBus, object[] constructorArguments, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource) { messageBus.QueueMessage(new TestCaseStarting(this)); var startTime = DateTime.UtcNow; var test = new XunitTest(this, DisplayName); var testOutputHelper = constructorArguments .OfType <TestOutputHelper>() .FirstOrDefault() ?? new TestOutputHelper(); testOutputHelper.Initialize(messageBus, test); Task <RunSummary> Fail(Exception ex) { var executionTime = (decimal)((DateTime.UtcNow - startTime).TotalSeconds); messageBus.QueueMessage(new TestFailed(test, executionTime, testOutputHelper !.Output, ex)); return(Task.FromResult(new RunSummary() { Failed = 1 })); } Task <RunSummary> Pass() { var executionTime = (decimal)((DateTime.UtcNow - startTime).TotalSeconds); messageBus.QueueMessage(new TestPassed(test, executionTime, testOutputHelper !.Output)); return(Task.FromResult(new RunSummary() { Total = 1 })); } Task <RunSummary> Skip(string reason) { messageBus.QueueMessage(new TestSkipped(test, reason)); return(Task.FromResult(new RunSummary() { Skipped = 1 })); } PropertyInitializationResult?propertyInitResult; try { propertyInitResult = PropertyInitializer.Initialize( TestMethod.TestClass.Class.ToRuntimeType(), TestMethod.Method.ToRuntimeMethod(), constructorArguments, new DefaultPropertyFactory()); } catch (Exception exception) { return(Fail(exception)); } if (propertyInitResult.ShouldSkip) { return(Skip(propertyInitResult.SkipReason !)); } try { propertyInitResult.Runner.Run(propertyInitResult.Parameters, testOutputHelper); return(Pass()); } catch (Exception propertyFailedException) { return(Fail(propertyFailedException)); } }