Exemplo n.º 1
0
        public void Unregister_WrongOrder_ThrowsException()
        {
            var mock1    = new Mock <IUnitOfWork>();
            var mock2    = new Mock <IUnitOfWork>();
            var registry = new UnitOfWorkRegistry();

            registry.Register(mock1.Object);
            registry.Register(mock2.Object);

            registry.Unregister(mock1.Object);
        }
Exemplo n.º 2
0
        public void Unregister_CorrectWorkflow()
        {
            var mock1    = new Mock <IUnitOfWork>();
            var mock2    = new Mock <IUnitOfWork>();
            var registry = new UnitOfWorkRegistry();

            registry.Register(mock1.Object);
            registry.Register(mock2.Object);

            registry.Unregister(mock2.Object);
            registry.Unregister(mock1.Object);
            Assert.IsNull(registry.GetCurrent());
        }
Exemplo n.º 3
0
        public void Register_asDefaultReturnsLastUnitOfWOrk()
        {
            var mock1    = new Mock <IUnitOfWork>();
            var mock2    = new Mock <IUnitOfWork>();
            var registry = new UnitOfWorkRegistry();

            registry.Register(mock1.Object);
            Assert.AreEqual(mock1.Object, registry.GetCurrent());
            Assert.IsNull(registry.GetCurrent(1));

            registry.Register(mock2.Object);
            Assert.AreEqual(mock2.Object, registry.GetCurrent());
            Assert.AreEqual(mock1.Object, registry.GetCurrent(1));
            Assert.IsNull(registry.GetCurrent(2));
        }
Exemplo n.º 4
0
        private Task WorkForAsyncOperations_asyncOperation(UnitOfWorkRegistry registry)
        {
            var mock2 = new Mock <IUnitOfWork>();

            registry.Register(mock2.Object);
            Assert.AreEqual(mock2.Object, registry.GetCurrent());

            registry.Unregister(mock2.Object);
            return(Task.FromResult(true));
        }
Exemplo n.º 5
0
        public async Task WorkForAsyncOperations()
        {
            var mock1    = new Mock <IUnitOfWork>();
            var registry = new UnitOfWorkRegistry();

            registry.Register(mock1.Object);

            Assert.AreEqual(mock1.Object, registry.GetCurrent());
            await WorkForAsyncOperations_asyncOperation(registry);

            Assert.AreEqual(mock1.Object, registry.GetCurrent());
            registry.Unregister(mock1.Object);

            Assert.IsNull(registry.GetCurrent());
        }