Ejemplo n.º 1
0
        public async Task FindRecordAsync_ExistingRecord_FindsExistingRecord()
        {
            var dbUser = new BsonDocument
            {
                { "givenname", "adminuser" },
                { "firstName", "Super" },
                { "lastName", "User" },
                { "email", "*****@*****.**" }
            };

            var db     = _client.GetDatabase("euro_monitor_db_dev");
            var filter = Builders <BsonDocument> .Filter.Eq("givenname", "adminuser");

            var collection = db.GetCollection <BsonDocument>("users_test");

            _dbProvider.Collection = "users_test";
            // no user in db
            var apiUser = await collection.Find(filter).FirstOrDefaultAsync();

            var providerUser = await _dbProvider.FindRecordAsync <User>("givenname", "adminuser");

            Assert.Null(apiUser);
            Assert.Null(providerUser);

            await collection.InsertOneAsync(dbUser);

            apiUser = await collection.Find(filter).FirstOrDefaultAsync();

            providerUser = await _dbProvider.FindRecordAsync <User>("givenname", "adminuser");

            Assert.NotNull(apiUser);
            Assert.NotNull(providerUser);

            collection.DeleteOne(filter);
        }