示例#1
0
        public void ReturnEmptyCollection_When_SensorsDB_IsEmpty()
        {
            //Arrange
            var contextOptions = new DbContextOptionsBuilder <SmartDormitoryDbContext>()
                                 .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                                 .Options;

            // Act && Asert
            using (var assertContext = new SmartDormitoryDbContext(contextOptions))
            {
                var sensorService = new SensorService(assertContext);
                var allSensors    = sensorService.GetAll().ToList();

                Assert.AreEqual(0, allSensors.Count);
            }
        }
示例#2
0
        public void ReturnAllSensors_When_Invoked()
        {
            //Arrange
            var contextOptions = new DbContextOptionsBuilder <SmartDormitoryDbContext>()
                                 .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                                 .Options;

            var ApiID = Guid.NewGuid().ToString();

            using (var arrangeContext = new SmartDormitoryDbContext(contextOptions))
            {
                var sensorForDB = new Sensor
                {
                    ApiId        = ApiID,
                    CurrentValue = 10,
                    Description  = "Description",
                    Name         = "Name",
                    MinValue     = 1,
                    MaxValue     = 100,
                    MinPollingIntervalInSeconds = 60,
                    SensorTypeId = 1,
                    LastUpdate   = DateTime.Now,
                };

                arrangeContext.Sensors.Add(sensorForDB);
                arrangeContext.SaveChanges();
            }

            // Act && Asert
            using (var assertContext = new SmartDormitoryDbContext(contextOptions))
            {
                var sensorService = new SensorService(assertContext);
                var allSensors    = sensorService.GetAll().ToList();

                Assert.AreEqual(1, allSensors.Count);
            }
        }
示例#3
0
 public IEnumerable <Sensor> Get()
 {
     return(_service.GetAll());
 }