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); }
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); }
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")); }
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;")); }
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); }
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); }
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); }
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;")); }