public void Match_argument_by_declared_type_when_an_exact_match_is_found() { var sut = new CallInfo(new[] { CreateArg <object>("hello"), CreateArg("world") }); Assert.That(sut.Arg <object>(), Is.EqualTo("hello")); Assert.That(sut.Arg <string>(), Is.EqualTo("world")); }
public void Match_argument_by_actual_type_when_no_declared_type_match_is_found() { var sut = new CallInfo(new[] { CreateArg <object>(123), CreateArg <object>("hello") }); Assert.That(sut.Arg <string>(), Is.EqualTo("hello")); Assert.That(sut.Arg <int>(), Is.EqualTo(123)); }
private static IEnumerable <ArraySegment <LogEventInfo> > MakeBatch(CallInfo callInfo) { var array = callInfo.Arg <LogEventInfo[]>(); var length = callInfo.Arg <int>(); return(array == null?Enumerable.Empty <ArraySegment <LogEventInfo> >() : new[] { new ArraySegment <LogEventInfo>(array, 0, length) }); }
private IObservable <IEnumerable <IConflictResolutionResult <IDatabaseTimeEntry> > > batchUpdateResult(CallInfo info) { var conflictFn = info.Arg <Func <IDatabaseTimeEntry, IDatabaseTimeEntry, ConflictResolutionMode> >(); var entitiesToDelete = info.Arg <IEnumerable <(long Id, IDatabaseTimeEntry Entity)> >(); var result = entitiesToDelete.Select(ignoreResultFromTuple); return(Observable.Return(result)); IConflictResolutionResult <IDatabaseTimeEntry> ignoreResultFromTuple((long Id, IDatabaseTimeEntry Entity) tuple) { var entity = tuple.Id % 2 == 0 ? null : tuple.Entity; var confictMode = conflictFn(entity, null); switch (confictMode) { case ConflictResolutionMode.Ignore: return(new IgnoreResult <IDatabaseTimeEntry>(tuple.Id)); case ConflictResolutionMode.Delete: return(new DeleteResult <IDatabaseTimeEntry>(tuple.Id)); default: throw new InvalidOperationException("Unexpected conflict resolution mode in DeleteAll"); } } }
public void Match_by_ref_type_arguments_when_argument_that_is_the_non_by_ref_type_is_provided() { const int expectedResult = 5; var sut = new CallInfo(new[] { CreateArg <object>("aasdf"), new ByRefArgument <int>(expectedResult) }); Assert.That(sut.Arg <int>(), Is.EqualTo(expectedResult)); }
public void Match_argument_by_actual_type_when_no_declared_type_match_is_found_and_when_a_compatible_argument_is_provided() { var list = new List <int>(); var sut = new CallInfo(new[] { CreateArg <object>("asdf"), CreateArg <object>(list) }); Assert.That(sut.Arg <IEnumerable <int> >(), Is.SameAs(list)); }
public void Match_by_ref_type_arguments_when_argument_compatbile_non_by_ref_type_is_provided() { var list = new List <int>(); var sut = new CallInfo(new[] { CreateArg <object>("aasdf"), new ByRefArgument <List <int> >(list) }); Assert.That(sut.Arg <IEnumerable <int> >(), Is.EqualTo(list)); }
private ISpan AddSpan(CallInfo callInfo) { var span = Substitute.For <ISpan>(); span.Operation = callInfo.Arg <string>(); Spans.Add(span); return(span); }
private static DbParameter CreateParameterMockWithSize(CallInfo info) { DbParameter parameterMock = CreateParameterMock(info); var size = info.Arg <int>(); parameterMock.Size.Returns(size); return(parameterMock); }
static ITrackingCollection <IRemoteRepositoryModel> SetupRepositories( CallInfo callInfo, IObservable <IRemoteRepositoryModel> repositories) { var collection = callInfo.Arg <ITrackingCollection <IRemoteRepositoryModel> >(); collection.Listen(repositories); return(collection); }
private static async Task <IActionResult> PostAsyncReturn(CallInfo info) { IApplicationResult <bool> result = new ApplicationResult <bool>(); Tuple <bool, List <string> > validationResult = Validator.Validate(info.Arg <ChargeMessage>()); result.Data = validationResult.Item1; result.Messages.AddRange(validationResult.Item2); return(result); }
private static DbParameter CreateParameterMock(CallInfo info) { var parameterName = info.Arg <string>(); var dbType = info.Arg <DbType>(); var direction = info.Arg <ParameterDirection>(); var parameterMock = Substitute.For <DbParameter>(); parameterMock.ParameterName.Returns(parameterName); parameterMock.DbType.Returns(dbType); parameterMock.Direction.Returns(direction); if (dbType.Equals(DbType.Int32)) { parameterMock.Value.Returns(default(int)); } return(parameterMock); }
private void RouteAsyncFunction(CallInfo callInfo) { var routeContext = callInfo.Arg <RouteContext>(); routeContext.Handler = context => { switch (context.Request.Method) { case "GET": context.Response.StatusCode = 403; break; case "POST": context.Response.StatusCode = 404; break; default: context.Response.StatusCode = 200; break; } return(Task.CompletedTask); }; }
private static async Task RegisterAsyncReturn(CallInfo info) { lock (Charges) { Charges.Add(info.Arg <Charge>()); } }
public void Throw_when_there_is_no_declared_type_match_but_multiple_compatible_arguments() { var sut = new CallInfo(new[] { CreateArg <object>("a"), CreateArg <object>("b") }); Assert.Throws <AmbiguousArgumentsException>(() => sut.Arg <string>()); }
private static void InvokeAction(CallInfo callInfo) { callInfo.Arg <Action>()(); }
private static Task RegisterAsyncReturn(CallInfo info) { Clients.Add(info.Arg <Client>()); return(Task.CompletedTask); }
private static Client GetAsyncReturn(CallInfo info) { return(Clients.FirstOrDefault(it => it.Cpf == info.Arg <string>())); }