Ejemplo n.º 1
0
        private (ContainerInternal, Mock <BatchAsyncContainerExecutor>) CreateMockBulkCosmosClientContext()
        {
            CosmosClientContext context = MockCosmosUtil.CreateMockCosmosClient(
                builder => builder.WithBulkExecution(true)).ClientContext;
            Mock <CosmosClientContext> mockContext = new Mock <CosmosClientContext>();

            mockContext.Setup(x => x.CreateLink(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns <string, string, string>((x, y, z) => context.CreateLink(x, y, z));
            mockContext.Setup(x => x.ClientOptions).Returns(context.ClientOptions);
            mockContext.Setup(x => x.ResponseFactory).Returns(context.ResponseFactory);
            mockContext.Setup(x => x.SerializerCore).Returns(context.SerializerCore);
            mockContext.Setup(x => x.DocumentClient).Returns(context.DocumentClient);
            mockContext.Setup(x => x.ProcessResourceOperationStreamAsync(
                                  It.IsAny <Uri>(),
                                  It.IsAny <ResourceType>(),
                                  It.IsAny <OperationType>(),
                                  It.IsAny <RequestOptions>(),
                                  It.IsAny <ContainerInternal>(),
                                  It.IsAny <Cosmos.PartitionKey?>(),
                                  It.IsAny <string>(),
                                  It.IsAny <Stream>(),
                                  It.IsAny <Action <RequestMessage> >(),
                                  It.IsAny <CosmosDiagnosticsContext>(),
                                  It.IsAny <CancellationToken>())).Returns <Uri, ResourceType, OperationType, RequestOptions, ContainerInternal, Cosmos.PartitionKey, string, Stream, Action <RequestMessage>, CosmosDiagnosticsContext, CancellationToken>(
                (uri, resourceType, operationType, requestOptions, containerInternal, pk, itemId, stream, requestEnricher, diagnostics, cancellationToken) =>
                context.ProcessResourceOperationStreamAsync(
                    uri,
                    resourceType,
                    operationType,
                    requestOptions,
                    containerInternal,
                    pk,
                    itemId,
                    stream,
                    requestEnricher,
                    diagnostics,
                    cancellationToken));

            Mock <BatchAsyncContainerExecutor> mockedExecutor = this.GetMockedBatchExcecutor();

            mockContext.Setup(x => x.GetExecutorForContainer(It.IsAny <ContainerInternal>())).Returns(mockedExecutor.Object);

            DatabaseInternal  db        = new DatabaseInlineCore(mockContext.Object, "test");
            ContainerInternal container = new ContainerInlineCore(mockContext.Object, db, "test");

            return(container, mockedExecutor);
        }
Ejemplo n.º 2
0
        private (ContainerInternal, Mock <BatchAsyncContainerExecutor>) CreateMockBulkCosmosClientContext()
        {
            CosmosClientContext context = MockCosmosUtil.CreateMockCosmosClient(
                builder => builder.WithBulkExecution(true)).ClientContext;
            Mock <CosmosClientContext> mockContext = new Mock <CosmosClientContext>();

            mockContext.Setup(x => x.CreateLink(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns <string, string, string>((x, y, z) => context.CreateLink(x, y, z));
            mockContext.Setup(x => x.ClientOptions).Returns(context.ClientOptions);
            mockContext.Setup(x => x.ResponseFactory).Returns(context.ResponseFactory);
            mockContext.Setup(x => x.SerializerCore).Returns(context.SerializerCore);
            mockContext.Setup(x => x.DocumentClient).Returns(context.DocumentClient);

            mockContext.Setup(x => x.OperationHelperAsync <ResponseMessage>(
                                  It.IsAny <string>(),
                                  It.IsAny <RequestOptions>(),
                                  It.IsAny <Func <ITrace, Task <ResponseMessage> > >(),
                                  It.IsAny <TraceComponent>(),
                                  It.IsAny <TraceLevel>()))
            .Returns <string, RequestOptions, Func <ITrace, Task <ResponseMessage> >, TraceComponent, TraceLevel>(
                (operationName, requestOptions, func, comp, level) => func(NoOpTrace.Singleton));

            mockContext.Setup(x => x.OperationHelperAsync <ItemResponse <dynamic> >(
                                  It.IsAny <string>(),
                                  It.IsAny <RequestOptions>(),
                                  It.IsAny <Func <ITrace, Task <ItemResponse <dynamic> > > >(),
                                  It.IsAny <TraceComponent>(),
                                  It.IsAny <TraceLevel>()))
            .Returns <string, RequestOptions, Func <ITrace, Task <ItemResponse <dynamic> > >, TraceComponent, TraceLevel>(
                (operationName, requestOptions, func, comp, level) => func(NoOpTrace.Singleton));

            mockContext.Setup(x => x.ProcessResourceOperationStreamAsync(
                                  It.IsAny <string>(),
                                  It.IsAny <ResourceType>(),
                                  It.IsAny <OperationType>(),
                                  It.IsAny <RequestOptions>(),
                                  It.IsAny <ContainerInternal>(),
                                  It.IsAny <Cosmos.PartitionKey?>(),
                                  It.IsAny <string>(),
                                  It.IsAny <Stream>(),
                                  It.IsAny <Action <RequestMessage> >(),
                                  It.IsAny <ITrace>(),
                                  It.IsAny <CancellationToken>())).Returns <string, ResourceType, OperationType, RequestOptions, ContainerInternal, Cosmos.PartitionKey, string, Stream, Action <RequestMessage>, ITrace, CancellationToken>(
                (uri, resourceType, operationType, requestOptions, containerInternal, pk, itemId, stream, requestEnricher, trace, cancellationToken) =>
                context.ProcessResourceOperationStreamAsync(
                    uri,
                    resourceType,
                    operationType,
                    requestOptions,
                    containerInternal,
                    pk,
                    itemId,
                    stream,
                    requestEnricher,
                    trace,
                    cancellationToken));

            Mock <BatchAsyncContainerExecutor> mockedExecutor = this.GetMockedBatchExcecutor();

            mockContext.Setup(x => x.GetExecutorForContainer(It.IsAny <ContainerInternal>())).Returns(mockedExecutor.Object);

            DatabaseInternal  db        = new DatabaseInlineCore(mockContext.Object, "test");
            ContainerInternal container = new ContainerInlineCore(mockContext.Object, db, "test");

            return(container, mockedExecutor);
        }