Пример #1
0
        public void SingletonTotalPopulationTest()
        {
            var cf              = new ConfigurableRecordFinder(new DummyDataBase());
            var names           = new[] { "alpha", "gamma" };
            int totalPopulation = cf.GetTotalPopulation(names);

            Assert.AreEqual(totalPopulation, 4);
        }
Пример #2
0
        public void ConfigurablePopulationTest()
        {
            var rf    = new ConfigurableRecordFinder(new DummyDatabase());
            var names = new[] { "alpha", "gamma" };
            int tp    = rf.GetTotalPopulation(names);

            Assert.That(tp, Is.EqualTo(4));
        }
Пример #3
0
        public void DependantTotalPopulationTest()
        {
            var db = new DummyDatabase();
            var rf = new ConfigurableRecordFinder(db);

            Assert.That(
                rf.GetTotalPopulation(new[] { "alpha", "gamma" }),
                Is.EqualTo(4));
        }
Пример #4
0
            public void ConfigurableTotalPopulationTest()
            {
                //database for test environment
                var rf    = new ConfigurableRecordFinder(new DummyDatabase());
                var names = new[] { "alpha", "gamma" };
                var tp    = rf.GetTotalPopulation(names);

                Assert.That(tp, Is.EqualTo(1 + 3));
            }
Пример #5
0
        public void ConfigurablePopulationTest()
        {
            // now in the ConfigurableRecordFinder we provide the db we want to use, for the test, will be the dummy one
            var rf = new ConfigurableRecordFinder(new DummyDatabase());
            // In this test we don't need to find records from the production db, we faked ones already
            var names = new[] { "alpha", "gamma" };
            int tp    = rf.GetTotalPopulation(names);

            Assert.That(tp, Is.EqualTo(4));
        }
Пример #6
0
        static void Main(string[] args)
        {
            var db  = SingletonDatabase.Instance;
            var db2 = SingletonDatabase.Instance;

            Console.WriteLine(db.GetPopulation("Kitchener"));
            Console.WriteLine($"db.Equals(db2): {db.Equals(db2)}");
            Console.WriteLine($"SingletonDatabase.Count: {SingletonDatabase.Count}");
            var rf = new SingletonRecordFinder();

            Console.WriteLine($"Total population of Kitchener and Waterloo: {rf.GetTotalPopulation(new [] { "Kitchener", "Waterloo" })}");
            var crf = new ConfigurableRecordFinder(new DummyDatabase());

            Console.WriteLine($"Total population of Kitchener and Waterloo with ConfigurableRecordFinder and DummyDatabase injected: {crf.GetTotalPopulation(new[] { "Kitchener", "Waterloo" })}");
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Singleton through dependency injection");
            var collection = new ServiceCollection();

            collection.AddSingleton <IDatabase, OrdinaryDatabse>();
            var serviceProvider = collection.BuildServiceProvider();
            var service         = serviceProvider.GetService <IDatabase>();
            var tokyoPop        = service.GetPopulation("Tokyo");

            Console.WriteLine($"Tokyo population is {tokyoPop}");


            SingletonRecordFinder recordFinder = new SingletonRecordFinder();
            var result = recordFinder.GetToalPopulation(new[] { "Tokyo", "New York" });

            Console.WriteLine($"Total Population {result}");

            var configurableRecordFinder = new ConfigurableRecordFinder(new DummyDatabase());
            var total = configurableRecordFinder.GetToalPopulation(new[] { "New York", "Tokyo" });

            Console.WriteLine(total);


            Console.WriteLine("A variation of singleton, which is MonoState");
            var ceo1 = new MonoState()
            {
                Name     = "Payam",
                Position = "CEO",
                Age      = 100
            };

            var ceo2 = new MonoState()
            {
                Name     = "Jack",
                Position = "Developer",
                Age      = 90
            };

            Console.WriteLine(ceo1);
            Console.WriteLine(ceo2);
        }