示例#1
0
        public void FromNameThenSwitchOnName(string expectedServiceLifeTimeWrapperName)
        {
            var actualServiceLifeTimeWrapper         = ServiceLifetimeWrapper.FromName(expectedServiceLifeTimeWrapperName);
            var actualNameServiceLifeTimeWrapperName = string.Empty;

            switch (actualServiceLifeTimeWrapper.Name)
            {
            case ServiceLifetimeWrapper.NotSet:
                actualNameServiceLifeTimeWrapperName = expectedServiceLifeTimeWrapperName;
                break;

            case ServiceLifetimeWrapper.Scoped:
                actualNameServiceLifeTimeWrapperName = expectedServiceLifeTimeWrapperName;
                break;

            case ServiceLifetimeWrapper.Transient:
                actualNameServiceLifeTimeWrapperName = expectedServiceLifeTimeWrapperName;
                break;

            case ServiceLifetimeWrapper.Singleton:
                actualNameServiceLifeTimeWrapperName = expectedServiceLifeTimeWrapperName;
                break;

            default:
                Assert.Fail("Switch case not found.");
                break;
            }
            Assert.AreEqual(expectedServiceLifeTimeWrapperName, actualNameServiceLifeTimeWrapperName);
        }
示例#2
0
 public void FromNameWhenPropertyDoesNotExistThenThrowException(string expectedServiceLifeTimeWrapperName)
 {
     Assert.ThrowsException <ArgumentException>(() =>
                                                ServiceLifetimeWrapper.FromName(expectedServiceLifeTimeWrapperName),
                                                $"Could not get a ServiceLifetimeWrapper from name: {expectedServiceLifeTimeWrapperName}"
                                                );
 }
示例#3
0
        public void FromNameWhenPropertyDoesExistAndRunInParallelThenReturnSingleInstance(
            string expectedServiceLifeTimeWrapperName)
        {
            var queue = new ConcurrentQueue <ServiceLifetimeWrapper>();

            Parallel.For(0, 1000000,
                         (i) => queue.Enqueue(ServiceLifetimeWrapper.FromName(expectedServiceLifeTimeWrapperName)));

            var firstItem = queue.First();

            foreach (var actualServiceLifeTimeWrapper in queue)
            {
                Assert.AreEqual(expectedServiceLifeTimeWrapperName, actualServiceLifeTimeWrapper.Name);
                Assert.AreSame(firstItem, actualServiceLifeTimeWrapper);
            }
        }
示例#4
0
        public void FromNameWhenPropertyDoesExistThenReturnSingleInstance(string expectedServiceLifeTimeWrapperName)
        {
            var list = new List <ServiceLifetimeWrapper>();

            for (var i = 0; i < 100; i++)
            {
                list.Add(ServiceLifetimeWrapper.FromName(expectedServiceLifeTimeWrapperName));
            }

            var firstItem = list.First();

            Assert.AreEqual(expectedServiceLifeTimeWrapperName, firstItem.Name);

            foreach (var actualServiceLifeTimeWrapper in list)
            {
                Assert.AreEqual(firstItem.Name, actualServiceLifeTimeWrapper.Name);
                Assert.AreSame(firstItem, actualServiceLifeTimeWrapper);
            }
        }
示例#5
0
        public void FromNameWhenPropertyDoesExistThenReturnInstance(string expectedServiceLifeTimeWrapperName)
        {
            var actualServiceLifeTimeWrapper = ServiceLifetimeWrapper.FromName(expectedServiceLifeTimeWrapperName);

            Assert.AreEqual(expectedServiceLifeTimeWrapperName, actualServiceLifeTimeWrapper.Name);
        }