public void CloseTo()
        {
            // Sometimes it's handy to have some leniancy on DateTimes in tests
            // Particularly if you've got something that hits the database!

            var firstDate  = new DateTime(2018, 03, 07, 19, 00, 00);
            var secondDate = new DateTime(2018, 03, 07, 19, 30, 25);

            secondDate.Should().BeCloseTo(firstDate, 30.Minutes());

            // Okay so 30 minutes might be an extreme example, but you could do ms too!

            var thirdDate = new DateTime(2018, 03, 07, 19, 00, 00).AddMilliseconds(4);

            firstDate.Should().BeCloseTo(firstDate, FILL_ME_IN.Milliseconds()); // Change FILL_ME_IN to make this pass
        }
Exemple #2
0
        public void HashKeysAndValues()
        {
            var hash = new Hashtable()
            {
                { "one", "uno" }, { "two", "dos" }
            };

            //Warning: Unfamiliar syntax ahead. Because the hashtable keys
            //only return an ICollection, there isn't a good way to ask it
            //if it matches, or contains values. So we are using a trick
            //from LINQ to cast it over. Note that the casting is not important
            //for this Koan - it's the value of the keys that is interesting

            var expectedKeys = new List <string>()
            {
                "one", "two"
            };

            expectedKeys.Sort();
            var actualKeys = hash.Keys.Cast <string>().ToList();

            actualKeys.Sort();

            CollectionAssert.AreEqual(expectedKeys, actualKeys);

            var expectedValues = new List <string>()
            {
                FILL_ME_IN.ToString(), FILL_ME_IN.ToString()
            };

            expectedValues.Sort();
            var actualValues = hash.Values.Cast <string>().ToList();

            actualValues.Sort();

            CollectionAssert.AreEqual(expectedValues, actualValues);
        }