Exemplo n.º 1
0
        public void Should_convert_from_InsertRequest_to_BsonDocument()
        {
            var document = BsonDocument.Parse("{a:1}");
            var request  = new InsertRequest(new BsonDocumentWrapper(document));

            var result = WriteModel <BsonDocument> .FromCore(request);

            result.Should().BeOfType <InsertOneModel <BsonDocument> >();
            var insertModel = (InsertOneModel <BsonDocument>)result;

            insertModel.Document.Should().BeSameAs(document);
        }
Exemplo n.º 2
0
        public void Should_convert_from_InsertRequest_to_Class()
        {
            var document = new TestClass {
                a = 1
            };
            var request = new InsertRequest(new BsonDocumentWrapper(document));

            var result = WriteModel <TestClass> .FromCore(request);

            result.Should().BeOfType <InsertOneModel <TestClass> >();
            var model = (InsertOneModel <TestClass>)result;

            model.Document.Should().BeSameAs(document);
        }
Exemplo n.º 3
0
        public void Should_convert_from_UpdateRequest_to_ReplaceOne_with_BsonDocument(bool isUpsert)
        {
            var filter      = new BsonDocument("a", 1);
            var replacement = BsonDocument.Parse("{a:2}");
            var request     = new UpdateRequest(UpdateType.Update,
                                                new BsonDocumentWrapper(filter),
                                                new BsonDocumentWrapper(replacement))
            {
                IsMulti  = false,
                IsUpsert = isUpsert
            };

            var result = WriteModel <BsonDocument> .FromCore(request);

            result.Should().BeOfType <ReplaceOneModel <BsonDocument> >();
            var model = (ReplaceOneModel <BsonDocument>)result;

            ((BsonDocumentFilterDefinition <BsonDocument>)model.Filter).Document.Should().Be(filter);
            model.Replacement.Should().BeSameAs(replacement);
            model.IsUpsert.Should().Be(isUpsert);
        }
Exemplo n.º 4
0
        public void Should_convert_from_UpdateRequest_to_UpdateMany(bool isUpsert)
        {
            var filter  = BsonDocument.Parse("{a:1}");
            var update  = BsonDocument.Parse("{$set: {a:2}}");
            var request = new UpdateRequest(UpdateType.Update,
                                            new BsonDocumentWrapper(filter),
                                            new BsonDocumentWrapper(update))
            {
                IsMulti  = true,
                IsUpsert = isUpsert
            };

            var result = WriteModel <BsonDocument> .FromCore(request);

            result.Should().BeOfType <UpdateManyModel <BsonDocument> >();
            var model = (UpdateManyModel <BsonDocument>)result;

            ((BsonDocumentFilterDefinition <BsonDocument>)model.Filter).Document.Should().BeSameAs(filter);
            ((BsonDocumentUpdateDefinition <BsonDocument>)model.Update).Document.Should().BeSameAs(update);
            model.IsUpsert.Should().Be(isUpsert);
        }
        public void Should_convert_from_UpdateRequest_to_ReplaceOne_with_BsonDocument(bool isUpsert)
        {
            var criteria    = Query.EQ("a", 1);
            var replacement = BsonDocument.Parse("{a:2}");
            var request     = new UpdateRequest(UpdateType.Update,
                                                new BsonDocumentWrapper(criteria),
                                                new BsonDocumentWrapper(replacement))
            {
                IsMulti  = false,
                IsUpsert = isUpsert
            };

            var result = WriteModel <BsonDocument> .FromCore(request);

            result.Should().BeOfType <ReplaceOneModel <BsonDocument> >();
            var model = (ReplaceOneModel <BsonDocument>)result;

            model.Criteria.Should().BeSameAs(criteria);
            model.Replacement.Should().BeSameAs(replacement);
            model.IsUpsert.Should().Be(isUpsert);
        }
        public void Should_convert_from_UpdateRequest_to_UpdateMany_with_wrappers(bool isUpsert)
        {
            var criteria = Query.EQ("a", 1);
            var update   = Update.Set("a", 2);
            var request  = new UpdateRequest(UpdateType.Update,
                                             new BsonDocumentWrapper(criteria),
                                             new BsonDocumentWrapper(update))
            {
                IsMulti  = true,
                IsUpsert = isUpsert
            };

            var result = WriteModel <BsonDocument> .FromCore(request);

            result.Should().BeOfType <UpdateManyModel <BsonDocument> >();
            var model = (UpdateManyModel <BsonDocument>)result;

            model.Criteria.Should().BeSameAs(criteria);
            model.Update.Should().BeSameAs(update);
            model.IsUpsert.Should().Be(isUpsert);
        }
        public void Should_convert_from_UpdateRequest_to_UpdateMany(bool isUpsert)
        {
            var criteria = BsonDocument.Parse("{a:1}");
            var update   = BsonDocument.Parse("{$set: {a:2}}");
            var request  = new UpdateRequest(UpdateType.Update,
                                             new BsonDocumentWrapper(criteria),
                                             new BsonDocumentWrapper(update))
            {
                IsMulti  = true,
                IsUpsert = isUpsert
            };

            var result = WriteModel <BsonDocument> .FromCore(request);

            result.Should().BeOfType <UpdateManyModel <BsonDocument> >();
            var model = (UpdateManyModel <BsonDocument>)result;

            model.Criteria.Should().BeSameAs(criteria);
            model.Update.Should().BeSameAs(update);
            model.IsUpsert.Should().Be(isUpsert);
        }
        public void Should_convert_from_UpdateRequest_to_ReplaceOne_with_Class(bool isUpsert)
        {
            var filter      = Query.EQ("a", 1);
            var replacement = new TestClass {
                a = 2
            };
            var request = new UpdateRequest(UpdateType.Replacement,
                                            new BsonDocumentWrapper(filter),
                                            new BsonDocumentWrapper(replacement))
            {
                IsMulti  = false,
                IsUpsert = isUpsert
            };

            var result = WriteModel <TestClass> .FromCore(request);

            result.Should().BeOfType <ReplaceOneModel <TestClass> >();
            var model = (ReplaceOneModel <TestClass>)result;

            model.Filter.Should().BeSameAs(filter);
            model.Replacement.Should().BeSameAs(replacement);
            model.IsUpsert.Should().Be(isUpsert);
        }