Exemplo n.º 1
0
 public ToggleMqttEntityStatusJobTest()
 {
     _initial   = SystemClock.Instance.GetCurrentInstant();
     _clock     = new FakeClock(_initial);
     _dbContext = ApplicationDbContextHelper.BuildTestDbContext(_clock);
     _job       = new ToggleMqttEntityStatusJob(_clock, _dbContext);
 }
Exemplo n.º 2
0
 public UpdateUserLastSeenAtTimestampJobTest()
 {
     _initial   = SystemClock.Instance.GetCurrentInstant();
     _clock     = new FakeClock(_initial);
     _dbContext = ApplicationDbContextHelper.BuildTestDbContext(_clock);
     _job       = new UpdateUserLastSeenAtTimestampJob(_dbContext);
 }
Exemplo n.º 3
0
 public DeviceServiceTest()
 {
     _dbContext         = ApplicationDbContextHelper.BuildTestDbContext();
     _initial           = SystemClock.Instance.GetCurrentInstant();
     _identifierService = new MqttIdentifierService(new FakeClock(_initial));
     _service           = new DeviceService(_dbContext, _identifierService);
 }
Exemplo n.º 4
0
        private async Task <(Sensor, Sensor)> SeedDefaultCaseAsync()
        {
            var roleManager = IdentityHelpers.BuildRoleManager(ApplicationDbContextHelper.BuildTestDbContext());
            await roleManager.CreateAsync(new IdentityRole <long>("Admin"));

            foreach (var userName in new[] { "normal-user-1", "normal-user-2", "normal-user-3", "admin-user" })
            {
                await _userManager.CreateAsync(new User
                {
                    UserName           = userName,
                    NormalizedUserName = userName.ToUpperInvariant(),
                    SecurityStamp      = Guid.NewGuid().ToString()
                }, "normal-password");
            }
            var admin = await _userManager.FindByNameAsync("admin-user");

            await _userManager.AddToRoleAsync(admin, "Admin");

            var deviceName = "device";
            var device     = new Device {
                Name               = deviceName,
                NormalizedName     = deviceName.ToUpperInvariant(),
                AuthenticationType = DeviceAuthenticationType.PreSharedKey,
                PreSharedKey       = "key"
            };

            _dbContext.Devices.Add(device);

            var name1   = "sensor-1";
            var sensor1 = new Sensor {
                Name = name1, NormalizedName = name1.ToUpperInvariant(), Device = device
            };

            _dbContext.Sensors.Add(sensor1);
            var name2   = "sensor-2";
            var sensor2 = new Sensor {
                Name = name2, NormalizedName = name2.ToUpperInvariant(), Device = device
            };

            _dbContext.Sensors.Add(sensor2);

            var user1 = await _userManager.FindByNameAsync("normal-user-1");

            var user2 = await _userManager.FindByNameAsync("normal-user-2");

            _dbContext.UserSensors.Add(new UserSensor {
                UserId = user1.Id, Sensor = sensor1
            });
            _dbContext.UserSensors.Add(new UserSensor {
                UserId = user1.Id, Sensor = sensor2
            });
            _dbContext.UserSensors.Add(new UserSensor {
                UserId = user2.Id, Sensor = sensor1
            });

            await _dbContext.SaveChangesAsync();

            return(sensor1, sensor2);
        }
Exemplo n.º 5
0
 public DashboardServiceTest()
 {
     _initial     = SystemClock.Instance.GetCurrentInstant();
     _dbContext   = ApplicationDbContextHelper.BuildTestDbContext();
     _userManager = IdentityHelpers.BuildUserManager(ApplicationDbContextHelper.BuildTestDbContext());
     _roleManager = IdentityHelpers.BuildRoleManager(ApplicationDbContextHelper.BuildTestDbContext());
     _service     = new DashboardService(_dbContext, _userManager);
 }
Exemplo n.º 6
0
 public UserManagementServiceTest()
 {
     _clock       = new FakeClock(SystemClock.Instance.GetCurrentInstant());
     _dbContext   = ApplicationDbContextHelper.BuildTestDbContext(_clock);
     _userManager = IdentityHelpers.BuildUserManager(ApplicationDbContextHelper.BuildTestDbContext(_clock));
     _roleManager = IdentityHelpers.BuildRoleManager(ApplicationDbContextHelper.BuildTestDbContext(_clock));
     _service     = new UserManagementService(_dbContext, _userManager, _roleManager, new NullLogger <UserManagementService>(), _clock);
 }
        public MqttEntityIdentifierSuggestionServiceTest()
        {
            var mockedAccessor = new Mock <IIdentifierDictionaryFileAccessor>();

            mockedAccessor.Setup(x => x.ListIdentifiers(It.IsAny <string>())).Returns(new List <string> {
                "id1", "id2", "id3"
            });
            _identifierService = new MqttIdentifierService(new FakeClock(Instant.FromUtc(2020, 1, 1, 0, 0)));

            _dbContext = ApplicationDbContextHelper.BuildTestDbContext();
            _service   = new MqttEntityIdentifierSuggestionService(_identifierService, mockedAccessor.Object, _dbContext);
        }
        public MosquittoBrokerMessageServiceTest()
        {
            _initial   = SystemClock.Instance.GetCurrentInstant();
            _clock     = new FakeClock(_initial);
            _dbContext = ApplicationDbContextHelper.BuildTestDbContext(_clock);
            var keyService = new SecureKeySuggestionService();

            _clientAuthService = new MosquittoClientAuthenticationService(keyService);
            var mockPlugin        = new Mock <MosquittoBrokerPluginPidService>();
            var identifierSerivce = new MqttIdentifierService(_clock);

            _deviceService = new DeviceService(_dbContext, identifierSerivce);
            _service       = new MosquittoBrokerMessageService(_clientAuthService, mockPlugin.Object, _deviceService);
        }
Exemplo n.º 9
0
        public MqttMessageIngestionServiceTest()
        {
            _dbContext = ApplicationDbContextHelper.BuildTestDbContext();
            _initial   = SystemClock.Instance.GetCurrentInstant();
            _clock     = new FakeClock(_initial);

            var mock = new Mock <IMosquittoBrokerPidAccessor>();

            mock.SetupGet(a => a.BrokerPid).Returns(10000);
            var mockPlugin = new Mock <IMosquittoBrokerPluginPidService>();

            mockPlugin.SetupGet(a => a.BrokerPidFromAuthPlugin).Returns(10000);

            _brokerService = new MosquittoBrokerService(_clock, new NullLogger <MosquittoBrokerService>(), mock.Object, mockPlugin.Object);

            _mqttIdentifierService = new MqttIdentifierService(_clock);
            _deviceService         = new DeviceService(_dbContext, _mqttIdentifierService);
            _valueService          = new SensorValueService(_dbContext);

            _service = new MqttMessageIngestionService(_deviceService, _mqttIdentifierService, _brokerService, _valueService, new NullLogger <MqttMessageIngestionService>());
        }
Exemplo n.º 10
0
 public SensorAssignmentServiceTest()
 {
     _dbContext   = ApplicationDbContextHelper.BuildTestDbContext();
     _userManager = IdentityHelpers.BuildUserManager(ApplicationDbContextHelper.BuildTestDbContext());
     _service     = new SensorAssignmentService(_dbContext, _userManager);
 }