public void BsonDocumentInCorrectFormatReturnsCompleteIndexedLocationStructure()
        {
            var bson            = new BsonDocument();
            var id              = new BsonElement("_id", "0");
            var indexedLocation = new BsonElement("IndexedLocation", "IndexedLocation");

            bson.Add(id);
            bson.Add(indexedLocation);
            var result = new IndexedLocationStructure().ConvertFromBsonDocument(bson);

            Assert.AreEqual("0", result.Id);
            Assert.AreEqual("IndexedLocation", result.IndexedLocation);
        }
Exemple #2
0
        public IndexedLocationResponse Read(IMongoDatabase db)
        {
            //Returning BsonDocument since protobuf doesn't support ObjectId type
            var collection = db.GetCollection <BsonDocument>("IndexedLocation");
            // In error checking if an error occured this will report back in the response message

            var bsonResult = collection.Find(x => true).FirstOrDefault();

            if (bsonResult == null)
            {
                return(new IndexedLocationResponse()
                {
                    Error = "No indexed location in database"
                });
            }
            var result = new IndexedLocationStructure().ConvertFromBsonDocument(bsonResult);

            var response = new IndexedLocationResponse()
            {
                IndexedLocation = result.IndexedLocation
            };

            return(response);
        }
 public static IndexedLocationStructure ConvertFromBsonDocument(this IndexedLocationStructure value, BsonDocument doc)
 {
     value.Id = doc.GetValue("_id").ToString();
     value.IndexedLocation = doc.GetValue("IndexedLocation").ToString();
     return(value);
 }