Exemple #1
0
        public void ConnectionEngineConstructorDoesNotThrowWhenValidArgumentsAreProvided()
        {
            var logger = new MockLogger();
            var db     = new SQLServerClientDatabase(TestConnectionString, new MockLogger(), SharedMockedCoreSettings);

            var engine = new ConnectionEngine(db, logger, 0, SharedMockedCoreSettings);

            Assert.IsNotNull(engine);
        }
Exemple #2
0
        public void ConnectionEngineCanStartAndStop()
        {
            var logger = new MockLogger();
            var db     = new SQLServerClientDatabase(TestConnectionString, new MockLogger(), SharedMockedCoreSettings);

            var engine = new ConnectionEngine(db, logger, 0, SharedMockedCoreSettings);

            engine.BeginStart();
            engine.BeginStop();
        }
        public void CanRunEngineThroughAllPhases()
        {
            var message = new MailMessage("*****@*****.**", "*****@*****.**");

            _connectionSetup.Setup(setup => setup.Setup()).Returns(new ServiceReadyResponse("service ready"));
            _mailTransfer.Setup(trans => trans.Execute(message)).Returns(new OkResponse("ok")).Verifiable();
            _connectionTermination.Setup(term => term.Terminate()).Returns(new ClosingTransmissionChannelResponse("closing")).Verifiable();
            var engine   = new ConnectionEngine(_connectionSetup.Object, _mailTransfer.Object, _connectionTermination.Object);
            var response = engine.Execute(message);

            Assert.That(response.ResponseCode, Is.EqualTo(SmtpResponseCode.ClosingTransmissionChannel));
            Assert.That(response.ResponseText, Is.EqualTo("closing"));
            _connectionSetup.Verify(setup => setup.Setup(), Times.Once);
            _mailTransfer.Verify(trans => trans.Execute(message), Times.Once);
            _connectionTermination.Verify(term => term.Terminate(), Times.Once);
        }
Exemple #4
0
        public void ConnectionEngineTriggersStoppedEventWhenEngineHasStopped()
        {
            var logger = new MockLogger();
            var db     = new SQLServerClientDatabase(TestConnectionString, new MockLogger(), SharedMockedCoreSettings);

            var engine = new ConnectionEngine(db, logger, 0, SharedMockedCoreSettings);

            var signalStoppedEvent = new AutoResetEvent(false);

            engine.Stopped += (s, e) => { signalStoppedEvent.Set(); };
            engine.BeginStart();
            engine.BeginStop();

            var engineStoppedSignaled = signalStoppedEvent.WaitOne(TimeSpan.FromSeconds(5));

            Assert.IsTrue(engineStoppedSignaled);
        }
Exemple #5
0
        /// <summary>
        /// Starts the connection engine.
        /// </summary>
        /// <returns>True if successful, otherwise false.</returns>
        private bool StartConnectionEngine()
        {
            try
            {
                ConnectionEngineInstance          = new ConnectionEngine(ClientDatabase, CoreLog, 0, CoreSettings);
                ConnectionEngineInstance.Stopped += Connection_Stopped;
                ConnectionEngineInstance.BeginStart();

                CoreLog.WriteSystemEvent(
                    string.Format("Connection Engine has started."),
                    EventLogEntryType.Information, ArchivialLibrary.Constants.EventIDs.StartedConnectionEngine, true);

                return(true);
            }
            catch (Exception ex)
            {
                var message = "Failed to start the connection engine.";
                var context = CoreLog.GenerateFullContextStackTrace();
                CoreLog.WriteSystemEvent(message, ex, context, ArchivialLibrary.Constants.EventIDs.FailedConnectionEngine, true);
                return(false);
            }
        }
Exemple #6
0
        public void ConnectionEngineConstructorThrowsExceptionWhenNoCoreSettingsProvided()
        {
            var db = new SQLServerClientDatabase(TestConnectionString, new MockLogger(), SharedMockedCoreSettings);

            var engine = new ConnectionEngine(db, new MockLogger(), 0, null);
        }
Exemple #7
0
 public void ConnectionEngineConstructorThrowsExceptionWhenNoDatabaseIsProvided()
 {
     var engine = new ConnectionEngine(null, new MockLogger(), 0, SharedMockedCoreSettings);
 }