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)); }
public void GetContainerTest() { var container = new IocContainer(); var s = new SimpleCommandModelService(container); Assert.NotNull(s.Container); Assert.Equal(container, s.Container); }
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); }
public void BeginTransactionTest() { var container = new IocContainer(); var s = new SimpleCommandModelService(container); using (var tran = s.BeginTransactionTest()) { Assert.IsType <DefaultTransaction>(tran); } }
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()); }
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()); }
public void BeginTransactionTest() { var container = new IocContainer(); var s = new SimpleCommandModelService(container); //Assert.ThrowsAny<NotSupportedException>(s.BeginTransactionTest); }