当前位置: 首页>>代码示例>>C#>>正文


C# Document.Int方法代码示例

本文整理汇总了C#中Document.Int方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Int方法的具体用法?C# Document.Int怎么用?C# Document.Int使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Document的用法示例。


在下文中一共展示了Document.Int方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Should_create_and_get_document

        public void Should_create_and_get_document()
        {
            Database.CreateTestCollection(Database.TestDocumentCollectionName);
            var db = Database.GetTestDatabase();

            var dateUtcNow = DateTime.UtcNow;
            var unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            TimeSpan span = (dateUtcNow.ToUniversalTime() - unixEpoch);

            // create document object
            var document = new Document()
                .String("foo", "foo string value")
                .Int("bar", 12345)
                .DateTime("dateTime", dateUtcNow);

            // save it to database collection
            db.Document.Create(Database.TestDocumentCollectionName, document);

            // get the very same document from database
            var returnedDocument = db.Document.Get(document.String("_id"));

            // check if created and returned document data are equal

            Assert.AreEqual(false, document.IsNull("_id"));
            Assert.AreEqual(false, document.IsNull("_key"));
            Assert.AreEqual(false, document.IsNull("_rev"));
            Assert.AreEqual(false, document.IsNull("foo"));
            Assert.AreEqual(false, document.IsNull("bar"));
            Assert.AreEqual(false, document.IsNull("dateTime"));
            Assert.AreEqual(false, returnedDocument.IsNull("_id"));
            Assert.AreEqual(false, returnedDocument.IsNull("_key"));
            Assert.AreEqual(false, returnedDocument.IsNull("_rev"));
            Assert.AreEqual(false, returnedDocument.IsNull("foo"));
            Assert.AreEqual(false, returnedDocument.IsNull("bar"));
            Assert.AreEqual(false, returnedDocument.IsNull("dateTime"));

            Assert.AreEqual(document.String("_id"), returnedDocument.String("_id"));
            Assert.AreEqual(document.String("_key"), returnedDocument.String("_key"));
            Assert.AreEqual(document.String("_rev"), returnedDocument.String("_rev"));
            Assert.AreEqual(document.Has("foo"), returnedDocument.Has("foo"));
            Assert.AreEqual(document.String("foo"), returnedDocument.String("foo"));
            Assert.AreEqual(document.Has("bar"), returnedDocument.Has("bar"));
            Assert.AreEqual(document.Int("bar"), returnedDocument.Int("bar"));
            Assert.AreEqual(typeof(long), returnedDocument.Type("dateTime"));
            Assert.AreEqual(typeof(DateTime), returnedDocument.DateTime("dateTime").GetType());
            Assert.AreEqual((long)span.TotalSeconds, document.Long("dateTime"));
            Assert.AreEqual(dateUtcNow.ToString("yyyy-MM-dd HH:mm:ss"), document.DateTime("dateTime").ToString("yyyy-MM-dd HH:mm:ss"));
        }
开发者ID:jocull,项目名称:ArangoDB-NET,代码行数:48,代码来源:ArangoDocumentTests.cs

示例2: Should_create_and_update_and_get_document

        public void Should_create_and_update_and_get_document()
        {
            Database.CreateTestCollection(Database.TestDocumentCollectionName);
            var db = Database.GetTestDatabase();

            // create document object
            var document = new Document()
                .String("foo", "foo string value")
                .Int("bar", 12345);

            // save it to database collection
            db.Document.Create(Database.TestDocumentCollectionName, document);

            // update data in that document
            document.String("baz.foo", "bar string value");

            // update document in database
            var isUpdated = db.Document.Update(document);

            Assert.AreEqual(true, isUpdated);

            // get the very same document from database
            var returnedDocument = db.Document.Get(document.String("_id"));

            // check if the data of updated and returned document are equal
            Assert.AreEqual(false, document.IsNull("_id"));
            Assert.AreEqual(false, document.IsNull("_key"));
            Assert.AreEqual(false, document.IsNull("_rev"));
            Assert.AreEqual(false, document.IsNull("foo"));
            Assert.AreEqual(false, document.IsNull("bar"));
            Assert.AreEqual(false, document.IsNull("baz.foo"));
            Assert.AreEqual(false, returnedDocument.IsNull("_id"));
            Assert.AreEqual(false, returnedDocument.IsNull("_key"));
            Assert.AreEqual(false, returnedDocument.IsNull("_rev"));
            Assert.AreEqual(false, returnedDocument.IsNull("foo"));
            Assert.AreEqual(false, returnedDocument.IsNull("bar"));
            Assert.AreEqual(false, returnedDocument.IsNull("baz.foo"));

            Assert.AreEqual(document.String("_id"), returnedDocument.String("_id"));
            Assert.AreEqual(document.String("_key"), returnedDocument.String("_key"));
            Assert.AreEqual(document.String("_rev"), returnedDocument.String("_rev"));
            Assert.AreEqual(document.Has("foo"), returnedDocument.Has("foo"));
            Assert.AreEqual(document.String("foo"), returnedDocument.String("foo"));
            Assert.AreEqual(document.Has("bar"), returnedDocument.Has("bar"));
            Assert.AreEqual(document.Int("bar"), returnedDocument.Int("bar"));
            Assert.AreEqual(document.Has("baz.foo"), returnedDocument.Has("baz.foo"));
            Assert.AreEqual(document.String("baz.foo"), returnedDocument.String("baz.foo"));
        }
开发者ID:jocull,项目名称:ArangoDB-NET,代码行数:48,代码来源:ArangoDocumentTests.cs

示例3: Post

        internal void Post(ArangoCollection collection)
        {
            var request = new Request(RequestType.Collection, HttpMethod.Post);
            request.RelativeUri = _apiUri;

            var document = new Document();

            // set collection name
            document.String("name", collection.Name);

            // (optional, default: 2) set type
            if (collection.Type != 0)
            {
                document.Enum("type", collection.Type);
            }

            // (optional, default: false) set waitForSync
            if (collection.WaitForSync)
            {
                document.Bool("waitForSync", collection.WaitForSync);
            }

            // (optional, default: arangodb config) set journalSize
            if (collection.JournalSize > 0)
            {
                document.Int("journalSize", collection.JournalSize);
            }

            // (optional, default: false) set isSystem
            if (collection.IsSystem)
            {
                document.Bool("isSystem", collection.IsSystem);
            }

            // (optional, default: false) set isVolatile
            if (collection.IsVolatile)
            {
                document.Bool("isVolatile", collection.IsVolatile);
            }

            if (collection.NumberOfShards != null)
            {
                document.Int("numberOfShards", (int) collection.NumberOfShards);
            }

            if (collection.ShardKeys != null)
            {
                document.List("shardKeys", collection.ShardKeys);
            }

            // (optional) set keyOptions
            if (collection.KeyOptions != null)
            {
                if (collection.KeyOptions.GeneratorType != 0)
                {
                    document.String("keyOptions.type", collection.KeyOptions.GeneratorType.ToString().ToLower());

                    if (collection.KeyOptions.GeneratorType == ArangoKeyGeneratorType.Autoincrement)
                    {
                        if (collection.KeyOptions.Increment > 0)
                        {
                            document.Int("keyOptions.increment", collection.KeyOptions.Increment);
                        }

                        if (collection.KeyOptions.Offset > 0)
                        {
                            document.Int("keyOptions.offset", collection.KeyOptions.Offset);
                        }
                    }
                }

                if (collection.KeyOptions.AllowUserKeys)
                {
                    document.Bool("keyOptions.allowUserKeys", collection.KeyOptions.AllowUserKeys);
                }
            }

            request.Body = Document.Serialize(document);

            var response = _connection.Process(request);

            switch (response.StatusCode)
            {
                case HttpStatusCode.OK:
                    collection.Id = response.Document.String("id");
                    collection.Name = response.Document.String("name");
                    collection.Status = response.Document.Enum<ArangoCollectionStatus>("status");
                    collection.Type = response.Document.Enum<ArangoCollectionType>("type");
                    collection.WaitForSync = response.Document.Bool("waitForSync");
                    collection.IsVolatile = response.Document.Bool("isVolatile");
                    collection.IsSystem = response.Document.Bool("isSystem");
                    break;
                default:
                    if (response.IsException)
                    {
                        throw new ArangoException(
                            response.StatusCode,
                            response.Document.String("driverErrorMessage"),
                            response.Document.String("driverExceptionMessage"),
                            response.Document.Object<Exception>("driverInnerException")
//.........这里部分代码省略.........
开发者ID:jsteemann,项目名称:ArangoDB-NET,代码行数:101,代码来源:CollectionOperation.cs

示例4: Should_create_and_update_and_get_edge

        public void Should_create_and_update_and_get_edge()
        {
            Database.CreateTestCollection(Database.TestDocumentCollectionName);
            Database.CreateTestCollection(Database.TestEdgeCollectionName, ArangoCollectionType.Edge);
            var db = Database.GetTestDatabase();

             // create test documents
            var doc1 = new Document()
                .String("foo", "foo string value 1")
                .Int("bar", 12345);

            var doc2 = new Document()
                .String("foo", "foo string value 2")
                .Int("bar", 54321);

            db.Document.Create(Database.TestDocumentCollectionName, doc1);
            db.Document.Create(Database.TestDocumentCollectionName, doc2);

            // create test edge
            var edge = new Document()
                .String("edgeFoo", "foo string value")
                .Int("edgeBar", 12345);

            edge.String("_from", doc1.String("_id"));
            edge.String("_to", doc2.String("_id"));

            db.Edge.Create(Database.TestEdgeCollectionName, edge);

            // update data in that document and update it in database
            edge.String("baz.foo", "bar string value");

            var isUpdated = db.Edge.Update(edge);

            Assert.AreEqual(true, isUpdated);

            // get the very same document from database
            var returnedEdge = db.Edge.Get(edge.String("_id"));

            // check if the data of updated and returned document are equal
            Assert.AreEqual(false, edge.IsNull("_id"));
            Assert.AreEqual(false, edge.IsNull("_key"));
            Assert.AreEqual(false, edge.IsNull("_rev"));
            Assert.AreEqual(false, edge.IsNull("_from"));
            Assert.AreEqual(false, edge.IsNull("_to"));
            Assert.AreEqual(false, edge.IsNull("edgeFoo"));
            Assert.AreEqual(false, edge.IsNull("edgeBar"));
            Assert.AreEqual(false, edge.IsNull("baz.foo"));
            Assert.AreEqual(false, returnedEdge.IsNull("_id"));
            Assert.AreEqual(false, returnedEdge.IsNull("_key"));
            Assert.AreEqual(false, returnedEdge.IsNull("_rev"));
            Assert.AreEqual(false, returnedEdge.IsNull("_from"));
            Assert.AreEqual(false, returnedEdge.IsNull("_to"));
            Assert.AreEqual(false, returnedEdge.IsNull("edgeFoo"));
            Assert.AreEqual(false, returnedEdge.IsNull("edgeBar"));
            Assert.AreEqual(false, returnedEdge.IsNull("baz.foo"));

            Assert.AreEqual(edge.String("_id"), returnedEdge.String("_id"));
            Assert.AreEqual(edge.String("_key"), returnedEdge.String("_key"));
            Assert.AreEqual(edge.String("_rev"), returnedEdge.String("_rev"));
            Assert.AreEqual(edge.Has("edgeFoo"), returnedEdge.Has("edgeFoo"));
            Assert.AreEqual(edge.String("edgeFoo"), returnedEdge.String("edgeFoo"));
            Assert.AreEqual(edge.Has("edgeBar"), returnedEdge.Has("edgeBar"));
            Assert.AreEqual(edge.Int("edgeBar"), returnedEdge.Int("edgeBar"));
            Assert.AreEqual(edge.Has("baz.foo"), returnedEdge.Has("baz.foo"));
            Assert.AreEqual(edge.String("baz.foo"), returnedEdge.String("baz.foo"));
        }
开发者ID:jsteemann,项目名称:ArangoDB-NET,代码行数:66,代码来源:ArangoEdgeTests.cs

示例5: Should_create_and_get_out_direction_edges

        public void Should_create_and_get_out_direction_edges()
        {
            Database.CreateTestCollection(Database.TestDocumentCollectionName);
            Database.CreateTestCollection(Database.TestEdgeCollectionName, ArangoCollectionType.Edge);
            var db = Database.GetTestDatabase();

            // create test documents
            var doc1 = new Document()
                .String("foo", "foo string value 1")
                .Int("bar", 12345);

            var doc2 = new Document()
                .String("foo", "foo string value 2")
                .Int("bar", 54321);

            db.Document.Create(Database.TestDocumentCollectionName, doc1);
            db.Document.Create(Database.TestDocumentCollectionName, doc2);

            // create test edge
            var edge1 = new Document()
                .String("edgeFoo", "foo string value 1")
                .Int("edgeBar", 12345);

            edge1.String("_from", doc1.String("_id"));
            edge1.String("_to", doc2.String("_id"));

            db.Edge.Create(Database.TestEdgeCollectionName, edge1);

            // create another test edge
            var edge2 = new Document()
                .String("edgeFoo", "foo string value 2")
                .Int("edgeBar", 54321);

            edge2.String("_from", doc2.String("_id"));
            edge2.String("_to", doc1.String("_id"));

            db.Edge.Create(Database.TestEdgeCollectionName, edge2);

            // get only outgoing edges (should be one)
            var outEdges = db.Edge.Get(Database.TestEdgeCollectionName, doc1.String("_id"), ArangoEdgeDirection.Out);

            Assert.AreEqual(1, outEdges.Count);

            var returnedEdge1 = outEdges.Where(x => x.String("_id") == edge1.String("_id")).First();

            Assert.AreEqual(false, edge1.IsNull("_id"));
            Assert.AreEqual(false, edge1.IsNull("_key"));
            Assert.AreEqual(false, edge1.IsNull("_rev"));
            Assert.AreEqual(false, edge1.IsNull("_from"));
            Assert.AreEqual(false, edge1.IsNull("_to"));
            Assert.AreEqual(false, edge1.IsNull("edgeFoo"));
            Assert.AreEqual(false, edge1.IsNull("edgeBar"));
            Assert.AreEqual(false, returnedEdge1.IsNull("_id"));
            Assert.AreEqual(false, returnedEdge1.IsNull("_key"));
            Assert.AreEqual(false, returnedEdge1.IsNull("_rev"));
            Assert.AreEqual(false, returnedEdge1.IsNull("_from"));
            Assert.AreEqual(false, returnedEdge1.IsNull("_to"));
            Assert.AreEqual(false, returnedEdge1.IsNull("edgeFoo"));
            Assert.AreEqual(false, returnedEdge1.IsNull("edgeBar"));

            Assert.AreEqual(edge1.String("_id"), returnedEdge1.String("_id"));
            Assert.AreEqual(edge1.String("_key"), returnedEdge1.String("_key"));
            Assert.AreEqual(edge1.String("_rev"), returnedEdge1.String("_rev"));
            Assert.AreEqual(edge1.String("_from"), returnedEdge1.String("_from"));
            Assert.AreEqual(edge1.String("_to"), returnedEdge1.String("_to"));
            Assert.AreEqual(edge1.Has("edgeFoo"), returnedEdge1.Has("edgeFoo"));
            Assert.AreEqual(edge1.String("edgeFoo"), returnedEdge1.String("edgeFoo"));
            Assert.AreEqual(edge1.Has("edgeBar"), returnedEdge1.Has("edgeBar"));
            Assert.AreEqual(edge1.Int("edgeBar"), returnedEdge1.Int("edgeBar"));
        }
开发者ID:jsteemann,项目名称:ArangoDB-NET,代码行数:70,代码来源:ArangoEdgeTests.cs

示例6: Post

        internal List<object> Post(string query, bool returnCount, out int count, int batchSize, Dictionary<string, object> bindVars)
        {
            var request = new Request(RequestType.Cursor, HttpMethod.Post);
            request.RelativeUri = _apiUri;

            var bodyDocument = new Document();

            // set AQL string
            bodyDocument.String("query", query);

            // (optional) set number of found documents
            if (returnCount)
            {
                bodyDocument.Bool("count", returnCount);
            }

            // (optional) set how much documents should be returned
            if (batchSize > 0)
            {
                bodyDocument.Int("batchSize", batchSize);
            }

            // (optional) set list of bind parameters
            if ((bindVars != null) && (bindVars.Count > 0))
            {
                var bindVarsDocument = new Document();

                foreach (KeyValuePair<string, object> item in bindVars)
                {
                    bindVarsDocument.Object(item.Key, item.Value);
                }

                bodyDocument.Object("bindVars", bindVarsDocument);
            }

            request.Body = bodyDocument.Serialize();

            var response = _connection.Process(request);
            var items = new List<object>();
            count = 0;

            switch (response.StatusCode)
            {
                case HttpStatusCode.Created:
                    items.AddRange(response.Document.List<object>("result"));

                    // get count of returned document if present
                    if (returnCount)
                    {
                        count = response.Document.Int("count");
                    }

                    // get more results if present
                    if (response.Document.Bool("hasMore"))
                    {
                        long cursorId = response.Document.Long("id");

                        items.AddRange(Put(cursorId));
                    }
                    break;
                default:
                    items = null;

                    if (response.IsException)
                    {
                        throw new ArangoException(
                            response.StatusCode,
                            response.Document.String("driverErrorMessage"),
                            response.Document.String("driverExceptionMessage"),
                            response.Document.Object<Exception>("driverInnerException")
                        );
                    }
                    break;
            }

            return items;
        }
开发者ID:jocull,项目名称:ArangoDB-NET,代码行数:77,代码来源:CursorOperation.cs


注:本文中的Document.Int方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。