Beispiel #1
0
        public void temp_controller_get_all_temps()
        {
            var tempController = new TempPlugin.TempController(_dbConnectionString);

            var addEntity = new TempPlugin.TempModel
            {
                Id       = 1,
                Value    = 1f,
                DateTime = new DateTime(2018, 12, 1, 12, 0, 0)
            };
            var addSuccess = tempController.AddTemp(addEntity);

            Assert.IsTrue(addSuccess);

            var addEntity2 = new TempPlugin.TempModel
            {
                Id       = 2,
                Value    = 2f,
                DateTime = new DateTime(2019, 12, 1, 12, 0, 0)
            };

            addSuccess = tempController.AddTemp(addEntity2);
            Assert.IsTrue(addSuccess);

            var temps = tempController.GetTemps().ToArray();

            Assert.IsNotNull(temps);
            Assert.AreEqual(2, temps.Length);

            Assert.AreEqual(addEntity2.Id, temps[0].Id);
            Assert.AreEqual(addEntity2.DateTime, temps[0].DateTime);
            Assert.AreEqual(addEntity2.Value, temps[0].Value);
            Assert.AreEqual(addEntity.Id, temps[1].Id);
            Assert.AreEqual(addEntity.DateTime, temps[1].DateTime);
            Assert.AreEqual(addEntity.Value, temps[1].Value);

            Assert.IsTrue(tempController.RemoveTemp((int)addEntity.Id));
            Assert.IsTrue(tempController.RemoveTemp((int)addEntity2.Id));
        }
Beispiel #2
0
        public void temp_controller_add_get_remove_count()
        {
            var tempController = new TempPlugin.TempController(_dbConnectionString);

            var addEntity = new TempPlugin.TempModel
            {
                Id       = 1234,
                Value    = 1.12345f,
                DateTime = new DateTime(2019, 12, 1, 12, 0, 0)
            };
            var addSuccess = tempController.AddTemp(addEntity);

            Assert.IsTrue(addSuccess);

            addSuccess = tempController.AddTemp(addEntity);
            Assert.IsFalse(addSuccess);

            var count = tempController.Count();

            Assert.AreEqual(1, count);

            var countDate = tempController.CountByDate(addEntity.DateTime);

            Assert.AreEqual(1, countDate);

            var getEntity = tempController.GetTemp((int)addEntity.Id);

            Assert.IsNotNull(getEntity);
            Assert.AreEqual(addEntity.Id, getEntity.Id);
            Assert.AreEqual(addEntity.DateTime, getEntity.DateTime);
            Assert.AreEqual(addEntity.Value, getEntity.Value);

            var removeSuccess = tempController.RemoveTemp((int)addEntity.Id);

            Assert.IsTrue(removeSuccess);

            removeSuccess = tempController.RemoveTemp((int)addEntity.Id);
            Assert.IsFalse(removeSuccess);

            getEntity = tempController.GetTemp((int)addEntity.Id);
            Assert.IsNull(getEntity);

            count = tempController.Count();
            Assert.AreEqual(0, count);

            countDate = tempController.CountByDate(addEntity.DateTime);
            Assert.AreEqual(0, countDate);

            /*
             * Test without Id
             * however data can not be removed because the id is not known
             *
             * var testEntity = new TempPlugin.TempModel
             * {
             *  Value =  1.12345f,
             *  DateTime = new DateTime(2019, 12, 1, 12, 0, 0)
             * };
             * addSuccess = tempController.AddTemp(testEntity);
             * Assert.IsTrue(addSuccess);
             */
        }