public void VerifyDeviceInfoWhenManagmentClassNotAvailable() { var deviceInformation = new DeviceInformationHelper(); var factory = new MockManagmentClassFactory(); deviceInformation.SetManagmentClassFactory(factory); var device = Task.Run(() => deviceInformation.GetDeviceInformationAsync()).Result; }
public void SetCountryCode() { // Mock event handler. var mockInformationInvalidated = new Mock <EventHandler>(); // Initialize device information helper. DeviceInformationHelper.InformationInvalidated += mockInformationInvalidated.Object; var deviceInformationHelper = new DeviceInformationHelper(); var device = deviceInformationHelper.GetDeviceInformationAsync().RunNotAsync(); Assert.IsNull(device.CarrierCountry); // Valid country code. var validCountryCode = "US"; AppCenter.SetCountryCode(validCountryCode); device = deviceInformationHelper.GetDeviceInformationAsync().RunNotAsync(); Assert.AreEqual(device.CarrierCountry, validCountryCode); mockInformationInvalidated.Verify(_ => _(It.IsAny <object>(), It.IsAny <EventArgs>()), Times.Once); // Invalid country code. var invalidCountryCode = "US1"; AppCenter.SetCountryCode(invalidCountryCode); device = deviceInformationHelper.GetDeviceInformationAsync().RunNotAsync(); // The code has not been updated and the event has not been called. Assert.AreEqual(device.CarrierCountry, validCountryCode); mockInformationInvalidated.Verify(_ => _(It.IsAny <object>(), It.IsAny <EventArgs>()), Times.Once); // Reset country code. AppCenter.SetCountryCode(null); device = deviceInformationHelper.GetDeviceInformationAsync().RunNotAsync(); Assert.IsNull(device.CarrierCountry); mockInformationInvalidated.Verify(_ => _(It.IsAny <object>(), It.IsAny <EventArgs>()), Times.Exactly(2)); // Clean. DeviceInformationHelper.InformationInvalidated -= mockInformationInvalidated.Object; }
public void SetWrapperSdk() { string wrapperName = $"expectedName {Guid.NewGuid()}"; string wrapperVersion = $"expectedVersion {Guid.NewGuid()}"; string releaseLabel = $"expectedLabel {Guid.NewGuid()}"; string updateDevKey = $"expectedUpdateDevKey {Guid.NewGuid()}"; string updatePackageHash = $"expectedHash {Guid.NewGuid()}"; string runtimeVersion = $"expectedRuntimeVersion {Guid.NewGuid()}"; WrapperSdk wrapperSdk = new WrapperSdk(wrapperName, wrapperVersion, runtimeVersion, releaseLabel, updateDevKey, updatePackageHash); DeviceInformationHelper.SetWrapperSdk(wrapperSdk); var deviceInformationHelper = new DeviceInformationHelper(); var device = deviceInformationHelper.GetDeviceInformationAsync().RunNotAsync(); Assert.AreEqual(wrapperName, device.WrapperSdkName); Assert.AreEqual(wrapperVersion, device.WrapperSdkVersion); Assert.AreEqual(releaseLabel, device.LiveUpdateReleaseLabel); Assert.AreEqual(updateDevKey, device.LiveUpdateDeploymentKey); Assert.AreEqual(updatePackageHash, device.LiveUpdatePackageHash); Assert.AreEqual(runtimeVersion, device.WrapperRuntimeVersion); }