public async Task SetUserIsDeleted_ToTrue()
        {
            //Arrange
            var contextOptions = new DbContextOptionsBuilder <DormitorySystemContext>()
                                 .UseInMemoryDatabase("SetUserIsDeleted_ToTrue")
                                 .Options;

            var seedUsersMock   = new Mock <ISeedUsers>();
            var seedApiDataMock = new Mock <ISeedApiData>();

            var user = new User
            {
                Id    = "00000000-0000-0000-0000-000000000001",
                Email = "*****@*****.**"
            };

            //Act
            using (var actContext = new DormitorySystemContext(contextOptions,
                                                               seedUsersMock.Object, seedApiDataMock.Object))
            {
                actContext.Users.Add(user);
                actContext.SaveChanges();
            }

            //Assert
            using (var assertContext = new DormitorySystemContext(contextOptions,
                                                                  seedUsersMock.Object, seedApiDataMock.Object))
            {
                var service = new UserService(assertContext);
                var result  = await service.DeleteUserAsync(user.Id);

                StringAssert.Contains("True", result.isDeleted.ToString());
            }
        }
Beispiel #2
0
        public async Task ReturnPublicSensors_WhenCollectionIsNotEmpty()
        {
            var contextOptions = new DbContextOptionsBuilder <DormitorySystemContext>()
                                 .UseInMemoryDatabase("ReturnPublicSensors_WhenCollectionIsNotEmpty")
                                 .Options;

            var seedUsersMock   = new Mock <ISeedUsers>();
            var seedApiDataMock = new Mock <ISeedApiData>();
            var measure         = new Measure
            {
                Id          = 1,
                MeasureType = "test"
            };
            var sensorType = new SensorType
            {
                Id   = 1,
                Name = "Test"
            };
            var sampleSensor = new SampleSensor
            {
                Id                 = Guid.Parse("00000000-0000-0000-0000-000000000002"),
                Tag                = "Test Sensor",
                Description        = "Test Sensor",
                MinPollingInterval = 20,
                MeasureId          = measure.Id,
                ValueCurrent       = 50,
                SensorTypeId       = sensorType.Id,
                IsOnline           = true
            };
            var userSensor = new UserSensor
            {
                Id               = Guid.Parse("00000000-0000-0000-0000-000000000001"),
                CreatedOn        = DateTime.Now,
                isDeleted        = false,
                SampleSensorId   = sampleSensor.Id,
                PollingInterval  = 100,
                SendNotification = true,
                IsPrivate        = false
            };

            //Act
            using (var actContext = new DormitorySystemContext(contextOptions,
                                                               seedUsersMock.Object, seedApiDataMock.Object))
            {
                actContext.Measures.Add(measure);
                actContext.SensorTypes.Add(sensorType);
                actContext.SampleSensors.Add(sampleSensor);
                actContext.UserSensors.Add(userSensor);
                actContext.SaveChanges();
            }
            //Assert
            using (var assertContext = new DormitorySystemContext(contextOptions,
                                                                  seedUsersMock.Object, seedApiDataMock.Object))
            {
                var service = new SensorService(assertContext);
                var result  = await service.GetPublicSensorsAsync();

                Assert.AreEqual(1, result.Count());
            }
        }
        public async Task ReturnListOfUsers_WhenCollectionIsNotEmpty()
        {
            var contextOptions = new DbContextOptionsBuilder <DormitorySystemContext>()
                                 .UseInMemoryDatabase("ReturnListOfUsers_WhenCollectionIsNotEmpty")
                                 .Options;

            var seedUsersMock   = new Mock <ISeedUsers>();
            var seedApiDataMock = new Mock <ISeedApiData>();

            var user = new User
            {
                Id    = "00000000-0000-0000-0000-000000000001",
                Email = "*****@*****.**"
            };

            //Act
            using (var actContext = new DormitorySystemContext(contextOptions,
                                                               seedUsersMock.Object, seedApiDataMock.Object))
            {
                actContext.Users.Add(user);
                actContext.SaveChanges();
            }
            //Assert
            using (var assertContext = new DormitorySystemContext(contextOptions,
                                                                  seedUsersMock.Object, seedApiDataMock.Object))
            {
                var service = new UserService(assertContext);
                var result  = await service.ListUsersAsync();

                Assert.AreEqual(1, result.Count());
                Assert.AreEqual(user.Id, result.First().Id);
            }
        }
Beispiel #4
0
 public ICBApiService(DormitorySystemContext context,
                      IApiProvider apiProvider,
                      INotificationsService notifications)
 {
     this.context       = context;
     this.apiProvider   = apiProvider;
     this.notifications = notifications;
 }
Beispiel #5
0
        public async Task ReturnProperSensor_WhenValidValueIsPassed()
        {
            //Arrange
            var contextOptions = new DbContextOptionsBuilder <DormitorySystemContext>()
                                 .UseInMemoryDatabase("ReturnProperSensor_WhenValidValueIsPassed")
                                 .Options;

            var seedUsersMock   = new Mock <ISeedUsers>();
            var seedApiDataMock = new Mock <ISeedApiData>();
            var measure         = new Measure
            {
                Id          = 1,
                MeasureType = "test"
            };
            var sensorType = new SensorType
            {
                Id   = 1,
                Name = "Test"
            };
            var sampleSensor = new SampleSensor
            {
                Id                 = Guid.Parse("00000000-0000-0000-0000-000000000001"),
                Tag                = "Test Sensor",
                Description        = "Test Sensor",
                MinPollingInterval = 20,
                MeasureId          = measure.Id,
                ValueCurrent       = 50,
                SensorTypeId       = sensorType.Id,
                IsOnline           = true
            };

            //Act
            using (var actContext = new DormitorySystemContext(contextOptions,
                                                               seedUsersMock.Object, seedApiDataMock.Object))
            {
                actContext.Measures.Add(measure);
                actContext.SensorTypes.Add(sensorType);
                actContext.SampleSensors.Add(sampleSensor);
                actContext.SaveChanges();
            }

            //Assert
            using (var assertContext = new DormitorySystemContext(contextOptions,
                                                                  seedUsersMock.Object, seedApiDataMock.Object))
            {
                var service = new SensorService(assertContext);
                var result  = await service.GetSampleSensorAsync(sampleSensor.Id);

                Assert.AreEqual(sampleSensor.Tag, result.Tag);
            }
        }
        public async Task ThrowSensorNullableException_WhenSensorIsNotPassed()
        {
            //Arrange
            var contextOptions = new DbContextOptionsBuilder <DormitorySystemContext>()
                                 .UseInMemoryDatabase("ThrowSensorNullableException_WhenSensorIsNotPassed")
                                 .Options;

            var seedUsersMock   = new Mock <ISeedUsers>();
            var seedApiDataMock = new Mock <ISeedApiData>();

            //Assert
            using (var assertContext = new DormitorySystemContext(contextOptions,
                                                                  seedUsersMock.Object, seedApiDataMock.Object))
            {
                var service = new SensorService(assertContext);
                var result  = await service.RegisterSensorAsync(null);
            }
        }
        public async Task ThrowSensorNullableException_WhenInvalidIdIsPassed()
        {
            //Arrange
            var contextOptions = new DbContextOptionsBuilder <DormitorySystemContext>()
                                 .UseInMemoryDatabase("ThrowSensorNullableException_WhenInvalidIdIsPassed")
                                 .Options;

            var seedUsersMock   = new Mock <ISeedUsers>();
            var seedApiDataMock = new Mock <ISeedApiData>();

            //Assert
            using (var assertContext = new DormitorySystemContext(contextOptions,
                                                                  seedUsersMock.Object, seedApiDataMock.Object))
            {
                var service = new SensorService(assertContext);
                var guid    = Guid.Parse("00000000-0000-0000-0000-000000000005");
                var result  = await service.DeleteUserSensorAsync(guid);
            }
        }
Beispiel #8
0
        public async Task ReturnEmptyCollection_WhenNoPublicSensors()
        {
            //Arrange
            var contextOptions = new DbContextOptionsBuilder <DormitorySystemContext>()
                                 .UseInMemoryDatabase("ReturnEmptyCollection_WhenNoPublicSensors")
                                 .Options;

            var seedUsersMock   = new Mock <ISeedUsers>();
            var seedApiDataMock = new Mock <ISeedApiData>();

            //Assert
            using (var assertContext = new DormitorySystemContext(contextOptions,
                                                                  seedUsersMock.Object, seedApiDataMock.Object))
            {
                var service = new SensorService(assertContext);
                var result  = await service.GetPublicSensorsAsync();

                Assert.AreEqual(0, result.Count());
            }
        }
Beispiel #9
0
 public NotificationsService(DormitorySystemContext context, IHubService hubService)
 {
     this.context    = context;
     this.hubService = hubService;
 }
        public async Task DeleteProperUserSensor_WhenValidIdIsPassed()
        {
            //Arrange
            var contextOptions = new DbContextOptionsBuilder <DormitorySystemContext>()
                                 .UseInMemoryDatabase("DeleteProperUserSensor_WhenValidIdIsPassed")
                                 .Options;

            var seedUsersMock   = new Mock <ISeedUsers>();
            var seedApiDataMock = new Mock <ISeedApiData>();

            var measure = new Measure
            {
                Id          = 1,
                MeasureType = "test"
            };
            var sensorType = new SensorType
            {
                Id   = 1,
                Name = "Test"
            };
            var sampleSensor = new SampleSensor
            {
                Id                 = Guid.Parse("00000000-0000-0000-0000-000000000002"),
                Tag                = "Test Sensor",
                Description        = "Test Sensor",
                MinPollingInterval = 20,
                MeasureId          = measure.Id,
                ValueCurrent       = 50,
                SensorTypeId       = sensorType.Id,
                IsOnline           = true
            };
            var userSensor = new UserSensor
            {
                Id               = Guid.Parse("00000000-0000-0000-0000-000000000001"),
                CreatedOn        = DateTime.Now,
                isDeleted        = false,
                SampleSensorId   = sampleSensor.Id,
                PollingInterval  = 100,
                SendNotification = true,
                IsPrivate        = false
            };

            //Act
            using (var actContext = new DormitorySystemContext(contextOptions,
                                                               seedUsersMock.Object, seedApiDataMock.Object))
            {
                actContext.Measures.Add(measure);
                actContext.SensorTypes.Add(sensorType);
                actContext.SampleSensors.Add(sampleSensor);
                actContext.UserSensors.Add(userSensor);
                actContext.SaveChanges();
            }

            //Assert
            using (var assertContext = new DormitorySystemContext(contextOptions,
                                                                  seedUsersMock.Object, seedApiDataMock.Object))
            {
                var service = new SensorService(assertContext);
                var result  = await service.DeleteUserSensorAsync(userSensor.Id);

                StringAssert.Contains("True", result.isDeleted.ToString());
            }
        }
 public UserService(DormitorySystemContext contex)
 {
     this.contex = contex;
 }
        public async Task ReturnProperUserWithSensors_WhenValidIdIsPassed()
        {
            //Arrange
            var contextOptions = new DbContextOptionsBuilder <DormitorySystemContext>()
                                 .UseInMemoryDatabase("ReturnProperUserSensor_WhenValidIdIsPassed")
                                 .Options;

            var seedUsersMock   = new Mock <ISeedUsers>();
            var seedApiDataMock = new Mock <ISeedApiData>();

            var user = new User
            {
                Id      = "00000000-0000-0000-0000-000000000001",
                Email   = "*****@*****.**",
                Sensors = new List <UserSensor>()
            };

            var measure = new Measure
            {
                Id          = 1,
                MeasureType = "test"
            };
            var sensorType = new SensorType
            {
                Id   = 1,
                Name = "Test"
            };
            var sampleSensor = new SampleSensor
            {
                Id                 = Guid.Parse("00000000-0000-0000-0000-000000000222"),
                Tag                = "Test Sensor",
                Description        = "Test Sensor",
                MinPollingInterval = 20,
                MeasureId          = measure.Id,
                ValueCurrent       = 50,
                SensorTypeId       = sensorType.Id,
                IsOnline           = true
            };
            var userSensor = new UserSensor
            {
                Id               = Guid.Parse("00000000-0000-0000-0000-000000000111"),
                CreatedOn        = DateTime.Now,
                isDeleted        = false,
                SampleSensorId   = sampleSensor.Id,
                PollingInterval  = 100,
                SendNotification = true,
                IsPrivate        = false,
                UserId           = user.Id
            };

            //Act
            using (var actContext = new DormitorySystemContext(contextOptions,
                                                               seedUsersMock.Object, seedApiDataMock.Object))
            {
                actContext.Users.Add(user);
                actContext.UserSensors.Add(userSensor);
                actContext.SaveChanges();
            }
            //Assert
            using (var assertContext = new DormitorySystemContext(contextOptions,
                                                                  seedUsersMock.Object, seedApiDataMock.Object))
            {
                var service = new UserService(assertContext);
                var result  = await service.GetUserWithSensorsAsync(user.Id);

                Assert.AreEqual(1, result.Sensors.Count());
                Assert.AreEqual(userSensor.Id, result.Sensors.First().Id);
            }
        }
 public SensorService(DormitorySystemContext context)
 {
     this.context = context;
 }