コード例 #1
0
        public void Test_Authenticate()
        {
            //arrange
            var clusterMock = new Mock<ICluster>();
            clusterMock.Setup(x => x.OpenBucket(It.IsAny<string>())).Returns(new Mock<IBucket>().Object);
            clusterMock.Setup(x => x.Authenticate(It.IsAny<IClusterCredentials>()));
            var cluster = clusterMock.Object;

            var credentials = new ClusterCredentials
            {
                ClusterUsername = "******",
                ClusterPassword = "",
                BucketCredentials = new Dictionary<string, string>
                {
                    {"default", "" },
                    {"authenticated", "secret" },
                    {"memcached", "" },
                    {"travel-sample", "wayward1" }
                }
            };

            //act
            cluster.Authenticate(credentials);
            var bucket = cluster.OpenBucket("authenticated");

            //assert
            Assert.IsNotNull(bucket);
        }
コード例 #2
0
        public void Test_CanAuthenticate_Views()
        {
            var credentials = new ClusterCredentials
            {
                ClusterUsername = "******",
                ClusterPassword = "******",
                BucketCredentials = new AttributeDictionary
                {
                    {"authenticated", "secret"}
                }
            };

            var cluster = new Cluster(TestConfiguration.GetCurrentConfiguration());

            cluster.Authenticate(credentials);

            //if authentication failed - an exception would be thrown during bootstrapping
            var bucket = cluster.OpenBucket("authenticated");
            var query = bucket.CreateQuery("somedoc", "someview");
            var result = bucket.Query<dynamic>(query);

            //assert - view does not exist but should still return a response and no auth error
            Assert.IsFalse(result.Success);
            Assert.AreEqual(HttpStatusCode.NotFound, result.StatusCode);
        }
コード例 #3
0
 public void Test_Query_WhenBucketOpenedThatIsNotInAuthenticator_Fails()
 {
     var cluster = new Cluster(TestConfiguration.GetCurrentConfiguration());
     var credentials = new ClusterCredentials
     {
         BucketCredentials = new Dictionary<string, string>
         {
             {"authenticated", "secret"}
         }
     };
     cluster.Authenticate(credentials);
     Assert.Throws<AuthenticationException>(() => cluster.OpenBucket("default"));
 }
コード例 #4
0
        public void Test_Query_WhenInvalidPassword_ThrowsException()
        {
            var cluster = new Cluster(TestConfiguration.GetCurrentConfiguration());
            var credentials = new ClusterCredentials
            {
                BucketCredentials = new Dictionary<string, string>
                {
                    {"authenticated", "secret1"}
                }
            };
            cluster.Authenticate(credentials);

            Assert.Throws<AggregateException>(()=>cluster.Query<dynamic>("select * from authenticated limit 1;"));
        }
コード例 #5
0
        public void Test_Query()
        {
            var cluster = new Cluster(TestConfiguration.GetCurrentConfiguration());
            var credentials = new ClusterCredentials
            {
                BucketCredentials = new Dictionary<string, string>
                {
                    {"authenticated", "secret"}
                }
            };
            cluster.Authenticate(credentials);

            var result = cluster.Query<dynamic>("select * from authenticated limit 1;");
            Assert.AreEqual(QueryStatus.Success, result.Status);
        }
コード例 #6
0
        public void Test_CanAuthenticate_KV()
        {
            var credentials = new ClusterCredentials
            {
                ClusterUsername = "******",
                ClusterPassword = "******",
                BucketCredentials = new AttributeDictionary
                {
                    {"authenticated", "secret"}
                }
            };

            var cluster = new Cluster(TestConfiguration.GetCurrentConfiguration());

            cluster.Authenticate(credentials);

            var bucket = cluster.OpenBucket("authenticated");
            var result = bucket.Upsert("thekey", "thevalue");
            Assert.IsTrue(result.Success);
        }
コード例 #7
0
        public void Test_CanAuthenticate_N1QL()
        {
            var credentials = new ClusterCredentials
            {
                ClusterUsername = "******",
                ClusterPassword = "******",
                BucketCredentials = new Dictionary<string, string>
                {
                    {"authenticated", "secret"}
                }
            };

            var cluster = new Cluster(TestConfiguration.GetCurrentConfiguration());

            cluster.Authenticate(credentials);

            var bucket = cluster.OpenBucket("authenticated");

            var query = new QueryRequest("SELECT * FROM `authenticated`;");
            var result = bucket.Query<dynamic>(query);

            Assert.IsTrue(result.Success);
        }
コード例 #8
0
        public void Test_Query_WhenAuthenticateNotCalled_ThrowsInvalidOperationException()
        {
            var cluster = new Cluster(TestConfiguration.GetCurrentConfiguration());
            var credentials = new ClusterCredentials
            {
                BucketCredentials = new Dictionary<string, string>
                {
                    {"authenticated", "secret1"}
                }
            };

            Assert.Throws<InvalidOperationException>(() => cluster.Query<dynamic>("select * from authenticated limit 1;"));
        }