/// <summary>
 /// Initializes a new instance of the <see cref="TraitsController"/> class.
 /// </summary>
 /// <param name="logger">Logging instance.</param>
 /// <param name="deviceRepository">Device repository.</param>
 public TraitsController(
     ILogger <TraitsController> logger,
     GoogleDeviceRepository deviceRepository)
 {
     _log = logger;
     _deviceRepository = deviceRepository;
 }
        public void CanAddItem()
        {
            // Arrange
            var device = DeviceTestData.FullDevice();

            device.Id = device.Id + "1";

            var expectedAddedTopics = device.Traits
                                      .SelectMany(trait => trait.State)
                                      .Where(x => x.Value.Topic != null)
                                      .Select(x => x.Value.Topic);

            var repository = new GoogleDeviceRepository(_logMock.Object, _messageHubMock.Object, _testFilePath);

            // Act
            repository.Add(device);
            var deviceConfigurationString = File.ReadAllText(_testFilePath);
            var result = new Dictionary <string, Device>(JsonConvert.DeserializeObject <Dictionary <string, Device> >(deviceConfigurationString));

            // Assert
            Assert.True(repository.Contains(device.Id));
            Assert.True(result.ContainsKey(device.Id));

            foreach (var expectedTopic in expectedAddedTopics)
            {
                _messageHubMock.Verify(x => x.Publish(It.Is <ConfigSubscriptionChangeEvent>(changeEvent => changeEvent.AddedSubscriptions.Contains(expectedTopic))), Times.Exactly(1));
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GoogleDeviceController"/> class.
 /// </summary>
 /// <param name="logger">Logging instance.</param>
 /// <param name="deviceRepository">Device repository.</param>
 public GoogleDeviceController(
     ILogger <GoogleDeviceController> logger,
     GoogleDeviceRepository deviceRepository)
 {
     _log = logger ?? throw new ArgumentException(nameof(logger));
     _deviceRepository = deviceRepository ?? throw new ArgumentException(nameof(deviceRepository));
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SyncIntentHandler"/> class.
 /// </summary>
 /// <param name="logger">Logging instance.</param>
 /// <param name="configuration">Configuration.</param>
 /// <param name="deviceRepository">Device repository.</param>
 public SyncIntentHandler(
     ILogger <SyncIntentHandler> logger,
     IConfiguration configuration,
     GoogleDeviceRepository deviceRepository)
 {
     _log              = logger ?? throw new ArgumentException(nameof(logger));
     _config           = configuration ?? throw new ArgumentException(nameof(configuration));
     _deviceRepository = deviceRepository ?? throw new ArgumentException(nameof(deviceRepository));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExecuteIntentHandler"/> class.
 /// </summary>
 /// <param name="logger">Logging instance.</param>
 /// <param name="messageHub">Message nhub.</param>
 /// <param name="deviceRepository">Device repository.</param>
 public ExecuteIntentHandler(
     ILogger <ExecuteIntentHandler> logger,
     IMessageHub messageHub,
     GoogleDeviceRepository deviceRepository)
 {
     _log              = logger ?? throw new ArgumentException(nameof(logger));
     _messageHub       = messageHub ?? throw new ArgumentException(nameof(messageHub));
     _deviceRepository = deviceRepository ?? throw new ArgumentException(nameof(deviceRepository));
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QueryIntentHandler"/> class.
 /// </summary>
 /// <param name="logger">Logging instance.</param>
 /// <param name="messageHub">Message hub.</param>
 /// <param name="deviceRepository">Device repository.</param>
 /// <param name="stateCache">State cache.</param>
 public QueryIntentHandler(
     ILogger <QueryIntentHandler> logger,
     IMessageHub messageHub,
     GoogleDeviceRepository deviceRepository,
     StateCache stateCache)
 {
     _log              = logger ?? throw new ArgumentException(nameof(logger));
     _messageHub       = messageHub ?? throw new ArgumentException(nameof(messageHub));
     _deviceRepository = deviceRepository ?? throw new ArgumentException(nameof(deviceRepository));
     _stateCache       = stateCache ?? throw new ArgumentException(nameof(stateCache));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GoogleHomeController"/> class.
 /// </summary>
 /// <param name="logger">Logging instance.</param>
 /// <param name="configuration">Configuration.</param>
 /// <param name="messageHub">Message nhub.</param>
 /// <param name="deviceRepository">Device repository.</param>
 /// <param name="stateCache">State cache.</param>
 public GoogleHomeController(
     ILogger <GoogleHomeController> logger,
     IConfiguration configuration,
     IMessageHub messageHub,
     GoogleDeviceRepository deviceRepository,
     StateCache stateCache)
 {
     _log              = logger;
     _config           = configuration;
     _messageHub       = messageHub;
     _deviceRepository = deviceRepository;
     _stateCache       = stateCache;
 }
        public void CanUpdateItem()
        {
            // Arrange
            var device      = DeviceTestData.FullDevice();
            var oldDeviceId = device.Id + "1";

            var expectedDeletedTopics = device.Traits
                                        .SelectMany(trait => trait.State)
                                        .Where(x => x.Value.Topic != null)
                                        .Select(x => x.Value.Topic)
                                        .ToList();

            device.Traits.Clear();
            device.Traits.Add(new DeviceTrait {
                Trait    = GoogleHome.Models.TraitType.Brightness,
                Commands = new Dictionary <string, IDictionary <string, string> >
                {
                    {
                        "action.devices.commands.BrightnessAbsolute",
                        new Dictionary <string, string>
                        {
                            {
                                "brightness",
                                "test/device/brightness/set"
                            }
                        }
                    }
                },
                State = new Dictionary <string, DeviceState>
                {
                    {
                        "brightness",
                        new DeviceState
                        {
                            Topic    = "/test/device/brightness",
                            ValueMap = null
                        }
                    }
                }
            });

            var expectedAddedTopics = device.Traits
                                      .SelectMany(trait => trait.State)
                                      .Where(x => x.Value.Topic != null)
                                      .Select(x => x.Value.Topic);

            var repository = new GoogleDeviceRepository(_logMock.Object, _messageHubMock.Object, _testFilePath);

            // Act
            repository.Update(oldDeviceId, device);
            var deviceConfigurationString = File.ReadAllText(_testFilePath);
            var result = new Dictionary <string, Device>(JsonConvert.DeserializeObject <Dictionary <string, Device> >(deviceConfigurationString));

            // Assert
            Assert.True(!repository.Contains(oldDeviceId));
            Assert.True(repository.Contains(device.Id));

            Assert.True(!result.ContainsKey(oldDeviceId));
            Assert.True(result.ContainsKey(device.Id));

            foreach (var expectedTopic in expectedAddedTopics)
            {
                _messageHubMock.Verify(x => x.Publish(It.Is <ConfigSubscriptionChangeEvent>(changeEvent => changeEvent.AddedSubscriptions.Contains(expectedTopic))), Times.Exactly(1));
            }

            foreach (var expectedTopic in expectedDeletedTopics)
            {
                _messageHubMock.Verify(x => x.Publish(It.Is <ConfigSubscriptionChangeEvent>(changeEvent => changeEvent.DeletedSubscriptions.Contains(expectedTopic))), Times.Exactly(1));
            }
        }