public void SingletonTotalPopulationTest() { var rf = new SingletonRecordFinder(); var names = new[] { "Seoul", "New York" }; int tp = rf.GetTotalPopulation(names); Assert.That(tp, Is.EqualTo(17800000 + 17500000)); }
public void SingletonTotalPopulationTest() { var rf = new SingletonRecordFinder(); var names = new[] { "Seoul", "Mexico City" }; int tp = rf.GetTotalPopulation(names); Assert.AreEqual(17500000 + 17400000, tp); }
public void ConfigurablePopulationTest() { SingletonRecordFinder singletonRecordFinder = new SingletonRecordFinder(); int population = singletonRecordFinder.GetTotalPopulation(new List <string>() { "Seoul", "Tokyo" }); Assert.AreEqual(33200000 + 17500000, population); }
public void SingletonTotalPopulationTest() { // Singleton database is used as live (production) database test // data of live database may changed by user // so we need to create another database for test environment var rf = new SingletonRecordFinder(); var names = new[] { "Seoul", "Mexico City" }; var tp = rf.GetTotalPopulation(names); Assert.That(tp, Is.EqualTo(17500000 + 17400000)); }
public void SingletonTotalPopulationTest() { // Here we're testing on a 'live db' // One of the consequences is that we need to look at the DB for the values we want to test var rf = new SingletonRecordFinder(); // If somebody removes from the db one of the entries, the test will break var names = new[] { "Seoul", "Mexico City", "Osaka" }; int tp = rf.GetTotalPopulation(names); Assert.That(tp, Is.EqualTo(17500000 + 17400000 + 16425000)); // to be independent from a live db is very expensive // what you want to do is to fake the object instead the real db // In this particular scenario, to fake it isn't possible because RecordFinder is using a hardcoded reference }
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" })}"); }