C# 视窗电话的测试加速度计实现 问题
我的应用程序通过类使用加速计数据 现在我想编写单元或代码DUI测试,出于这个原因,我需要一个特殊的C# 视窗电话的测试加速度计实现 问题,c#,windows-phone-8,decompiling,C#,Windows Phone 8,Decompiling,我的应用程序通过类使用加速计数据 现在我想编写单元或代码DUI测试,出于这个原因,我需要一个特殊的加速计测试实现来控制返回的数据 理论上,我有3种选择: 创建加速计的子类-不可能,因为加速计是密封的类 通过在运行时使用反射替换加速计的实现,这不是IMHO的最佳选择 创建SensorBase的子类 //类型:Microsoft.Devices.Sensors.SensorBase`1 //程序集:Microsoft.Devices.Sensors,版本=8.0.0.0,区域性=中性,PublicK
加速计测试实现来控制返回的数据
理论上,我有3种选择:
创建加速计
的子类-不可能,因为加速计
是密封的
类
通过在运行时使用反射替换加速计的实现
,这不是IMHO的最佳选择
创建SensorBase的子类
//类型:Microsoft.Devices.Sensors.SensorBase`1
//程序集:Microsoft.Devices.Sensors,版本=8.0.0.0,区域性=中性,PublicKeyToken=24eec0d8c86cda1e
//MVID:81ED89AA-6B11-4B39-BAFA-38D59CBB1E3B
//程序集位置:C:\Program Files(x86)\Reference Assembly\Microsoft\Framework\WindowsPhone\v8.0\Microsoft.Devices.Sensors.dll
使用制度;
使用系统安全;
名称空间Microsoft.Devices.Sensors
{
///
///所有Windows Phone传感器类的基类。
///
///传感器返回的读数类型。
公共抽象类SensorBase:IDisposable其中TSensorReading:ISensorReading
{
///
///获取实现的对象,该对象包含传感器的当前值。此对象将是以下类型之一,具体取决于引用的传感器:、、。
///
///
///
///实现包含传感器当前值的对象。
///
公共当前值{get;}
///
///获取或设置事件之间的首选时间。
///
///
///
///类型:。CurrentValueChanged事件之间的首选时间。
///
公共时间跨度TimeBetweenUpdate{get;set;}
///
///获取传感器数据的有效性。
///
///
///
///类型:。如果传感器数据有效,则为true;否则为false。
///
公共bool IsDataValid{get;}
///
///当传感器收到新数据时发生。
///
公共事件处理程序CurrentValueChanged;
静态传感器底座();
内部传感器底座();
///
///允许对象在垃圾回收回收对象之前尝试释放资源并执行其他清理操作。
///
[安全性安全关键]
~SensorBase();
///
///释放传感器使用的托管和非托管资源。
///
[安全性安全关键]
公开无效处置();
///
///开始从传感器采集数据。
///
公共虚拟void Start();
///
///停止从传感器采集数据。
///
公共虚拟无效停止();
}
}
您找到了构造函数:
internal SensorBase();
此构造函数防止SensorBase
具有默认的公共构造函数,并且不能从其程序集外部对此类进行子类化
测试它将是复杂的。您可以重新设计应用程序,并为加速计使用包装器/适配器
仅用于测试,或者您可以检查是否有可能在Windows Phone上安装
// Type: Microsoft.Devices.Sensors.Accelerometer
// Assembly: Microsoft.Devices.Sensors, Version=8.0.0.0, Culture=neutral, PublicKeyToken=24eec0d8c86cda1e
// MVID: 81ED89AA-6B11-4B39-BAFA-38D59CBB1E3B
// Assembly location: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\WindowsPhone\v8.0\Microsoft.Devices.Sensors.dll
using System;
namespace Microsoft.Devices.Sensors
{
/// <summary>
/// Provides Windows Phone applications access to the device’s accelerometer sensor.
/// </summary>
public sealed class Accelerometer : SensorBase<AccelerometerReading>
{
/// <summary>
/// Gets or sets whether the device on which the application is running supports the accelerometer sensor.
/// </summary>
///
/// <returns>
/// true if the device on which the application is running supports the accelerometer sensor; otherwise, false.
/// </returns>
public static bool IsSupported { get; internal set; }
/// <summary>
/// Gets the current state of the accelerometer. The value is a member of the <see cref="T:Microsoft.Devices.Sensors.SensorState"/> enumeration.
/// </summary>
///
/// <returns>
/// Type: <see cref="T:Microsoft.Devices.Sensors.SensorState"/>.
/// </returns>
public SensorState State { get; private set; }
/// <summary>
/// Occurs when new data arrives from the accelerometer. This method is deprecated in the current release. Applications should use the <see cref="E:Microsoft.Devices.Sensors.SensorBase`1.CurrentValueChanged"/> event of the <see cref="T:Microsoft.Devices.Sensors.SensorBase`1"/> class instead.
/// </summary>
[Obsolete("use CurrentValueChanged")]
public event EventHandler<AccelerometerReadingEventArgs> ReadingChanged;
static Accelerometer();
/// <summary>
/// Releases the managed and unmanaged resources used by the <see cref="T:Microsoft.Devices.Sensors.Accelerometer"/>.
/// </summary>
public new void Dispose();
/// <summary>
/// Starts data acquisition from the accelerometer.
/// </summary>
public new void Start();
/// <summary>
/// Stops data acquisition from the accelerometer.
/// </summary>
public new void Stop();
}
}
// Type: Microsoft.Devices.Sensors.SensorBase`1
// Assembly: Microsoft.Devices.Sensors, Version=8.0.0.0, Culture=neutral, PublicKeyToken=24eec0d8c86cda1e
// MVID: 81ED89AA-6B11-4B39-BAFA-38D59CBB1E3B
// Assembly location: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\WindowsPhone\v8.0\Microsoft.Devices.Sensors.dll
using System;
using System.Security;
namespace Microsoft.Devices.Sensors
{
/// <summary>
/// The base class for all Windows Phone sensor classes.
/// </summary>
/// <typeparam name="TSensorReading">The type of reading returned by the sensor.</typeparam>
public abstract class SensorBase<TSensorReading> : IDisposable where TSensorReading : ISensorReading
{
/// <summary>
/// Gets an object that implements <see cref="T:Microsoft.Devices.Sensors.ISensorReading"/> that contains the current value of the sensor. This object will be one of the following types, depending on which sensor is being referenced: <see cref="T:Microsoft.Devices.Sensors.AccelerometerReading"/>, <see cref="T:Microsoft.Devices.Sensors.CompassReading"/>, <see cref="T:Microsoft.Devices.Sensors.GyroscopeReading"/>, <see cref="T:Microsoft.Devices.Sensors.MotionReading"/>.
/// </summary>
///
/// <returns>
/// An object that implements <see cref="T:Microsoft.Devices.Sensors.ISensorReading"/> that contains the current value of the sensor.
/// </returns>
public TSensorReading CurrentValue { get; }
/// <summary>
/// Gets or sets the preferred time between <see cref="E:Microsoft.Devices.Sensors.SensorBase`1.CurrentValueChanged"/> events.
/// </summary>
///
/// <returns>
/// Type: <see cref="T:System.TimeSpan"/>. The preferred time between CurrentValueChanged events.
/// </returns>
public TimeSpan TimeBetweenUpdates { get; set; }
/// <summary>
/// Gets the validity of the sensor’s data.
/// </summary>
///
/// <returns>
/// Type: <see cref="T:System.Boolean"/>. true if the sensor’s data is valid; otherwise, false.
/// </returns>
public bool IsDataValid { get; }
/// <summary>
/// Occurs when new data arrives from the sensor.
/// </summary>
public event EventHandler<SensorReadingEventArgs<TSensorReading>> CurrentValueChanged;
static SensorBase();
internal SensorBase();
/// <summary>
/// Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection.
/// </summary>
[SecuritySafeCritical]
~SensorBase();
/// <summary>
/// Releases the managed and unmanaged resources used by the sensor.
/// </summary>
[SecuritySafeCritical]
public void Dispose();
/// <summary>
/// Starts acquisition of data from the sensor.
/// </summary>
public virtual void Start();
/// <summary>
/// Stops acquisition of data from the sensor.
/// </summary>
public virtual void Stop();
}
}
internal SensorBase();