Ejemplo n.º 1
0
        public void Should_support_string()
        {
            var id = BsonIdUrlEncoder.Decode("123");

            id.Type.Should().Be(BsonType.String);
            BsonIdUrlEncoder.Encode(id).Should().Be("123");
            BsonIdUrlEncoder.Decode("123e").Type.Should().Be(BsonType.String);
        }
Ejemplo n.º 2
0
        public void Should_support_long()
        {
            var id = BsonIdUrlEncoder.Decode("123L");

            id.Type.Should().Be(BsonType.Int64);
            id.AsInt64.Should().Be(123L);
            BsonIdUrlEncoder.Encode(id).Should().Be("123L");
            BsonIdUrlEncoder.Decode("123l").Should().Be(id);
        }
Ejemplo n.º 3
0
        public IActionResult SingleDelete(string collection, string id)
        {
            var bsonId = BsonIdUrlEncoder.Decode(id);

            if (!repository.Delete <BsonDocument>(bsonId, collection))
            {
                return(NotFound());
            }
            return(Ok());
        }
Ejemplo n.º 4
0
        public void Should_support_objectId()
        {
            var oid = ObjectId.NewObjectId();
            var id  = BsonIdUrlEncoder.Decode(oid + "o");

            id.Type.Should().Be(BsonType.ObjectId);
            id.AsObjectId.Should().Be(oid);
            BsonIdUrlEncoder.Encode(id).Should().Be(oid + "o");
            BsonIdUrlEncoder.Decode(oid + "O").Should().Be(id);
        }
Ejemplo n.º 5
0
        public void Should_support_guid()
        {
            var guid = new Guid("7E360B14-B0DF-47FF-A491-518A3E11C0A2");
            var id   = BsonIdUrlEncoder.Decode(guid + "g");

            id.Type.Should().Be(BsonType.Guid);
            id.AsGuid.Should().Be(guid);
            BsonIdUrlEncoder.Encode(id).Should().Be(guid.ToString("N") + "g");
            BsonIdUrlEncoder.Decode(guid.ToString("N") + "G").Should().Be(id);
        }
Ejemplo n.º 6
0
        public IActionResult SinglePut(string collection, [FromBody] JObject body, string id = null)
        {
            var doc = JsonSerializer.Deserialize(body.ToString()).AsDocument;

            if (!string.IsNullOrEmpty(id))
            {
                doc["_id"] = BsonIdUrlEncoder.Decode(id);
            }
            repository.Upsert(collection, doc);
            return(CreatedAtAction("SingleGet", new { collection, id = BsonIdUrlEncoder.Encode(doc["_id"]) }, null));
        }
Ejemplo n.º 7
0
        public IActionResult SingleGet(string collection, string id)
        {
            var bsonId = BsonIdUrlEncoder.Decode(id);
            var doc    = repository.Get <BsonDocument>(bsonId, collection);

            if (doc == null)
            {
                return(NotFound());
            }
            return(Content(JsonSerializer.Serialize(doc), "application/json", Encoding.UTF8));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> SinglePut(string collection, string id = null)
        {
            var doc = await DocumentFromRequest();

            if (!string.IsNullOrEmpty(id))
            {
                doc["_id"] = BsonIdUrlEncoder.Decode(id);
            }
            storageService.Upsert(collection, doc);
            return(CreatedAtAction("SingleGet", new { collection, id = BsonIdUrlEncoder.Encode(doc["_id"]) }, null));
        }