private IList <IStorageChannel> CreateSensorChannels()
        {
            OverlordIdentity.InitializeAnonymousIdentity();
            AzureStorage storage = new AzureStorage();

            storage.AuthenticateAnonymousDevice(TestData.device_02_id.UrnToId(),
                                                TestData.device_02_token);
            //OverlordIdentity.AddClaim(Resource.Storage, StorageAction.FindDevice);
            //IStorageDevice = storage.GetCurrentUser();

            IStorageAlert alert_1 = new IStorageAlert()
            {
                SensorType  = "I0",
                IntMaxValue = 100,
                IntMinValue = -10
            };
            IStorageAlert alert_2 = new IStorageAlert()
            {
                SensorType  = "I0",
                IntMaxValue = 40,
                IntMinValue = 0
            };

            List <IStorageAlert> alerts = new List <IStorageAlert>()
            {
                alert_1, alert_2
            };

            OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddChannel);
            IStorageChannel channel = storage.AddChannel("xUnit_IngestTests_Channel_01",
                                                         "A test channel for xUnit AzureStorageIngestTests", "I0", "Test integer units",
                                                         alerts);

            OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddChannel);
            alert_1 = new IStorageAlert()
            {
                SensorType  = "S0",
                StringValue = "Alert 1!"
            };
            alert_2 = new IStorageAlert()
            {
                SensorType  = "S0",
                StringValue = "Alert 1!"
            };

            alerts = new List <IStorageAlert>()
            {
                alert_1, alert_2
            };
            OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddChannel);
            IStorageChannel channel_2 = storage.AddChannel("xUnit_IngestTests_Channel_03",
                                                           "A test channel for xUnit AzureStorageIngestTests", "S0", "Test stringr units",
                                                           alerts);

            return(new List <IStorageChannel>()
            {
                channel, channel_2
            });
        }
        public void CanAuthenticateAnonymousDevice()
        {
            OverlordIdentity.InitializeAnonymousIdentity();
            AzureStorage storage = new AzureStorage();

            Assert.True(storage.AuthenticateAnonymousDevice(TestData.device_01_id.UrnToId(),
                                                            TestData.device_01_token));
            Assert.False(OverlordIdentity.HasClaim(Authentication.Role, UserRole.Anonymous));
            Assert.True(OverlordIdentity.HasClaim(Authentication.Role, UserRole.Device));
        }
Example #3
0
 public void CanInitializeIdentity()
 {
     Assert.False(OverlordIdentity.HasClaim(Authentication.Role, UserRole.Anonymous));
     OverlordIdentity.InitializeAnonymousIdentity();
     Assert.True(OverlordIdentity.HasClaim(Authentication.Role, UserRole.Anonymous));
     OverlordIdentity.InitializeDeviceIdentity(TestData.device_01_id.UrnToId(), TestData.device_01_token, new string[0]);
     Assert.False(OverlordIdentity.HasClaim(Authentication.Role, UserRole.Anonymous));
     Assert.True(OverlordIdentity.HasClaim(Authentication.Role, UserRole.Device));
     OverlordIdentity.InitializeUserIdentity(TestData.user_01_id.UrnToId(), TestData.user_01_token, new string[0]);
     Assert.False(OverlordIdentity.HasClaim(Authentication.Role, UserRole.Device));
     Assert.True(OverlordIdentity.HasClaim(Authentication.Role, UserRole.User));
 }
Example #4
0
        public void CanAddSensor()
        {
            AzureStorage storage = new AzureStorage();

            OverlordIdentity.InitializeAnonymousIdentity();
            storage.AuthenticateAnonymousDevice(TestData.device_02_id.UrnToId(),
                                                TestData.device_02_token);
            OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddSensor);
            IStorageSensor sensor = storage.AddSensor(TestData.sensor_01_name, TestData.sensor_01_unit, null, null);

            Assert.NotNull(sensor);
            Assert.Equal(sensor.Name, TestData.sensor_01_name);
            Assert.Equal(sensor.Unit, TestData.sensor_01_unit);
        }
Example #5
0
        public void CanAddDeviceReadingParallel()
        {
            Dictionary <int, IStorageDevice> devices = new Dictionary <int, IStorageDevice>();

            OverlordIdentity.InitializeAnonymousIdentity();
            AzureStorage storage = new AzureStorage();

            storage.AuthenticateAnonymousUser(TestData.user_02_id.UrnToId(),
                                              TestData.user_02_token);
            OverlordIdentity.AddClaim(Resource.Storage, StorageAction.FindUser);
            IStorageUser user = storage.GetCurrentUser();

            for (int i = 0; i <= 5; i++)

            {
                OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDevice);
                IStorageDevice device = storage.AddDevice(user, "xUnit_CanAddDevicereadingParallel_Device_" + i.ToString(),
                                                          "xUnit_CanAddDevicereadingParallel_Device_Token", null, null);
                devices.Add(i, device);
            }
            OverlordIdentity.InitializeAnonymousIdentity();
            Parallel.For(0, devices.Count, d =>
            {
                Log.Partition();
                storage.AuthenticateAnonymousDevice(devices[d].Id.ToUrn(), devices[0].Token);
                IDictionary <string, object> sensor_values = TestData.GenerateRandomSensorData(10);
                OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDeviceReading);
                storage.AddDeviceReading(TestData.GenerateRandomTime(null, null, null, null),
                                         sensor_values);
                //Sleep for a random interval
                Thread.Sleep(TestData.GenerateRandomInteger(0, 1000));

                //Add another set of sensor data
                OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDeviceReading);
                storage.AddDeviceReading(TestData.GenerateRandomTime(null, null, null, null),
                                         TestData.GenerateRandomSensorData(sensor_values));

                //Sleep for a random interval
                Thread.Sleep(TestData.GenerateRandomInteger(0, 1000));

                //Add another set of sensor data
                OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDeviceReading);
                storage.AddDeviceReading(TestData.GenerateRandomTime(null, null, null, null),
                                         TestData.GenerateRandomSensorData(sensor_values));
            });
        }
Example #6
0
        public void CanAddDeviceReading()
        {
            OverlordIdentity.InitializeAnonymousIdentity();
            AzureStorage storage = new AzureStorage();

            storage.AuthenticateAnonymousDevice(TestData.device_01_id.UrnToId(),
                                                TestData.device_01_token);
            OverlordIdentity.AddClaim(Resource.Storage, StorageAction.FindDevice);
            IStorageDevice device = storage.GetCurrentDevice();
            IDictionary <string, object> sensor_values = TestData.GenerateRandomSensorData(10);

            foreach (KeyValuePair <string, object> s in sensor_values)
            {
                OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddSensor);
                storage.AddSensor(s.Key, "CanAddDeviceReading_Test", null, null);
            }
            OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDeviceReading);
            storage.AddDeviceReading(DateTime.Now, sensor_values);
        }
        private void CreateDeviceReadings()
        {
            IList <IStorageChannel>          channels = CreateSensorChannels();
            Dictionary <int, IStorageDevice> devices  = new Dictionary <int, IStorageDevice>();

            OverlordIdentity.InitializeAnonymousIdentity();
            AzureStorage storage = new AzureStorage();

            storage.AuthenticateAnonymousUser(TestData.user_02_id.UrnToId(),
                                              TestData.user_02_token);
            OverlordIdentity.AddClaim(Resource.Storage, StorageAction.FindUser);
            IStorageUser user = storage.GetCurrentUser();

            for (int i = 0; i <= 5; i++)
            {
                OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDevice);
                IStorageDevice device = storage.AddDevice(user, "xUnit_IngestTests_Device_" + i.ToString(),
                                                          "xUnit_IngestTests_Device_Token", null, null);
                devices.Add(i, device);
            }
            IDictionary <int, IDictionary <string, object> > sensor_values = new Dictionary <int, IDictionary <string, object> >(6);

            for (int d = 0; d <= 5; d++)
            {
                sensor_values[d] = TestData.GenerateRandomSensorData(10);
                foreach (string s in sensor_values[d].Keys)
                {
                    IStorageSensor sensor = new IStorageSensor()
                    {
                        DeviceId = devices[d].Id,
                        Name     = s,
                        Channels = new List <Guid>()
                    };
                    List <IStorageAlert> alerts = new List <IStorageAlert>();
                    foreach (IStorageChannel channel in channels.Where(c => c.SensorType.ToSensorType() ==
                                                                       sensor.Name.ToSensorType()))
                    {
                        sensor.Channels.Add(channel.Id);
                    }
                    OverlordIdentity.AddClaim(Resource.Storage, StorageAction.UpdateDevice);
                    devices[d].Sensors.Add(new KeyValuePair <string, IStorageSensor>(s, sensor));
                    devices[d] = storage.UpdateDevice(devices[d]);
                }
            }
            OverlordIdentity.InitializeAnonymousIdentity();
            storage.AuthenticateAnonymousDevice(devices[0].Id.ToUrn(), devices[0].Token);
            for (int d = 0; d < devices.Count(); d++)
            {
                //Log.Partition();
                OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDeviceReading);
                storage.AddDeviceReading(devices[d], TestData.GenerateRandomTime(null, null, null, null),
                                         sensor_values[d]);
                //Sleep for a random interval
                Thread.Sleep(TestData.GenerateRandomInteger(0, 1000));

                //Add another set of sensor data
                OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDeviceReading);
                storage.AddDeviceReading(devices[d], TestData.GenerateRandomTime(null, null, null, null),
                                         TestData.GenerateRandomSensorData(sensor_values[d]));

                //Sleep for a random interval
                Thread.Sleep(TestData.GenerateRandomInteger(0, 1000));

                //Add another set of sensor data
                OverlordIdentity.AddClaim(Resource.Storage, StorageAction.AddDeviceReading);
                storage.AddDeviceReading(devices[d], TestData.GenerateRandomTime(null, null, null, null),
                                         TestData.GenerateRandomSensorData(sensor_values[d]));
            }
        }