public void TestClose()
        {
            var dal   = new DummyDal();
            var logic = new LogicImplementation(dal);

            logic.Close();
            Assert.IsTrue((dal.CloseCalled),
                          $"LogicLayerTests - \"Close\" does not call corresponding method from data access implementation!");
        }
        public void TestGetRunInfoForDate()
        {
            var dal   = new DummyDal();
            var logic = new LogicImplementation(dal);

            var info = logic.GetRunInfoForDate(new DateTime(42).Date);

            Assert.IsTrue((dal.GetRunInfoForDateCalledCount > 0),
                          $"LogicLayerTests - \"GetRunInfoForDate\" does not call corresponding method from data access implementation!");
            Assert.IsTrue((info.IsEqual(dal.StoredInfo)),
                          $"LogicLayerTests - \"GetRunInfoForDate\" does not return RunInfo as passed by data access implementation !");
        }
        public void TestLogicOmitsTimeFromDate()
        {
            var dal   = new DummyDal();
            var logic = new LogicImplementation(dal);
            var date  = new DateTime(1234, 5, 6, 12, 12, 12);
            var info  = new RunInfo(321, new TimeSpan(0, 15, 30));

            logic.SetRunInfoForDate(date, info);
            Assert.IsTrue((date.Date == dal.RequestedDate),
                          $"LogicLayerTests - \"SetRunInfoForDate\" does not omit time info from Date when passing on to data access implementation !");
            info = logic.GetRunInfoForDate(date);
            Assert.IsTrue((date.Date == dal.RequestedDate),
                          $"LogicLayerTests - \"SetRunInfoForDate\" does not omit time info from Date when passing on to data access implementation !");
        }
        public void TestSetRunInfoForDate()
        {
            var dal   = new DummyDal();
            var logic = new LogicImplementation(dal);
            var date  = new DateTime(1234, 5, 6);
            var info  = new RunInfo(321, new TimeSpan(0, 15, 30));

            logic.SetRunInfoForDate(date, info);

            Assert.IsTrue((dal.StoreRunInfoCalled),
                          $"LogicLayerTests - \"SetRunInfoForDate\" does not call corresponding method from data access implementation!");
            Assert.IsTrue((info.IsEqual(dal.StoredInfo)),
                          $"LogicLayerTests - \"SetRunInfoForDate\" does not pass RunInfo correctly to data access implementation !");
            Assert.IsTrue((date == dal.RequestedDate),
                          $"LogicLayerTests - \"SetRunInfoForDate\" does not pass date correctly to data access implementation !");
        }
        public void TestGetRunInfoForPastThirtyDays()
        {
            const int count = 30;
            var       dal   = new DummyDal();
            var       logic = new LogicImplementation(dal);

            dal.ReturnDateinInterval = true;

            var infos = logic.GetRunInfoForPastThirtyDays();

            Assert.IsTrue((infos.Length == count),
                          $"LogicLayerTests - \"GetRunInfoForPastThirtyDays\" does not return thirty RunInfo values!");
            for (int i = 0; i < count; i++)
            {
                Assert.IsTrue((infos[i].Interval == Extensions.EncodeDateToTimeSpan(DateTime.Now.Date - new TimeSpan(count - i - 1, 0, 0, 0))),
                              $"LogicLayerTests - \"GetRunInfoForPastThirtyDays\" does not return RunInfo values for correct dates in correct sequence (oldest first)!");
            }
        }
        public void TestSetRunInfoBusinessRules()
        {
            var dal   = new DummyDal();
            var logic = new LogicImplementation(dal);
            var date  = DateTime.Now.Date;

            try
            {
                var info = new RunInfo(-5, new TimeSpan(3210));
                logic.SetRunInfoForDate(date, info);
                Assert.Fail($"LogicLayerTests - \"SetRunInfoForDate\" does not throw ArgumentOutOfRangeException for negative distance!");
            }
            catch (ArgumentOutOfRangeException e)
            {
                // this is expected, no problem
            }
            catch (AssertFailedException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                Assert.Fail($"LogicLayerTests - \"SetRunInfoForDate\" with negative distance throws {e.GetType().Name} instead of ArgumentOutOfRangeException !");
            }

            try
            {
                var info = new RunInfo(130, new TimeSpan(0, 0, 9));
                logic.SetRunInfoForDate(date, info);
                Assert.Fail($"LogicLayerTests - \"SetRunInfoForDate\" does not throw ArgumentOutOfRangeException for speed in excess of 50km/h!");
            }
            catch (ArgumentOutOfRangeException e)
            {
                // this is expected, no problem
            }
            catch (AssertFailedException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                Assert.Fail($"LogicLayerTests - \"SetRunInfoForDate\" with speed in excess of 50km/h throws {e.GetType().Name} instead of ArgumentOutOfRangeException !");
            }
        }