public void DefaultDeviceChangedEvent_DefaultDevicePropertyShouldBeChanged() { var device = OutputDeviceModelTests.GetDeviceMock("222", "headphones", this.deviceStateNotifMock.Object); deviceStateNotifMock.Raise(m => m.ActiveDeviceAdded += null, device); deviceStateNotifMock.Raise(m => m.DefaultDeviceChanged += null, device.Id); Assert.Equal(this.model.DefaultDevice, device); }
public void ActiveDeviceAddedEvent_NewDeviceShouldBeAdded() { var devicesCount = this.model.ActiveDevices.Count; var newDevice = OutputDeviceModelTests.GetDeviceMock("222", "headphones", this.deviceStateNotifMock.Object); this.deviceStateNotifMock.Raise(m => m.ActiveDeviceAdded += null, newDevice); Assert.Equal(devicesCount + 1, this.model.ActiveDevices.Count); Assert.Contains(newDevice, this.model.ActiveDevices); }
public DeviceProviderTests() { var iDeviceEnumMock = new Mock <IDeviceEnumerator>(); deviceStateNotifMock = new Mock <IDeviceStateNotificationHandler>(); defaultDevice = OutputDeviceModelTests.GetDeviceMock("111", "speakers", this.deviceStateNotifMock.Object); var device = OutputDeviceModelTests.GetDeviceMock("123", "device", this.deviceStateNotifMock.Object); var devices = new List <OutputDeviceModel> { defaultDevice, device }; iDeviceEnumMock.Setup(m => m.GetCurrentActiveDevices(deviceStateNotifMock.Object)).Returns(devices); iDeviceEnumMock.Setup(m => m.GetDefaultDeviceId()).Returns(defaultDevice.Id); model = GetDeviceProviderMock(iDeviceEnumMock.Object, deviceStateNotifMock.Object); }
public void FirstDeviceAdded_NoOutputDeviceShouldBeFalse() { //remove all active devices var activeDevicesCount = this.model.ActiveDevices.Count; for (int i = activeDevicesCount - 1; i >= 0; i--) { deviceStateNotifMock.Raise(m => m.DeviceDisabled += null, this.model.ActiveDevices[i].Id); } Assert.True(this.model.NoOutputDevices); var newDevice = OutputDeviceModelTests.GetDeviceMock("222", "newDevice", this.deviceStateNotifMock.Object); deviceStateNotifMock.Raise(m => m.ActiveDeviceAdded += null, newDevice); Assert.False(this.model.NoOutputDevices); Assert.Contains(newDevice, this.model.ActiveDevices); Assert.Equal(newDevice, this.model.DefaultDevice); }
public static void DefaultDeviceShouldNotBeNull_WhenDeviceEnumeratorReturnsInvalidDefaultDeviceId() { var IDeviceEnumMock = new Mock <IDeviceEnumerator>(); var deviceStateNotificationMock = new Mock <IDeviceStateNotificationHandler>(); var device = OutputDeviceModelTests.GetDeviceMock("111", "speakers", deviceStateNotificationMock.Object); var devices = new List <OutputDeviceModel> { device }; IDeviceEnumMock.Setup(m => m.GetCurrentActiveDevices(deviceStateNotificationMock.Object)).Returns(devices); IDeviceEnumMock.Setup(m => m.GetDefaultDeviceId()).Returns(String.Empty); var model = (DeviceProvider)Activator.CreateInstance(typeof(DeviceProvider), BindingFlags.NonPublic | BindingFlags.Instance, null, new object[] { IDeviceEnumMock.Object, deviceStateNotificationMock.Object }, CultureInfo.InvariantCulture, null); Assert.NotNull(model.DefaultDevice); }
public DeviceProviderViewModelTests() { this.deviceProviderMock = new Mock <IDeviceProvider>(); var deviceStateNotif = new Mock <IDeviceStateNotificationHandler>(); var device1 = OutputDeviceModelTests.GetDeviceMock("1", "speakers", deviceStateNotif.Object); var device2 = OutputDeviceModelTests.GetDeviceMock("2", "headphones", deviceStateNotif.Object); var activeDevices = new ObservableCollection <OutputDeviceModel> { device1, device2 }; this.deviceProviderMock.Setup(m => m.ActiveDevices).Returns(activeDevices); this.deviceProviderMock.Setup(m => m.DefaultDevice).Returns(device1); this.deviceProviderMock.Setup(m => m.NoOutputDevices).Returns(false); FieldInfo instance = typeof(DeviceProvider).GetField("instance", BindingFlags.NonPublic | BindingFlags.Static); instance.SetValue(null, deviceProviderMock.Object); this.model = new DeviceProviderViewModel(); }