Ejemplo n.º 1
0
            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"));
            }
Ejemplo n.º 2
0
            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));
            }
Ejemplo n.º 3
0
        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) });
        }
Ejemplo n.º 4
0
        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");
                }
            }
        }
Ejemplo n.º 5
0
            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));
            }
Ejemplo n.º 6
0
            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));
            }
Ejemplo n.º 7
0
            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));
            }
Ejemplo n.º 8
0
        private ISpan AddSpan(CallInfo callInfo)
        {
            var span = Substitute.For <ISpan>();

            span.Operation = callInfo.Arg <string>();
            Spans.Add(span);
            return(span);
        }
Ejemplo n.º 9
0
        private static DbParameter CreateParameterMockWithSize(CallInfo info)
        {
            DbParameter parameterMock = CreateParameterMock(info);
            var         size          = info.Arg <int>();

            parameterMock.Size.Returns(size);
            return(parameterMock);
        }
Ejemplo n.º 10
0
    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);
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        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);
            };
        }
Ejemplo n.º 14
0
 private static async Task RegisterAsyncReturn(CallInfo info)
 {
     lock (Charges) { Charges.Add(info.Arg <Charge>()); }
 }
Ejemplo n.º 15
0
            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>());
            }
Ejemplo n.º 16
0
 private static void InvokeAction(CallInfo callInfo)
 {
     callInfo.Arg <Action>()();
 }
Ejemplo n.º 17
0
 private static Task RegisterAsyncReturn(CallInfo info)
 {
     Clients.Add(info.Arg <Client>());
     return(Task.CompletedTask);
 }
Ejemplo n.º 18
0
 private static Client GetAsyncReturn(CallInfo info)
 {
     return(Clients.FirstOrDefault(it => it.Cpf == info.Arg <string>()));
 }