public OperationTestBase()
 {
     _databaseNamespace      = CoreTestConfiguration.DatabaseNamespace;
     _collectionNamespace    = CoreTestConfiguration.GetCollectionNamespaceForTestClass(GetType());
     _messageEncoderSettings = CoreTestConfiguration.MessageEncoderSettings;
     _session = CoreTestConfiguration.StartSession();
 }
        protected IReadWriteBinding CreateReadWriteBinding(bool useImplicitSession = false)
        {
            var options = new CoreSessionOptions(isImplicit: useImplicitSession);
            var session = CoreTestConfiguration.StartSession(_cluster, options);

            return(new WritableServerBinding(_cluster, session));
        }
        private void DropView(CollectionNamespace viewNamespace)
        {
            var operation = new DropCollectionOperation(viewNamespace, CoreTestConfiguration.MessageEncoderSettings);

            using (var session = CoreTestConfiguration.StartSession(_cluster))
                using (var binding = new WritableServerBinding(_cluster, session.Fork()))
                    using (var bindingHandle = new ReadWriteBindingHandle(binding))
                    {
                        operation.Execute(bindingHandle, CancellationToken.None);
                    }
        }
        protected void VerifySessionIdWasSentWhenSupported <TResult>(
            Func <WritableServerBinding, CancellationToken, Task <TResult> > executeAsync,
            Func <WritableServerBinding, CancellationToken, TResult> execute,
            string commandName,
            bool async)
        {
            var eventCapturer = new EventCapturer().Capture <CommandStartedEvent>(e => e.CommandName == commandName);

            using (var cluster = CoreTestConfiguration.CreateCluster(b => b.Subscribe(eventCapturer)))
            {
                using (var session = CoreTestConfiguration.StartSession(cluster))
                    using (var binding = new WritableServerBinding(cluster, session))
                    {
                        var cancellationToken = new CancellationTokenSource().Token;
                        if (async)
                        {
                            executeAsync(binding, cancellationToken).GetAwaiter().GetResult();
                        }
                        else
                        {
                            execute(binding, cancellationToken);
                        }

                        var commandStartedEvent = (CommandStartedEvent)eventCapturer.Next();
                        var command             = commandStartedEvent.Command;
                        if (session.Id == null)
                        {
                            command.Contains("lsid").Should().BeFalse();
                        }
                        else
                        {
                            command["lsid"].Should().Be(session.Id);
                        }
                        session.ReferenceCount().Should().Be(1);
                    }
            }
        }
        private ICoreSessionHandle CreateSession(ICluster cluster, bool useImplicitSession)
        {
            var options = new CoreSessionOptions(isImplicit: useImplicitSession);

            return(CoreTestConfiguration.StartSession(cluster, options));
        }