예제 #1
0
        public ClientOutboxPersisterV2TestsFixture()
        {
            Now             = DateTime.UtcNow;
            DateTimeService = new Mock <IDateTimeService>();
            Settings        = new Mock <ReadOnlySettings>();
            Connection      = new Mock <DbConnection>();
            Transaction     = new Mock <DbTransaction> {
                CallBase = true
            };
            Command    = new Mock <DbCommand>();
            Parameters = new Mock <DbParameterCollection>();
            ClientOutboxTransaction = new SqlClientOutboxTransaction(Connection.Object, Transaction.Object);
            EndpointName            = "SFA.DAS.NServiceBus";

            Events = new List <object>
            {
                new FooEvent(Now.AddDays(-1)),
                new BarEvent(Now)
            };

            TransportOperations     = Events.Select(e => new TransportOperation(Guid.NewGuid(), e)).ToList();
            TransportOperationsData = JsonConvert.SerializeObject(TransportOperations, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Auto
            });
            ClientOutboxMessage        = new ClientOutboxMessageV2(GuidComb.NewGuidComb(), EndpointName, TransportOperations);
            SynchronizedStorageSession = new Mock <SynchronizedStorageSession>();
            SqlSession              = SynchronizedStorageSession.As <ISqlStorageSession>();
            OutboxMessages          = new List <IClientOutboxMessageAwaitingDispatch>();
            CancellationTokenSource = new CancellationTokenSource();
            CancellationToken       = CancellationTokenSource.Token;

            DateTimeService.Setup(d => d.UtcNow).Returns(Now);
            Parameters.Setup(p => p.Add(It.IsAny <DbParameter>()));
            Command.SetupSet(c => c.CommandText = It.IsAny <string>());
            Command.SetupSet(c => c.Transaction = It.IsAny <DbTransaction>());

            Command.Protected().Setup <DbParameter>("CreateDbParameter").Returns(() =>
            {
                var parameter = new Mock <DbParameter> {
                    CallBase = true
                };

                parameter.SetupProperty(p => p.ParameterName);
                parameter.SetupProperty(p => p.Value);

                return(parameter.Object);
            });

            Command.Protected().Setup <DbParameterCollection>("DbParameterCollection").Returns(Parameters.Object);
            Connection.Protected().Setup <DbTransaction>("BeginDbTransaction", IsolationLevel.Unspecified).Returns(Transaction.Object);
            Connection.Protected().Setup <DbCommand>("CreateDbCommand").Returns(Command.Object);
            Settings.Setup(s => s.Get <Func <DbConnection> >("SqlPersistence.ConnectionBuilder")).Returns(() => Connection.Object);
            SqlSession.Setup(s => s.Connection).Returns(Connection.Object);
            SqlSession.Setup(s => s.Transaction).Returns(Transaction.Object);

            ClientOutboxStorage = new ClientOutboxPersisterV2(DateTimeService.Object, Settings.Object);
        }