コード例 #1
0
        public void ExecuteTest()
        {
            var container = ServiceFactory.CreateContainer(null, f => f.Mock <SimpleCommand>((context, command) => command.ResultValue = command.Value * 2));
            var s         = new SimpleCommandModelService(container);

            Assert.Equal(10, s.ExecuteTest(5));
        }
コード例 #2
0
        public void GetContainerTest()
        {
            var container = new IocContainer();
            var s         = new SimpleCommandModelService(container);

            Assert.NotNull(s.Container);
            Assert.Equal(container, s.Container);
        }
コード例 #3
0
        public void GetUserTest()
        {
            var container = new IocContainer();
            var username  = "******";
            var s         = new SimpleCommandModelService(container);

            Assert.Null(s.User);
            container.AddService <IUserFactory>(new UserFactory(ioc => username));
            Assert.Equal(username, s.User);
        }
コード例 #4
0
        public void BeginTransactionTest()
        {
            var container = new IocContainer();
            var s         = new SimpleCommandModelService(container);

            using (var tran = s.BeginTransactionTest())
            {
                Assert.IsType <DefaultTransaction>(tran);
            }
        }
コード例 #5
0
        public void IncrementTest()
        {
            var container = new IocContainer();
            var s         = new SimpleCommandModelService(container);

            List <Task> tasks = new List <Task>();

            for (int i = 0; i < 10; i++)
            {
                tasks.Add(Task.Factory.StartNew(() =>
                {
                    s.IncrementTest1();
                }));
            }
            Task.WaitAll(tasks.ToArray());
            Assert.Equal(11, s.IncrementTest1());
            Assert.Equal(1, s.IncrementTest2());
        }
コード例 #6
0
        public void LockTest()
        {
            var container = new IocContainer();
            var s         = new SimpleCommandModelService(container);

            System.Collections.Concurrent.ConcurrentBag <int> bag = new System.Collections.Concurrent.ConcurrentBag <int>();
            List <Task> tasks = new List <Task>();

            for (int i = 0; i < 10; i++)
            {
                tasks.Add(Task.Factory.StartNew(() =>
                {
                    bag.Add(s.LockTest());
                }));
            }
            Task.WaitAll(tasks.ToArray());
            Assert.Equal(55, bag.Sum());
        }
コード例 #7
0
 public void BeginTransactionTest()
 {
     var container = new IocContainer();
     var s         = new SimpleCommandModelService(container);
     //Assert.ThrowsAny<NotSupportedException>(s.BeginTransactionTest);
 }