Exemplo n.º 1
0
 public void GenerateIndexUriTest()
 {
     DBFieldSet target = new DBFieldSet("a","b","c");
     Uri expected = new Uri("a_1_b_1_c_1", UriKind.Relative);
     Uri actual = target.GenerateIndexUri();
     actual.Should().Be(expected);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DBIndex"/> class.
 /// </summary>
 /// <param name="collection">The collection.</param>
 /// <param name="indexUri">The index URI.</param>
 /// <param name="indexKeyFieldSet">The index key field set.</param>
 /// <param name="unique">if set to <c>true</c> [unique].</param>
 public DBIndex(DBCollection collection, Uri indexUri, DBFieldSet indexKeyFieldSet, bool unique)
 {
     Collection = collection;
     Uri relative = indexUri.IsAbsoluteUri ? indexUri.MakeRelativeUri(collection.Uri) : indexUri;
     Uri = new Uri(new Uri(collection.Uri.ToString() + "/"), relative);
     KeyFieldSet = indexKeyFieldSet;
     Unique = unique;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DBCursorOptions"/> class.
        /// </summary>
        /// <param name="collection">The collection to query against.</param>
        /// <param name="selector">The selector query.</param>
        /// <param name="returnFields">The fields to be returned.</param>
        /// <param name="orderBy">The field or fields to order the results by.</param>
        /// <param name="numberToSkip">The number of results to skip.</param>
        /// <param name="numberToReturn">The number to return in a given batch.</param>
        /// <param name="limit">If specified, only this many results are returned.</param>
        /// <param name="explain">if set to <c>true</c> a query explanation will be included.</param>
        /// <param name="snapshot">if set to <c>true</c> then execute against a data snapshot.</param>
        /// <param name="flags">The option flags.</param>
        /// <param name="explicitIndexHint">The explicit index hint.</param>
        public DBCursorOptions(IDBCollection collection,
            DBQuery selector = null,
            DBFieldSet returnFields = null,
            DBFieldSet orderBy = null,
            int? numberToSkip = null,
            int? numberToReturn = null,
            int? limit = null,
            bool explain = false,
            bool snapshot = false,
            CursorFlags flags = CursorFlags.None,
            IDBIndex explicitIndexHint = null)
        {
            Condition.Requires(snapshot, "snapshot")
                .Evaluate(!(snapshot && explicitIndexHint != null), "Snapshot is not allowed when there is an explicit hint")
                .Evaluate(!(snapshot && orderBy != null), "Snapshot is not allowed when there field set to order by");
            Condition.Requires(numberToReturn, "numberToReturn")
                .Evaluate(!(numberToReturn.HasValue && limit.HasValue), "You may not specify both numberToReturn AND limit. They are ways to set a common property. Choose one to set.");

            Collection = collection;
            Selector = selector ?? DBQuery.SelectAll;
            ReturnFields = returnFields;
            Explain = explain;
            Flags = flags;
            Hint = explicitIndexHint;
            OrderBy = orderBy;
            Snapshot = snapshot;

            if (numberToSkip.HasValue)
                NumberToSkip = numberToSkip;
            if (numberToReturn.HasValue)
                NumberToReturn = numberToReturn.Value;
            if (limit.HasValue)
                Limit = limit;

            //If we have special query details
            if (OrderBy != null && OrderBy.Keys.Any() ||
                Hint != null ||
                Explain)
            {
                //Push everything into a container
                DBQuery query = Selector;
                Selector = new DBQuery();
                Selector["query"] = query;
                if (OrderBy != null && OrderBy.Keys.Any())
                    Selector["orderby"] = OrderBy;
                if (Hint != null)
                    Selector["$hint"] = Hint.Name;
                if (Explain)
                    Selector["$explain"] = true;
                if (Snapshot)
                    Selector["$snapshot"] = true;
            }
        }
Exemplo n.º 4
0
 public void op_ImplicitTest()
 {
     DBFieldSet fieldSet = new DBFieldSet("a", "b", "c");
     string[] expected = new string[] {"a", "b", "c"};
     string[] actual;
     actual = fieldSet;
     actual.Should().Contain(expected);
 }
Exemplo n.º 5
0
 public void DBFieldSetConstructorTest1()
 {
     IEnumerable<string> fieldNames = new string[] { "a", "b", "c" };
     DBFieldSet target = new DBFieldSet(fieldNames);
     target.Keys.Should().Contain(new string[] { "a", "b", "c" });
 }
Exemplo n.º 6
0
 public void DBFieldSetConstructorTest()
 {
     DBFieldSet target = new DBFieldSet("a", "b", "c");
     target.Keys.Should().Contain(new string[] { "a", "b", "c" });
 }
Exemplo n.º 7
0
 public void op_ImplicitTest3()
 {
     string s = "a,b,c";
     DBFieldSet expected = new DBFieldSet("a", "b", "c");
     DBFieldSet actual;
     actual = s;
     actual.Should().Contain(expected);
 }
Exemplo n.º 8
0
 public void op_ImplicitTest2()
 {
     DBFieldSet fieldSet = new DBFieldSet("a", "b", "c");
     string expected = "a";
     string actual;
     actual = fieldSet;
     actual.Should().Be(expected);
 }
Exemplo n.º 9
0
 public void op_ImplicitTest1()
 {
     string[] s = new string[] { "a", "b", "c" };
     DBFieldSet expected = new DBFieldSet("a", "b", "c");
     DBFieldSet actual;
     actual = s;
     actual.Should().Contain(expected);
 }