예제 #1
0
        public async Task GetBucket_UsesParametersToGetBucketFromProvider()
        {
            // Arrange

            var collection = new Mock <ICouchbaseCollection>();

            var scope = new Mock <IScope>();

            scope
            .Setup(m => m.Collection("collection"))
            .Returns(collection.Object);

            var bucket = new Mock <IBucket>();

            bucket
            .Setup(m => m.Scope("scope"))
            .Returns(scope.Object);

            var bucketProvider = new Mock <INamedBucketProvider>();

            bucketProvider
            .Setup(m => m.GetBucketAsync())
            .ReturnsAsync(bucket.Object);

            var namedBucketProvider = new LocalCollectionBucketProvider(bucketProvider.Object, "scope", "collection");

            // Act

            var result = await namedBucketProvider.GetCollectionAsync();

            // Assert

            Assert.Equal(collection.Object, result);
        }
예제 #2
0
        public async Task GetCollectionAsync_MultipleCalls_ReturnsCachedResult()
        {
            // Arrange

            var collection = new Mock <ICouchbaseCollection>();

            var scope = new Mock <IScope>();

            scope
            .Setup(m => m.Collection("collection"))
            .Returns(collection.Object);

            var bucket = new Mock <IBucket>();

            bucket
            .Setup(m => m.Scope("scope"))
            .Returns(scope.Object);

            var bucketProvider = new Mock <INamedBucketProvider>();

            bucketProvider
            .Setup(m => m.GetBucketAsync())
            .ReturnsAsync(bucket.Object);

            var namedBucketProvider = new LocalCollectionBucketProvider(bucketProvider.Object, "scope", "collection");

            // Act

            var result = await namedBucketProvider.GetCollectionAsync();

            var result2 = await namedBucketProvider.GetCollectionAsync();

            // Assert

            Assert.Equal(result, result2);

            bucketProvider.Verify(
                m => m.GetBucketAsync(),
                Times.Once);
            scope.Verify(
                m => m.Collection(It.IsAny <string>()),
                Times.Once);
        }