Пример #1
0
 // private methods
 private IEnumerable <WriteModel <BsonDocument> > ParseRequests(BsonArray requests)
 {
     foreach (var request in requests.Cast <BsonDocument>())
     {
         yield return(ParseRequest(request));
     }
 }
Пример #2
0
 private void ExecuteOperations(IMongoClient client, BsonArray operations)
 {
     foreach (var operation in operations.Cast <BsonDocument>())
     {
         ExecuteOperation(client, operation);
     }
 }
        private void AssertEvents(BsonArray eventItems, UnifiedEntityMap entityMap)
        {
            var unifiedEventMatcher = new UnifiedEventMatcher(new UnifiedValueMatcher(entityMap));

            foreach (var eventItem in eventItems.Cast <BsonDocument>())
            {
                var clientId      = eventItem["client"].AsString;
                var eventCapturer = entityMap.EventCapturers[clientId];
                var eventType     = eventItem.GetValue("eventType", defaultValue: "command").AsString;
                var actualEvents  = UnifiedEventMatcher.FilterEventsByType(eventCapturer.Events, eventType);

                unifiedEventMatcher.AssertEventsMatch(actualEvents, eventItem["events"].AsBsonArray);
            }
        }
Пример #4
0
        private List <JsonDrivenTest> ParseCallbackOperations(BsonArray operations)
        {
            var tests = new List <JsonDrivenTest>();

            foreach (var operation in operations.Cast <BsonDocument>())
            {
                var methodName = operation["name"].AsString;
                var @object    = operation["object"].AsString;
                var test       = _jsonDrivenTestFactory.CreateTest(@object, methodName);
                test.Arrange(operation);
                tests.Add(test);
            }
            return(tests);
        }
Пример #5
0
        protected override void VerifyCollection(IMongoCollection <BsonDocument> collection, BsonArray expectedData)
        {
            var data = collection.FindSync("{}").ToList();

            if (ClusterDescription.Servers[0].Version < new SemanticVersion(2, 6, 0) && _options.IsUpsert)
            {
                foreach (var doc in data)
                {
                    doc.Remove("_id");
                }

                foreach (var doc in expectedData.Cast <BsonDocument>())
                {
                    doc.Remove("_id");
                }
            }

            data.Should().BeEquivalentTo(expectedData);
        }
Пример #6
0
        static Expression PushEachExpression(Expression that, Expression field, BsonDocument document)
        {
            int       position = -1;
            BsonArray each = null;
            BsonValue sort = null, slice = null;

            foreach (var e in document.Elements)
            {
                //TODO
                switch (e.Name)
                {
                case "$each":
                    if (e.Value.BsonType != BsonType.Array)
                    {
                        throw new ArgumentException("Push all/each value must be array.");
                    }
                    each = e.Value.AsBsonArray;
                    break;

                case "$sort":
                    sort = e.Value;
                    break;

                case "$slice":
                    if (!e.Value.IsNumeric)
                    {
                        throw new ArgumentException("$slice must be a numeric value.");
                    }
                    slice = e.Value;
                    break;

                case "$position":
                    if (!e.Value.IsNumeric)
                    {
                        throw new ArgumentException("$position must be a numeric value.");
                    }
                    position = e.Value.ToInt32();
                    if (position < 0)
                    {
                        throw new ArgumentException("$position must not be negative.");
                    }
                    break;

                default:
                    throw new ArgumentException(string.Format(null, "Unrecognized clause in $push: ({0}).", e.Name));
                }
            }

            if (sort != null)
            {
                switch (sort.BsonType)
                {
                case BsonType.Int32:
                    switch (sort.AsInt32)
                    {
                    case 1:
                        each = new BsonArray(each.OrderBy(x => x)); break;                                         //TODO comparer?

                    case -1:
                        each = new BsonArray(each.OrderByDescending(x => x)); break;                                         //TODO comparer?

                    default:
                        throw new ArgumentException("Numeric $sort value must be either 1 or -1.");
                    }
                    break;

                case BsonType.Document:
                    //TODO not needed in Mongo v2.6
                    foreach (var d1 in each)
                    {
                        if (d1.BsonType != BsonType.Document)
                        {
                            throw new ArgumentException("$sort requires $each to be an array of objects.");
                        }
                    }

                    each = new BsonArray(QueryCompiler.Query(each.Cast <BsonDocument>(), null, null, new SortByDocument(sort.AsBsonDocument), 0, 0));
                    break;

                default:
                    throw new ArgumentException("$sort value must be 1, -1, or a document.");
                }
            }

            if (slice != null)
            {
                each = each.Slice(0, slice.ToInt32());
            }

            return(Expression.Call(that, GetMethod("PushAll"), Data, field,
                                   Expression.Constant(each, typeof(BsonValue)), Expression.Constant(position, typeof(int))));
        }
 protected virtual List <BsonDocument> ParseExpectedContents(BsonArray data)
 {
     return(data.Cast <BsonDocument>().ToList());
 }