OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 namespace NativeClientVSAddIn |
| 6 { |
| 7 using System; |
| 8 |
| 9 /// <summary> |
| 10 /// This class fakes the mechanism for reading and writing properties on prope
rty pages. |
| 11 /// </summary> |
| 12 public class MockPropertyManager : PropertyManager |
| 13 { |
| 14 /// <summary> |
| 15 /// Relays property get calls to the provided delegate. |
| 16 /// </summary> |
| 17 private PropertyGetter getter_; |
| 18 |
| 19 /// <summary> |
| 20 /// Relays property set calls to the provided delegate. |
| 21 /// </summary> |
| 22 private PropertySetter setter_; |
| 23 |
| 24 /// <summary> |
| 25 /// Constructs the property manager. |
| 26 /// </summary> |
| 27 /// <param name="platformType">The platform type to represent.</param> |
| 28 /// <param name="getter">Receives property get requests and returns mock val
ues.</param> |
| 29 /// <param name="setter">Receives property set requests and checks them.</pa
ram> |
| 30 public MockPropertyManager( |
| 31 ProjectPlatformType platformType, PropertyGetter getter, PropertySetter
setter) |
| 32 { |
| 33 this.ProjectPlatform = platformType; |
| 34 getter_ = getter; |
| 35 setter_ = setter; |
| 36 } |
| 37 |
| 38 /// <summary> |
| 39 /// Can be used to capture the property requests and return whatever value i
s desired. |
| 40 /// If this returns null then the test will throw an error that the property
was unexpected. |
| 41 /// </summary> |
| 42 /// <param name="page">Property page name.</param> |
| 43 /// <param name="name">Property name.</param> |
| 44 /// <returns>Value to return. Should return null if property was unexpected.
</returns> |
| 45 public delegate string PropertyGetter(string page, string name); |
| 46 |
| 47 /// <summary> |
| 48 /// Can be used to capture the property requests and set whatever value is d
esired or do checks. |
| 49 /// If this returns false then the test will throw an error that the propert
y was unexpected. |
| 50 /// </summary> |
| 51 /// <param name="page">Property page name.</param> |
| 52 /// <param name="name">Property name.</param> |
| 53 /// <param name="value">Value to set.</param> |
| 54 /// <returns>True if the value was expected, false if unexpected (error).</r
eturns> |
| 55 public delegate bool PropertySetter(string page, string name, string value); |
| 56 |
| 57 /// <summary> |
| 58 /// The full path to the output assembly. |
| 59 /// </summary> |
| 60 public override string PluginAssembly |
| 61 { |
| 62 get { return getter_("Property", "PluginAssembly"); } |
| 63 protected set { setter_("Property", "PluginAssembly", value); } |
| 64 } |
| 65 |
| 66 /// <summary> |
| 67 /// The main project directory. |
| 68 /// </summary> |
| 69 public override string ProjectDirectory |
| 70 { |
| 71 get { return getter_("Property", "ProjectDirectory"); } |
| 72 protected set { setter_("Property", "ProjectDirectory", value); } |
| 73 } |
| 74 |
| 75 /// <summary> |
| 76 /// The directory where the output assembly is placed. |
| 77 /// </summary> |
| 78 public override string OutputDirectory |
| 79 { |
| 80 get { return getter_("Property", "OutputDirectory"); } |
| 81 protected set { setter_("Property", "OutputDirectory", value); } |
| 82 } |
| 83 |
| 84 /// <summary> |
| 85 /// Reads any generic property from the current target properties. |
| 86 /// </summary> |
| 87 /// <param name="page">Name of the page where the property is located.</para
m> |
| 88 /// <param name="name">Name of the property.</param> |
| 89 /// <returns>Mock value of the property as returned by the getter_.</returns
> |
| 90 public override string GetProperty(string page, string name) |
| 91 { |
| 92 string value = getter_(page, name); |
| 93 if (value == null) |
| 94 { |
| 95 throw new Exception(string.Format( |
| 96 "Property request not expected by test! Page: {0}, Prop: {1}", page,
name)); |
| 97 } |
| 98 |
| 99 return value; |
| 100 } |
| 101 |
| 102 /// <summary> |
| 103 /// Sets any generic property to the current target properties. |
| 104 /// </summary> |
| 105 /// <param name="page">Page where property is located.</param> |
| 106 /// <param name="name">Name of the property.</param> |
| 107 /// <param name="value">Unevaluated string value to set.</param> |
| 108 public override void SetProperty(string page, string name, string value) |
| 109 { |
| 110 if (!setter_(page, name, value)) |
| 111 { |
| 112 throw new Exception(string.Format( |
| 113 "Property set request was not expected by test! Page {0}, Prop: {1}"
, page, name)); |
| 114 } |
| 115 } |
| 116 } |
| 117 } |
OLD | NEW |