public void DataAccessImplementationIsDerivedFromIDataAccess()
        {
            IDataAccess dal = new DataAccessImplementation() as IDataAccess;

            Assert.IsNotNull(dal,
                             $"DataAccessLayerTests - Class \"DataAccessImplementation\" does not implement interface \"IDataAccess\"!");
        }
        public void TestClearData()
        {
            const int distance1 = 1000;
            var       interval1 = new TimeSpan(0, 6, 0);
            var       da        = new DataAccessImplementation();
            var       date      = DateTime.Now - new TimeSpan(5, 0, 0, 0);

            da.StoreRunInfo(date, new RunInfo(distance1, interval1));

            var info = da.GetRunInfoForDate(date);

            Assert.IsNotNull(info, $"DataAccessLayerTests - \"GetRunInfoForDate\" returns null for date with stored info!");
            Assert.IsTrue((info.DistanceInMeter == distance1), $"DataAccessLayerTests - \"GetRunInfoForDate\" returns wrong distance: was {info.DistanceInMeter}, expected {distance1}!");
            Assert.IsTrue((info.Interval == interval1), $"DataAccessLayerTests - \"GetRunInfoForDate\" returns wrong interval: was {info.Interval.ToString()}, expected {interval1.ToString()}!");

            da.ClearData();
            info = da.GetRunInfoForDate(date);
            Assert.IsNotNull(info, $"DataAccessLayerTests - \"GetRunInfoForDate\" returns null after call to \"ClearData\"!");
            Assert.IsTrue((info.DistanceInMeter == 0), $"DataAccessLayerTests - \"GetRunInfoForDate\" returns wrong distance after call to \"ClearData\": was {info.DistanceInMeter}, expected {0}!");
            Assert.IsTrue((info.Interval == new TimeSpan(0, 0, 0)), $"DataAccessLayerTests - \"GetRunInfoForDate\" returns wrong interval after call to \"ClearData\": was {info.Interval.ToString()}, expected {new TimeSpan(0, 0, 0).ToString()}!");


            da   = new DataAccessImplementation();
            info = da.GetRunInfoForDate(date);
            Assert.IsNotNull(info, $"DataAccessLayerTests - \"GetRunInfoForDate\" returns null after call to \"ClearData\" & restart!");
            Assert.IsTrue((info.DistanceInMeter == 0), $"DataAccessLayerTests - \"ClearData\" does not clear distance data on disk!");
            Assert.IsTrue((info.Interval == new TimeSpan(0, 0, 0)), $"DataAccessLayerTests - \"ClearData\" does not clear instance data on disk!!");
        }
Beispiel #3
0
        static void Main()
        {
            DataAccessImplementation dataAcces = new DataAccessImplementation();
            LogicImplementation      logic     = new LogicImplementation(dataAcces);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm(logic));
        }
        public void NonexistingDatereturnsDefaultValue()
        {
            var da   = new DataAccessImplementation();
            var info = da.GetRunInfoForDate(DateTime.Now.Date + new TimeSpan(3000, 0, 0, 0));

            Assert.IsNotNull(info, $"DataAccessLayerTests - \"GetRunInfoForDate\" returns null for date without info (should be default value)!");
            Assert.IsTrue((info.DistanceInMeter == 0), $"DataAccessLayerTests - \"GetRunInfoForDate\" does not return zero distance for date without info!");
            Assert.IsTrue((info.Interval == new TimeSpan(0, 0, 0)), $"DataAccessLayerTests - \"GetRunInfoForDate\" does not return zero interval for date without info!");
        }
        public void StoreAndRetrieveRunInfos()
        {
            const int distance1 = 1000;
            var       interval1 = new TimeSpan(0, 6, 0);
            var       da        = new DataAccessImplementation();
            var       date      = DateTime.Now - new TimeSpan(5, 0, 0, 0);

            da.StoreRunInfo(date, new RunInfo(distance1, interval1));

            var info = da.GetRunInfoForDate(date);

            Assert.IsNotNull(info, $"DataAccessLayerTests - \"GetRunInfoForDate\" returns null for date with stored info!");
            Assert.IsTrue((info.DistanceInMeter == distance1), $"DataAccessLayerTests - \"GetRunInfoForDate\" returns wrong distance: was {info.DistanceInMeter}, expected {distance1}!");
            Assert.IsTrue((info.Interval == interval1), $"DataAccessLayerTests - \"GetRunInfoForDate\" returns wrong interval: was {info.Interval.ToString()}, expected {interval1.ToString()}!");
        }
        public void OverWriteRunInfo()
        {
            const int distance1 = 1000;
            var       interval1 = new TimeSpan(0, 6, 0);
            const int distance2 = 2000;
            var       interval2 = new TimeSpan(0, 15, 0);
            var       da        = new DataAccessImplementation();
            var       date      = DateTime.Now - new TimeSpan(5, 0, 0, 0);

            try
            {
                da.StoreRunInfo(date, new RunInfo(distance1, interval1));
                da.StoreRunInfo(date, new RunInfo(distance2, interval2));
            }
            catch (Exception e)
            {
                Assert.Fail($"DataAccessLayerTests - OverWriteRunInfo: storing new info for existing date throws exception: {e.Message} ");
            }
            var info = da.GetRunInfoForDate(date);

            Assert.IsNotNull(info, $"DataAccessLayerTests - \"GetRunInfoForDate\" returns null for date with stored info!");
            Assert.IsTrue((info.DistanceInMeter == distance2), $"DataAccessLayerTests - \"GetRunInfoForDate\" returns wrong distance after overwrite: was {info.DistanceInMeter}, expected {distance2}!");
            Assert.IsTrue((info.Interval == interval2), $"DataAccessLayerTests - \"GetRunInfoForDate\" returns wrong interval after overwrite: was {info.Interval.ToString()}, expected {interval2.ToString()}!");
        }