private void AssertControls(DeviceConfiguration deviceConfiguration, params string[] names)
 {
     deviceConfiguration.Controls.Select(c => c.Name).ToArray().ShouldBeEquivalentTo(names);
 }
 public static void TellClientPort(this IActorContext context, DeviceConfiguration message) => context.GetClientPort().Tell(message);
 private static void AssertDevice(
     DeviceConfiguration deviceConfiguration, CreatedDevice device,
     string expectedName, string[] expectedControls,
     string[] expectedSimpleActions = null, string[] expectedSlidingActions = null)
 {
     if (expectedSimpleActions == null)
         expectedSimpleActions = DefaultSimpleActions;
     if (expectedSlidingActions == null)
         expectedSlidingActions = DefaultSlidingActions;
     if (expectedControls.Length == 0)
     {
         expectedSimpleActions = new string[0];
         expectedSlidingActions = new string[0];
     }
     device.Id.Should().NotBe(Guid.Empty);
     device.Name.Should().Be(expectedName);
     device.SimpleActions.Should().BeEquivalentTo(expectedSimpleActions, nameof(device.SimpleActions));
     device.SlidingActions.Should().BeEquivalentTo(expectedSlidingActions, nameof(device.SlidingActions));
     device.ControlIds.Length.Should().Be(expectedControls.Length, nameof(device.ControlIds));
     for (var i = 0; i < expectedControls.Length; i++)
     {
         string name = deviceConfiguration.Controls.First(c => c.Id == device.ControlIds[i]).Name;
         name.Should().Be(expectedControls[i]);
     }
 }
 private static void AssertJustCreatedDevice(
     DeviceConfiguration deviceConfiguration, CreatedDevice device,
     string expectedName,
     string[] expectedSimpleActions = null, string[] expectedSlidingActions = null)
 {
     AssertDevice(deviceConfiguration, device, expectedName, new[] { expectedName }, expectedSimpleActions, expectedSlidingActions);
 }
 public void WhenDeviceStoreIsRestartedAfterDeviceHasBeenUpdated_ThenTheDeviceConfigurationIsStillThere()
 {
     var message = new UpdateDevice(LastConfiguration.Devices[0].Id, "bedroom", new Guid[0]);
     SingleClientProxy.Tell(message);
     LastConfiguration = ExpectMsg<DeviceConfiguration>();
     RestartDeviceStore();
     AssertDeviceConfigurationThroughAddDevice(2, (m, d) =>
     {
         AssertDeviceIdFromLastConfiguration(d, 0);
         AssertDeviceIdFromLastConfiguration(d, 1);
         AssertDevice(m, d[0], "bedroom", new string[0]);
         AssertJustCreatedDevice(m, d[1], "dining room");
     });
 }
 public void WhenDeviceStoreIsRestartedAfterDeviceHasBeenRemoved_ThenTheDeviceConfigurationIsStillThere()
 {
     SingleClientProxy.Tell(new RemoveDevice(LastConfiguration.Devices[0].Id));
     LastConfiguration = ExpectMsg<DeviceConfiguration>();
     RestartDeviceStore();
     AssertDeviceConfigurationThroughAddDevice(1, (m, d) =>
     {
         AssertDeviceIdFromLastConfiguration(d, 0);
         AssertJustCreatedDevice(m, d[0], "dining room");
     });
 }
 public void WhenDeviceStoreIsRestartedAfterDeviceHasBeenCreated_ThenTheDeviceConfigurationIsStillThere()
 {
     SingleClientProxy.Tell(new CreateDevice("bedroom", new Guid[0]));
     LastConfiguration = ExpectMsg<DeviceConfiguration>();
     RestartDeviceStore();
     AssertDeviceConfigurationThroughAddDevice(3, (m, d) =>
     {
         AssertDeviceIdFromLastConfiguration(d, 0);
         AssertDeviceIdFromLastConfiguration(d, 1);
         AssertDeviceIdFromLastConfiguration(d, 2);
         AssertJustCreatedDevice(m, d[0], "kitchen");
         AssertJustCreatedDevice(m, d[1], "dining room");
         AssertDevice(m, d[2], "bedroom", new string[0]);
     });
 }
 public void WhenDeviceStoreIsRestartedAfterControlUpdateWhichUpdates_ThenTheDeviceConfigurationIsStillThere()
 {
     var message = CreateControls("kitchen", "living room");
     GetOrCreatePluginProxy("fake").Tell(message);
     LastConfiguration = ExpectMsg<DeviceConfiguration>();
     RestartDeviceStore();
     AssertDeviceConfigurationThroughAddDevice(2, (m, d) =>
     {
         AssertDeviceIdFromLastConfiguration(d, 0);
         AssertDeviceIdFromLastConfiguration(d, 1);
         AssertJustCreatedDevice(m, d[0], "kitchen");
         AssertDevice(m, d[1], "dining room", new[] { "living room" });
     });
 }
Example #9
0
 private static void PrintConfiguration(DeviceConfiguration message)
 {
     WriteLine("Received device configuration");
     WriteLine("Devices:");
     foreach (CreatedDevice device in message.Devices)
     {
         WriteLine($" - Id: {device.Id}, Name: {device.Name}, Simple: [{string.Join(", ", device.SimpleActions)}], Sliding: [{string.Join(", ", device.SlidingActions)}], Controls: [{string.Join(", ", device.ControlIds)}]");
     }
     WriteLine("Controls:");
     foreach (var control in message.Controls)
     {
         WriteLine($" - Id: {control.Id}, Name: {control.Name}");
     }
     WriteLine();
     Write("Enter command: ");
 }