public static IReturnValueConfiguration <BuildResult> WhenBuildAnyArguments(this IReturnValueArgumentValidationConfiguration <BuildResult> fake) => fake.WhenArgumentsMatch( arguments => { var unitId = arguments.Get <UnitId>(0); return(unitId.Kind is ParameterInfo[]); });
public void Setup(string stepText, string functionName, bool hasInlineTable, params string[] parameters) { var vsProject = A.Fake <Project>(); var project = A.Fake <IProject>(); var step = A.Fake <IStep>(); A.CallTo(() => step.Text).Returns(stepText); A.CallTo(() => step.Parameters).Returns(new List <string>(parameters)); A.CallTo(() => step.HasInlineTable).Returns(hasInlineTable); A.CallTo(() => project.VsProject).Returns(vsProject); _textSnapshotLine = A.Fake <ITextSnapshotLine>(); A.CallTo(() => _textSnapshotLine.GetText()).Returns(stepText); var codeClass = A.Fake <CodeClass>(); _functionCall = A.CallTo(() => codeClass.AddFunction(functionName, vsCMFunction.vsCMFunctionFunction, vsCMTypeRef.vsCMTypeRefVoid, -1, vsCMAccess.vsCMAccessPublic, A <object> ._)); var codeFunction = A.Fake <CodeFunction>(); _functionCall.Returns(codeFunction); A.CallTo(() => project.FindOrCreateClass(SelectedClass)).Returns(codeClass); _stepImplementationGenerator = new StepImplementationGenerator(project, step); }
public static void CallsDataRetriever <T>(this IReturnValueArgumentValidationConfiguration <Task <CacheValue <T> > > configuration) => configuration .ReturnsLazily(async call => { var dataRetriever = (Func <Task <T> >)call.Arguments[1]; var result = await dataRetriever(); return(new CacheValue <T>(result, result != null)); });
public void Arrange(IReturnValueArgumentValidationConfiguration <Task <ITwitterResult <TDTO> > > callToQueryExecutor) { if (_expectedResults != null) { throw new InvalidOperationException("Can only be run once"); } _expectedResults = CreatePages(); callToQueryExecutor.ReturnsNextFromSequence(_expectedResults); }
public static void MultipleReturns( IFoo fake, IReturnValueArgumentValidationConfiguration <int> configuration, Exception exception) { "establish" .x(() => fake = A.Fake <IFoo>()); "when configuring multiple returns on the same configuration" .x(() => { configuration = A.CallTo(() => fake.Baz()); configuration.Returns(42); exception = Record.Exception(() => configuration.Returns(0)); }); "it should throw an invalid operation exception" .x(() => exception.Should().BeAnExceptionOfType <InvalidOperationException>()); }
public static void ReturnThenCallsBaseMethod( IFoo fake, IReturnValueArgumentValidationConfiguration <int> configuration, Exception exception) { "establish" .x(() => fake = A.Fake <IFoo>()); "when configuring a return then base method call on the same configuration" .x(() => { configuration = A.CallTo(() => fake.Baz()); configuration.Returns(42); exception = Record.Exception(() => configuration.CallsBaseMethod()); }); "it should throw an InvalidOperationException" .x(() => exception.Should().BeAnExceptionOfType <InvalidOperationException>()); }
public static void MultipleThrows( IFoo fake, IReturnValueArgumentValidationConfiguration <int> configuration, Exception exception) { "establish" .x(() => fake = A.Fake <IFoo>()); "when configuring a return then a throw on the same configuration" .x(() => { configuration = A.CallTo(() => fake.Baz()); configuration.Throws(new ArgumentNullException()); exception = Record.Exception(() => configuration.Throws(new ArgumentException())); }); "it should throw an InvalidOperationException" .x(() => exception.Should().BeAnExceptionOfType <InvalidOperationException>()); }
public virtual void SetUp() { _stateTransitionOrchestrator = _stateTransitionOrchestrator.Fake(); _uninitialisedStateFactory = _uninitialisedStateFactory.Fake(); _creatingStateFactory = _creatingStateFactory.Fake(); _validStateFactory = _validStateFactory.Fake(); _expiredStateFactory = _expiredStateFactory.Fake(); _updatingStateFactory = _updatingStateFactory.Fake(); _getProjectionLockFactory = _getProjectionLockFactory.Fake(); _uninitialisedState = _uninitialisedState.Fake(); _creatingState = _creatingState.Fake(); _validState = _validState.Fake(); _expiredState = _expiredState.Fake(); _updatingState = _updatingState.Fake(); _initialiseStateCall = A.CallTo(() => _stateTransitionOrchestrator.TransitionToState(A <IState <Department> > .That.Matches(state => state.Id == StateId.Uninitialised))); _initialiseStateTask = new Task(() => {}); _initialiseStateCall.Returns(_initialiseStateTask); ConfigureStateFactory_ToReturnState(_uninitialisedStateFactory, _uninitialisedState); ConfigureStateFactory_ToReturnState(_creatingStateFactory, _creatingState); ConfigureStateFactory_ToReturnState(_validStateFactory, _validState); ConfigureStateFactory_ToReturnState(_expiredStateFactory, _expiredState); ConfigureStateFactory_ToReturnState(_updatingStateFactory, _updatingState); ConfigureState_ToHaveStateId(_uninitialisedState, StateId.Uninitialised); ConfigureState_ToHaveStateId(_creatingState, StateId.Creating); ConfigureState_ToHaveStateId(_validState, StateId.Valid); ConfigureState_ToHaveStateId(_expiredState, StateId.Expired); ConfigureState_ToHaveStateId(_updatingState, StateId.Updating); _sut = new ProjectionSystem <Department>( _stateTransitionOrchestrator, _uninitialisedStateFactory, _creatingStateFactory, _validStateFactory, _expiredStateFactory, _updatingStateFactory, _getProjectionLockFactory); }
public static void MultipleThrows( IFoo fake, IReturnValueArgumentValidationConfiguration <int> configuration, Exception exception) { "Given a fake" .x(() => fake = A.Fake <IFoo>()); "And I configure the return method to throw an exception" .x(() => { configuration = A.CallTo(() => fake.Baz()); configuration.Throws <ArgumentNullException>(); }); "When I use the same configuration object to have the method throw an exception again" .x(() => exception = Record.Exception(() => configuration.Throws <ArgumentException>())); "Then it throws an invalid operation exception" .x(() => exception.Should().BeAnExceptionOfType <InvalidOperationException>()); }
public static void ReturnThenCallsBaseMethod( IFoo fake, IReturnValueArgumentValidationConfiguration <int> configuration, Exception exception) { "Given a fake" .x(() => fake = A.Fake <IFoo>()); "And I configure the return value for the method" .x(() => { configuration = A.CallTo(() => fake.Baz()); configuration.Returns(42); }); "When I use the same configuration object to have the method call the base method" .x(() => exception = Record.Exception(() => configuration.CallsBaseMethod())); "Then it throws an invalid operation exception" .x(() => exception.Should().BeAnExceptionOfType <InvalidOperationException>()); }
public static IReturnValueConfiguration <BuildResult> WhenBuildArgumentsOfType <T1, T2, T3, T4, T5, T6, T7>( this IReturnValueArgumentValidationConfiguration <BuildResult> fake) => fake.WhenArgumentsMatch( arguments => { var types = new[] { typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7) }.Where(_ => _ != typeof(Unit)).ToArray(); var unitId = arguments.Get <UnitId>(0); var parameters = unitId.Kind as ParameterInfo[]; if (unitId.Tag != SpecialTag.Argument || parameters?.Length != types.Length) { return(false); } for (var i = 0; i < parameters.Length; i++) { if (parameters[i].ParameterType != types[i]) { return(false); } } return(true); });
public static IAfterCallSpecifiedWithOutAndRefParametersConfiguration ReturnsAsync <TResult>(this IReturnValueArgumentValidationConfiguration <Task <TResult> > valueConfiguration, TResult value) { return(valueConfiguration.Returns(Task.FromResult(value))); }
public static void MultipleReturns( IFoo fake, IReturnValueArgumentValidationConfiguration<int> configuration, Exception exception) { "establish" .x(() => fake = A.Fake<IFoo>()); "when configuring multiple returns on the same configuration" .x(() => { configuration = A.CallTo(() => fake.Baz()); configuration.Returns(42); exception = Record.Exception(() => configuration.Returns(0)); }); "it should throw an invalid operation exception" .x(() => exception.Should().BeAnExceptionOfType<InvalidOperationException>()); }
public static void MultipleReturns( IFoo fake, IReturnValueArgumentValidationConfiguration<int> configuration, Exception exception) { "Given a fake" .x(() => fake = A.Fake<IFoo>()); "And I configure the return value for the method" .x(() => { configuration = A.CallTo(() => fake.Baz()); configuration.Returns(42); }); "When I use the same configuration object to set the return value again" .x(() => exception = Record.Exception(() => configuration.Returns(0))); "Then it throws an invalid operation exception" .x(() => exception.Should().BeAnExceptionOfType<InvalidOperationException>()); }
public static void MultipleThrows( IFoo fake, IReturnValueArgumentValidationConfiguration<int> configuration, Exception exception) { "establish" .x(() => fake = A.Fake<IFoo>()); "when configuring a return then a throw on the same configuration" .x(() => { configuration = A.CallTo(() => fake.Baz()); configuration.Throws(new ArgumentNullException()); exception = Record.Exception(() => configuration.Throws(new ArgumentException())); }); "it should throw an InvalidOperationException" .x(() => exception.Should().BeAnExceptionOfType<InvalidOperationException>()); }
public static void ReturnThenCallsBaseMethod( IFoo fake, IReturnValueArgumentValidationConfiguration<int> configuration, Exception exception) { "establish" .x(() => fake = A.Fake<IFoo>()); "when configuring a return then base method call on the same configuration" .x(() => { configuration = A.CallTo(() => fake.Baz()); configuration.Returns(42); exception = Record.Exception(() => configuration.CallsBaseMethod()); }); "it should throw an InvalidOperationException" .x(() => exception.Should().BeAnExceptionOfType<InvalidOperationException>()); }
public static void AddAssertValidation(this IReturnValueArgumentValidationConfiguration <Expression <Action> > callSpecification, CallValidator callValidator) { callSpecification.Invokes(call => callValidator.SetArguments(call.Arguments)).Returns(() => MarkIsTrue(callValidator)); }
public FakeItEasyQueryOptions(IReturnValueArgumentValidationConfiguration <TReturnValue> configuration) { _configuration = configuration; }
public static UnorderedCallAssertion MustHaveHappenedOnceAndOnly <TInterface>(this IReturnValueArgumentValidationConfiguration <TInterface> configuration) { // once exactly call with specified and with any arguments means only call with specified arguments was performed configuration.MustHaveHappenedOnceExactly(); return(configuration.WithAnyArguments().MustHaveHappenedOnceExactly()); }
public PostMethod() { _aCallToSubmitHandlerPostAsync = A.CallTo(() => _submitHandler.PostAsync(A <SubmitKey> ._, A <string> ._)); }
public static IReturnValueConfiguration <BuildResult> WhenBuildArgumentsOfType <T1, T2, T3, T4, T5, T6>( this IReturnValueArgumentValidationConfiguration <BuildResult> fake) => fake.WhenBuildArgumentsOfType <T1, T2, T3, T4, T5, T6, Unit>();