static void Main(string[] args)
        {
            var t  = Employee.GetInstance();
            var t1 = Employee.GetInstance();
            var t2 = Employee.GetInstance();
            var t3 = Employee.GetInstance();

            var s = GenericSingleton <SimpleClass> .Instance();

            var s1 = GenericSingleton <SimpleClass> .Instance();

            var s2 = GenericSingleton <SimpleClass> .Instance();

            var s3 = GenericSingleton <SimpleClass> .Instance();

            var f  = Fruit.GetInstance();
            var f1 = Fruit.GetInstance();
            var f2 = Fruit.GetInstance();
            var f3 = Fruit.GetInstance();

            var b  = Bike.GetInstance();
            var b1 = Bike.GetInstance();
            var b2 = Bike.GetInstance();
            var b3 = Bike.GetInstance();

            Console.ReadKey();
        }
Beispiel #2
0
        private void 设置城市ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //第四步:将要实现的方法绑定到委托事件
            SetCityName setcityname = GenericSingleton <SetCityName> .CreateInstrance();

            setcityname.MyEvent += new SetCityName.MyDelegate(b_MyEvent);//监听b窗体事件
            setcityname.ShowDialog();
        }
Beispiel #3
0
        public void CheckGenericCounter()
        {
            GenericSingleton <GenOneSingleton> firstOne = GenOneSingleton.getInstance;

            firstOne = GenOneSingleton.getInstance;

            Assert.AreEqual(1, firstOne.getCounter());
        }
Beispiel #4
0
        public Login()
        {
            InitializeComponent();
            //    headerName("Tela", "Login");
            GlobalConfiguration _global_configuration = GenericSingleton <GlobalConfiguration> .GetInstance();

            _global_configuration.getBDPath(Application.StartupPath);
            EfetuarLogin("daniel", "daniel");
        }
        public Configuracao_bd()
        {
            InitializeComponent();
            GlobalConfiguration _global_configuration = GenericSingleton <GlobalConfiguration> .GetInstance();

            _global_configuration.getBDPath(Application.StartupPath);
            edtIP.Text    = _global_configuration.Bd_server_path;
            edtLogin.Text = _global_configuration.Bd_server_login;
            edtSenha.Text = _global_configuration.Bd_server_password;
        }
Beispiel #6
0
        public Form1()
        {
            InitializeComponent();
            GlobalConfiguration _global_configuration = GenericSingleton <GlobalConfiguration> .GetInstance();

            _global_configuration.getBDPath(Application.StartupPath);
            try { lblUsuarioLogado.Text = "Login: "******"Suporte Técnico"; }
            panelAdd(new cenarios.cadastro.criarProva(), pnlContent);
        }
Beispiel #7
0
        public void TwoInheritedInstancesAreTheSame()
        {
            GenericSingleton <GenOneSingleton> son         = null;
            GenericSingleton <GenOneSingleton> sonOfTheSon = null;

            Parallel.Invoke(
                () => son         = GenOneSingleton.getInstance,
                () => sonOfTheSon = GenThreeSingleton.getInstance);

            Assert.AreSame(son, sonOfTheSon);
        }
Beispiel #8
0
        public void TestGetCustomerById()
        {
            int entityId = custTestId;

            IUnityContainer container = GenericSingleton <ComponentContainer> .GetInstance().Container;

            IDomainFactory factory = container.Resolve <CustomerFactory>();

            IDomainObject c = factory.GetBusinessEntityById(entityId);

            Assert.AreEqual(entityId, c.BusinessEntityID);
        }
Beispiel #9
0
        public void TwoInstancesAreTheSame_ParallelMethod()
        {
            GenericSingleton <GenOneSingleton> firstOne  = null;
            GenericSingleton <GenOneSingleton> secondOne = null;

            Parallel.Invoke(
                () => firstOne  = GenOneSingleton.getInstance,
                () => secondOne = GenOneSingleton.getInstance
                );

            Assert.AreSame(firstOne, secondOne);
        }
Beispiel #10
0
        public void TwoInstancesAreTheSame_NormalMethod()
        {
            GenericSingleton <GenOneSingleton> firstOne  = GenOneSingleton.getInstance;
            GenericSingleton <GenOneSingleton> secondOne = GenOneSingleton.getInstance;

            GenericSingleton <GenTwoSingleton> firstTwo  = GenTwoSingleton.getInstance;
            GenericSingleton <GenTwoSingleton> secondTwo = GenTwoSingleton.getInstance;

            Assert.AreSame(firstOne, secondOne);
            Assert.AreSame(firstTwo, secondTwo);
            Assert.AreNotSame(firstOne, firstTwo);
        }
Beispiel #11
0
        public void TestGetPhoneByMasterId()
        {
            int masterId = 504438;

            IUnityContainer container = GenericSingleton <ComponentContainer> .GetInstance().Container;

            IDomainFactory factory = container.Resolve <PhoneFactory>();

            Phone ph = (Phone)factory.GetBusinessEntityByMasterEntityId(masterId);

            Assert.AreEqual(masterId, ph.customerId);
        }
Beispiel #12
0
        public void TestGetPhoneById()
        {
            int entityId = phoneTestId;

            IUnityContainer container = GenericSingleton <ComponentContainer> .GetInstance().Container;

            IDomainFactory factory = container.Resolve <PhoneFactory>();

            Phone ph = (Phone)factory.GetBusinessEntityById(entityId);

            Assert.AreEqual(entityId, ph.BusinessEntityID);
        }
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            GlobalConfiguration _global_configuration = GenericSingleton <GlobalConfiguration> .GetInstance();

            _global_configuration.Bd_server_path     = edtIP.Text;
            _global_configuration.Bd_server_login    = edtLogin.Text;
            _global_configuration.Bd_server_password = edtSenha.Text;
            _global_configuration.setBDPath(Application.StartupPath);
            //entidades contexto = new Contexto().GetContexto();
            entidades contexto = GenericSingleton <entidades> .GetInstance();

            contexto = new entidades(new Connection().getConnection());
            this.Close();
        }
Beispiel #14
0
        public void TestAddPhone()
        {
            IUnityContainer container = GenericSingleton <ComponentContainer> .GetInstance().Container;

            IDomainFactory factory = container.Resolve <PhoneFactory>();

            Phone ph = (Phone)factory.CreateBusinessEntity();

            ph.phoneNumber = "6125551234";

            ph.AddToDb();

            Phone phNew = (Phone)factory.GetBusinessEntityById(ph.phoneId);

            Assert.AreEqual(phNew.BusinessEntityID, ph.BusinessEntityID);
        }
        private void CallSingletonWithGeneric()
        {
            GenericSingleton <SimpleType> instance = new GenericSingleton <SimpleType>();
            SimpleType simple = instance.GetInstance();

            GenericSingleton <SimpleType> instance2 = new GenericSingleton <SimpleType>();
            SimpleType simple2 = instance2.GetInstance();

            if (simple == simple2)
            {
                Console.WriteLine("Singleton works, both variables contain the same instance.");
            }
            else
            {
                Console.WriteLine("Singleton failed, variables contain different instances.");
            }
        }
Beispiel #16
0
        public void TestDeleteBeforeInDB()
        {
            IUnityContainer container = GenericSingleton <ComponentContainer> .GetInstance().Container;

            IDomainFactory factory = container.Resolve <PhoneFactory>();

            Phone ph = (Phone)factory.CreateBusinessEntity();

            ph.phoneNumber = "6515551234";

            try
            {
                ph.Delete();
            }
            catch (InvalidOperationException ex)
            {
                Assert.IsTrue(true, ex.Message);
            }
        }
Beispiel #17
0
        public void TestUpdateBeforeInDB()
        {
            IUnityContainer container = GenericSingleton <ComponentContainer> .GetInstance().Container;

            IDomainFactory factory = container.Resolve <PhoneFactory>();

            Phone ph = (Phone)factory.CreateBusinessEntity();

            ph.phoneNumber = "6515551234";

            Exception genEx;

            try
            {
                ph.Update();
            }
            catch (InvalidOperationException ex)
            {
                genEx = ex;
            }
        }
Beispiel #18
0
 static void Main(string[] args)
 {
     GenericSingleton <SimpleType> instance = new GenericSingleton <SimpleType>();
     SimpleType simple = instance.GetInstance();
 }