Exemplo n.º 1
0
 public TestUnregisteredWithDependencies(TestSingleton testSingleton)
 {
     if (testSingleton == null)
     {
         throw new ArgumentNullException(nameof(testSingleton));
     }
 }
Exemplo n.º 2
0
 public IEnumerator SetUp()
 {
     TestSingleton.SetIsAccessible(true);
     TestSingleton.SetPersistence(false);
     CreateMultipleSingletonObjects(Random.Range(5, 25), true);
     yield return(0);
 }
Exemplo n.º 3
0
 public TestService(TestTransient testTransient, TestSingleton testSingleton, IFactory <TestTransient> transientFactory, IFactory <TestSingleton> singletonFactory)
 {
     TestTransient    = testTransient;
     TestSingleton    = testSingleton;
     TransientFactory = transientFactory;
     SingletonFactory = singletonFactory;
 }
Exemplo n.º 4
0
        public void Instance()
        {
            TestSingleton first  = TestSingleton.Instance;
            TestSingleton second = TestSingleton.Instance;

            Assert.That(first, Is.EqualTo(second));
        }
Exemplo n.º 5
0
        public void Singleton_ReturnsSingletonInstance()
        {
            TestSingleton instance1 = Singleton <TestSingleton> .Instance;
            TestSingleton instance2 = TestSingleton.Instance;

            Assert.AreSame(instance1, instance2, "Expected object to be same singleton instance.");
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            //abstract factory design pattern
            TestAbstractFactory tbf = new TestAbstractFactory();

            tbf.Run();

            //factory method design pattern
            TestFactoryMethod tfm = new TestFactoryMethod();

            tfm.Run();

            //Singleton design pattern
            TestSingleton ts = new TestSingleton();

            ts.Run();

            TestOptimizedSingleton tos = new TestOptimizedSingleton();

            tos.Run();

            //Bridge design pattern
            TestBridge tb = new TestBridge();

            tb.Run();
        }
Exemplo n.º 7
0
        public IndexModel(ILogger <IndexModel> logger, TestScope _testScope, TestSingleton _testSingleton, TestTransient _testTransient, IServiceProvider provider)
        {
            _logger             = logger;
            this._testScope     = _testScope;
            this._testSingleton = _testSingleton;
            this._testTransient = _testTransient;

            //此处拿到的IServiceProvider是每个请求生成的IServiceProvider,所有的scope和transient生命周期的都由这个类生成
            this._serviceProvider = provider;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Create multiple singleton objects for testing.
        /// </summary>
        /// <param name="numObjects"></param>
        private void CreateMultipleSingletonObjects(int numObjects, bool randomData = false)
        {
            for (int i = 0; i < numObjects; i++)
            {
                CreateSingletonObject("SingletonObject" + i.ToString());
            }

            if (!randomData)
            {
                return;
            }
            TestSingleton.SetPersistence(Random.value > 0.5f); // Randomly assign persistence
        }
Exemplo n.º 9
0
 void Awake()
 {
     if (instance != null)
     {
         Destroy(gameObject);
     }
     else
     {
         instance   = this;
         instance.i = this.index;
         DontDestroyOnLoad(gameObject);
     }
 }
Exemplo n.º 10
0
    // Use this for initialization
    void Start()
    {
        pool = EntityPoolBuilder.FindByName("TestPool");

        ZEntity en = pool.CreateEntity(1);

        Debug.Log(" en data is " + en.GetComponent <TestComponent4> ().data4.ToString());

        //test singleton
        TestSingleton test = SingletonEntity <TestSingleton> .Instance;

        if (test != null)
        {
            Debug.Log(" SingletonEntity data is " + test.data2.ToString());
        }
    }
Exemplo n.º 11
0
        public IEnumerator NonPersistentSceneChange()
        {
            // Arrange
            var instance = TestSingleton.Instance;

            // Act
            TestSingleton.SetPersistence(false);

            var asyncLoad = SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().name);

            while (!asyncLoad.isDone)
            {
                yield return(null);
            }

            // Assert
            Assert.AreEqual(0, GameObject.FindObjectsOfType <TestSingleton>().Length);
        }
Exemplo n.º 12
0
        public void AddWithKeyTest()
        {
            ServiceCollection services = new ServiceCollection();
            TestSingleton     instance = new TestSingleton();

            services.AddSingletonWithKey(typeof(ITestSingleton), instance, "A");
            int count = services.Count(s => s.ServiceType == typeof(ITestSingleton));

            count.ShouldBe(0);
            services.AddSingletonWithKey(typeof(ITestSingleton0), typeof(TestSingleton0), "B");
            count = services.Count(s => s.ServiceType == typeof(TestSingleton0));
            count.ShouldBe(1);
            IServiceProvider serviceProvider = services.BuildServiceProvider();
            var service = serviceProvider.GetRequiredServiceWithKey <ITestSingleton0>("B");

            service.ShouldBeOfType <TestSingleton0>();
            serviceProvider.GetRequiredServiceWithKey <ITestSingleton>("A").ShouldBe(instance);
        }
Exemplo n.º 13
0
        public void BuildChain_Success_NoCondition()
        {
            var singleton = new TestSingleton();

            singleton.Guid = Guid.NewGuid().ToString();

            _builder.WithHandler <FirstHandler>()
            .WithHandler <SecondHandler>()
            .WithHandler <EmptyConstructorHandler>().BuildChain()
            .AddSingleton(singleton);

            IServiceProvider serviceProvider = _services.BuildServiceProvider();

            var scope        = serviceProvider.CreateScope();
            var firstHandler = scope.ServiceProvider.GetRequiredService <ITestChain>();

            Assert.Equal(typeof(SecondHandler), firstHandler.Handle());
            Assert.Equal(singleton.Guid, ((FirstHandler)firstHandler).GetSingleton().Guid);
        }
Exemplo n.º 14
0
    //use awake for singleton
    void Awake()
    {
        //check to see if null
        //if so, there is nothing there, this has never been run there so signs  of any other sngleton in existance.
        if (instance == null)
        {
            instance = this;
        }

        else if (instance != this)
        {
            //this is not the first component that has run
            Destroy(this.gameObject);
        }
        // we want to keep this since we are the component that is going to be going betwwen scenes
        DontDestroyOnLoad(this.gameObject);

        //load data saved and out in places needed.
    }
        static void Main(string[] args)
        {
            TestBridge cls1 = new TestBridge();

            cls1.Execute();

            TestFactory cls5 = new TestFactory();

            cls5.Execute();

            TestBuilder cls15 = new TestBuilder();

            cls15.Execute();

            TestPrototype cls9 = new TestPrototype();

            cls9.Execute();

            TestObserver cls7 = new TestObserver();

            cls7.Execute();

            TestAdaptor cls = new TestAdaptor();

            cls.Execute();

            TestDecorater cls4 = new TestDecorater();

            cls4.Execute();

            TestComposite cls3 = new TestComposite();

            cls3.Execute();

            TestProxy cls10 = new TestProxy();

            cls10.Execute();

            TestIterator cls6 = new TestIterator();

            cls6.Execute();

            TestState cls14 = new TestState();

            cls14.Execute();

            TestCommand cls2 = new TestCommand();

            cls2.Execute();

            // ************
            TestProducerConsumer cls8 = new TestProducerConsumer();

            cls8.Execute();

            TestReaderWriter cls11 = new TestReaderWriter();

            cls11.Execute();

            TestSimpleThread cls12 = new TestSimpleThread();

            cls12.Execute();

            TestSingleton cls13 = new TestSingleton();

            cls13.Execute();
        }
Exemplo n.º 16
0
 private void button18_Click(object sender, EventArgs e)
 {
     TestSingleton.Testar();
 }