public void Dispose()
 {
     using (var context = new TestProcessManagerDbContext(dbName))
     {
         context.Database.Delete();
     }
 }
 public void Setup()
 {
     using (var context = new TestProcessManagerDbContext(this.DbName)) {
         context.Database.Delete();
         context.Database.Create();
     }
 }
Example #3
0
 public SqlProcessManagerDataContextFixture()
 {
     using (var context = new TestProcessManagerDbContext(dbName)) {
         context.Database.Delete();
         context.Database.Create();
     }
 }
        public void Setup()
        {
            using (var context = new TestProcessManagerDbContext(this.DbName)) {
                context.Database.Delete();
                context.Database.Create();
            }

            this._bus1     = new Mock <ICommandBus>();
            this._command1 = new TestCommand();
            this._command2 = new TestCommand();
            this._command3 = new TestCommand();

            var id = Guid.NewGuid();

            this._exceptions = new List <Exception>();

            this._saveFinished            = new ManualResetEvent(false);
            this._sendContinueResetEvent1 = new AutoResetEvent(false);
            this._sendStartedResetEvent1  = new AutoResetEvent(false);

            this._bus1.Setup(x => x.Send(It.Is <Envelope <ICommand> >(c => c.Body.Id == this._command2.Id)))
            .Callback(() => {
                this._sendStartedResetEvent1.Set();
                this._sendContinueResetEvent1.WaitOne();
            });

            Task.Factory.StartNew(() => {
                using (var context = new SqlProcessManagerDataContext <OrmTestProcessManager>(
                           () => new TestProcessManagerDbContext(this.DbName), this._bus1.Object, new JsonTextSerializer())) {
                    var aggregate = new OrmTestProcessManager(id);
                    aggregate.AddEnvelope(new Envelope <ICommand>(this._command1), new Envelope <ICommand>(this._command2),
                                          new Envelope <ICommand>(this._command3));
                    context.Save(aggregate);
                }
            }).ContinueWith(t => this._exceptions.Add(t.Exception.InnerException), TaskContinuationOptions.OnlyOnFaulted)
            .ContinueWith(t => this._saveFinished.Set());

            Assert.IsTrue(this._sendStartedResetEvent1.WaitOne(3000));

            this._bus2 = new Mock <ICommandBus>();
            this._sendContinueResetEvent2 = new AutoResetEvent(false);
            this._sendStartedResetEvent2  = new AutoResetEvent(false);
            this._bus2.Setup(x => x.Send(It.Is <Envelope <ICommand> >(c => c.Body.Id == this._command2.Id)))
            .Callback(() => {
                this._sendStartedResetEvent2.Set();
                this._sendContinueResetEvent2.WaitOne();
            });

            this._findAndSaveFinished = new ManualResetEvent(false);

            Task.Factory.StartNew(() => {
                using (var context = new SqlProcessManagerDataContext <OrmTestProcessManager>(
                           () => new TestProcessManagerDbContext(this.DbName), this._bus2.Object, new JsonTextSerializer())) {
                    var entity = context.Find(id);
                    context.Save(entity);
                }
            }).ContinueWith(t => this._exceptions.Add(t.Exception.InnerException), TaskContinuationOptions.OnlyOnFaulted)
            .ContinueWith(t => this._findAndSaveFinished.Set());
        }
 public void TearDown()
 {
     using (var context = new TestProcessManagerDbContext(this.DbName)) {
         context.Database.Delete();
     }
 }