예제 #1
0
        /// <summary>
        /// Make some requests on the Developer collection
        /// </summary>
        public static void DeveloperCollectionTest()
        {
            IDeveloperRepository repository = new DeveloperRepository();
            var          developer          = Factory.CreateDeveloper();
            BsonDocument doc = repository.CreateDocument(developer);

            //Insert a document
            var savedDoc = Task.Factory.StartNew(async() => await repository.InsertDocumentAsync(doc))
                           .GetAwaiter().GetResult().Result;

            //Update a document
            DeveloperModel savedObj = BsonSerializer.Deserialize <DeveloperModel>(savedDoc);

            savedObj.CompanyName = "Bosch";

            savedObj = Task.Factory.StartNew(async() => await repository.UpdateAsync(savedObj))
                       .GetAwaiter().GetResult().Result;

            //Find all developers
            var developers = Task.Factory.StartNew(async() => await repository.FindAllAsync())
                             .GetAwaiter().GetResult().Result;

            //Find by id
            var obj = Task.Factory.StartNew(async() => await repository.FindByIdAsync(savedObj.ID))
                      .GetAwaiter().GetResult().Result;

            if (obj != null)
            {
                Console.WriteLine(obj.ToJson());
            }

            //Find by text

            var objects = Task.Factory.StartNew(async() => await repository.FindByTextSearchAsync("bosch"))
                          .GetAwaiter().GetResult().Result;

            foreach (var result in objects)
            {
                Console.WriteLine(result.ToJson());
            }

            //Call view
            var viewDocs = Task.Factory.StartNew(async() => await repository.GetDocumentFromDeveloperView())
                           .GetAwaiter().GetResult().Result;

            foreach (var viewDoc in viewDocs)
            {
                Console.WriteLine(viewDoc.ToJson());
            }

            //Delete by id
            //var ok = Task.Factory.StartNew(async () => await repository.DeleteByIdAsync(savedObj.ID))
            //  .GetAwaiter().GetResult().Result;

            //Delete all objects
            //ok = Task.Factory.StartNew(async () => await repository.DeleteAllAsync())
            //  .GetAwaiter().GetResult().Result;
        }