Utils.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Web.DynamicData;
  6. using System.Web.DynamicData.ModelProviders;
  7. namespace MonoTests.Common
  8. {
  9. static class Utils
  10. {
  11. public static MetaModel GetModel<ContextType> ()
  12. {
  13. // This is really, really dumb but we need that since if the type has already
  14. // been registered by another test, or tests are re-ran without nunit having
  15. // reloaded the dll we'll get a duplicate entry exception.
  16. MetaModel m;
  17. try {
  18. m = MetaModel.GetModel (typeof (ContextType));
  19. } catch (InvalidOperationException) {
  20. m = new MetaModel ();
  21. m.RegisterContext (typeof (ContextType));
  22. } finally {
  23. MetaModel.ResetRegistrationException ();
  24. }
  25. return m;
  26. }
  27. public static void RegisterContext (DataModelProvider model)
  28. {
  29. RegisterContext (model, null);
  30. }
  31. public static void RegisterContext (DataModelProvider model, ContextConfiguration config)
  32. {
  33. // Just in case no model has been created yet
  34. MetaModel m = new MetaModel ();
  35. // And get the default model instead, whatever it is
  36. m = MetaModel.Default;
  37. try {
  38. m.RegisterContext (model, config);
  39. } catch (InvalidOperationException) {
  40. // ignore
  41. }
  42. }
  43. public static string BuildActionName (MetaTable table, string action)
  44. {
  45. return "/" + table.Name + "/" + action + ".aspx";
  46. }
  47. public static string BuildActionName (MetaTable table, string action, string query)
  48. {
  49. string ret = "/" + table.Name + "/" + action + ".aspx";
  50. if (!String.IsNullOrEmpty (query))
  51. ret += "?" + query;
  52. return ret;
  53. }
  54. }
  55. }