public void Test_Statement() { var query = new QueryRequest(). BaseUri(new Uri(string.Format("http://{0}:8093/query", _server))). Statement("SELECT * FROM default"); var values = query.GetFormValues(); Assert.AreEqual("SELECT * FROM default", values["statement"]); }
public void Test_Positional_Parameters() { var query = new QueryRequest(). BaseUri(new Uri(string.Format("http://{0}:8093/query", _server))). Statement("SELECT * FROM default WHERE type=$1"). AddPositionalParameter("dog"); var values = query.GetFormValues(); Assert.AreEqual("SELECT * FROM default WHERE type=$1", values["statement"]); Assert.AreEqual(new[] {"dog"}, values["args"]); }
public void Test_Statement_ClientContextId_Pretty() { var query = new QueryRequest(). BaseUri(new Uri(string.Format("http://{0}:8093/query", _server))). Statement("SELECT * FROM default"). ClientContextId("somecontextlessthanorequalto64chars"). Pretty(true); var values = query.GetFormValues(); Assert.AreEqual(true, values["pretty"]); }
public void Test_Statement_ClientContextId() { var query = new QueryRequest(). BaseUri(new Uri(string.Format("http://{0}:8093/query", _server))). Statement("SELECT * FROM default"). ClientContextId("somecontextlessthanorequalto64chars"); var values = query.GetFormValues(); string contextid = values["client_context_id"].ToString().Split(new String[] {"::"}, System.StringSplitOptions.None)[0]; Assert.AreEqual("somecontextlessthanorequalto64chars", contextid); }
public void GetFormValues_MultipleTokensSameVBucketId_HighestSequenceNumberIsUsed2() { var document1 = new Mock<IDocument<dynamic>>(); document1.Setup(x => x.Token).Returns(new MutationToken("bucket1_name", 102, 22, 9999)); var document2 = new Mock<IDocument<dynamic>>(); document2.Setup(x => x.Token).Returns(new MutationToken("bucket1_name", 102, 11, 8332)); var document3 = new Mock<IDocument<dynamic>>(); document3.Setup(x => x.Token).Returns(new MutationToken("bucket2_name", 133, 23, 333)); var queryRequest = new QueryRequest("SELECT * FROM `bucket1_name`;"). ConsistentWith(MutationState.From(document1.Object, document2.Object, document3.Object)). #pragma warning disable 618 ScanConsistency(ScanConsistency.AtPlus); #pragma warning restore 618 var actual = queryRequest.GetFormValues()["scan_vectors"]; var expected = "{\"bucket1_name\":{\"102\":[9999,\"22\"]},\"bucket2_name\":{\"133\":[333,\"23\"]}}"; Assert.AreEqual(expected, JsonConvert.SerializeObject(actual)); }
public void GetFormValues_WhenScanConsistenyIsAtPlus_ScanVectorsIsAddedToFormValues() { var document1 = new Mock<IDocument<dynamic>>(); document1.Setup(x => x.Token).Returns(new MutationToken("bucket1_name", 102, 22, 8282)); var document2 = new Mock<IDocument<dynamic>>(); document2.Setup(x => x.Token).Returns(new MutationToken("bucket1_name", 123, 11, 8332)); var document3 = new Mock<IDocument<dynamic>>(); document3.Setup(x => x.Token).Returns(new MutationToken("bucket2_name", 133, 23, 333)); var queryRequest = new QueryRequest("SELECT * FROM `bucket1_name`;"). ConsistentWith(MutationState.From(document1.Object, document2.Object, document3.Object)). #pragma warning disable 618 ScanConsistency(ScanConsistency.AtPlus); #pragma warning restore 618 var actual = queryRequest.GetFormValues()["scan_vectors"]; var expected = "{\"bucket1_name\":{\"102\":[8282,\"22\"],\"123\":[8332,\"11\"]},\"bucket2_name\":{\"133\":[333,\"23\"]}}"; Assert.AreEqual(expected, JsonConvert.SerializeObject(actual)); }
public void When_MaxServerParallism_Is_Set_Request_Has_It() { var queryRequest = new QueryRequest("SELECT * FROM default;"); queryRequest.MaxServerParallelism(4); var query = queryRequest.GetFormValues(); Assert.AreEqual(4.ToString(), query["max_parallelism"]); }
public void When_ScanWait_Is_Set_Request_Has_The_Value() { var queryRequest = new QueryRequest("SELECT * FROM default;"); queryRequest.ScanWait(TimeSpan.FromSeconds(10)); var query = queryRequest.GetFormValues(); Assert.AreEqual("10000ms", query["scan_wait"]); }
public void When_Timeout_Is_Not_Set_QueryString_Values_Use_Timeout_Default() { var query = new QueryRequest() .BaseUri(new Uri(string.Format("http://{0}:8093/query", _server))) .Statement("SELECT * from Who"); var queryStringValues = query.GetFormValues(); Assert.AreEqual(queryStringValues["timeout"], "75000ms"); }
public void Test_Named_Parameters_Two_Arguments() { var query = new QueryRequest(). BaseUri(new Uri(string.Format("http://{0}:8093/query", _server))). Statement("SELECT * FROM default WHERE type=$canine OR type=$feline"). AddNamedParameter("canine", "dog"). AddNamedParameter("feline", "cat"); var values = query.GetFormValues(); Assert.AreEqual("SELECT * FROM default WHERE type=$canine OR type=$feline", values["statement"]); Assert.AreEqual("dog", values["$canine"]); Assert.AreEqual("cat", values["$feline"]); }
public void When_Timeout_Is_Not_Set_Default_To_75000ms() { var query = new QueryRequest() .BaseUri(new Uri(string.Format("http://{0}:8093/query", _server))) .Statement("SELECT * FROM `beer-sample`"); var values = query.GetFormValues(); Assert.AreEqual("SELECT * FROM `beer-sample`", values["statement"]); Assert.AreEqual("75000ms", values["timeout"]); }
public void When_Timeout_Set_Query_Contains_Milliseconds_With_Unit() { var query = new QueryRequest() .BaseUri(new Uri(string.Format("http://{0}:8093/query", _server))) .Statement("SELECT * FROM `beer-sample`") .Timeout(new TimeSpan(0, 0, 0, 0, 5)); var values = query.GetFormValues(); Assert.AreEqual("SELECT * FROM `beer-sample`", values["statement"]); Assert.AreEqual("5ms", values["timeout"]); }
public void When_isAdmin_Is_False_Credentials_Contains_local() { var query = new QueryRequest(). BaseUri(new Uri(string.Format("http://{0}:8093/query", _server))). Statement("SELECT * FROM authenticated"). AddCredentials("authenticated", "secret", false); var values = query.GetFormValues(); Assert.AreEqual("SELECT * FROM authenticated", values["statement"]); Assert.AreEqual("{ user = local:authenticated, pass = secret }", ((List<Object>)values["creds"]).ElementAt(0).ToString()); }
public void MutationState_WhenScanConsistencyIsNotAtPlus_ThrowsArgumentException() { var document1 = new Mock<IDocument<dynamic>>(); document1.Setup(x => x.Token).Returns(new MutationToken("bucket1_name", 102, 22, 8282)); var document2 = new Mock<IDocument<dynamic>>(); document2.Setup(x => x.Token).Returns(new MutationToken("bucket1_name", 123, 11, 8332)); var document3 = new Mock<IDocument<dynamic>>(); document3.Setup(x => x.Token).Returns(new MutationToken("bucket2_name", 133, 23, 333)); var queryRequest = new QueryRequest("SELECT * FROM `bucket1_name`;"). ConsistentWith(MutationState.From(document1.Object, document2.Object, document3.Object)). ScanConsistency(ScanConsistency.NotBounded); Assert.Throws<ArgumentException>(() => queryRequest.GetFormValues()); }