ResXDataNodeByteArrayTests.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // ResXDataNodeByteArrayTests.cs : Tests how ResXDataNode handles byte[]
  3. // type resources.
  4. //
  5. // Author:
  6. // Gary Barnett ([email protected])
  7. //
  8. // Copyright (C) Gary Barnett (2012)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. using System;
  29. using System.IO;
  30. using System.Resources;
  31. using System.Collections;
  32. using NUnit.Framework;
  33. using System.ComponentModel.Design;
  34. namespace MonoTests.System.Resources {
  35. [TestFixture]
  36. public class ResXDataNodeByteArrayTests : ResourcesTestHelper {
  37. [Test]
  38. public void GetValueITRSNotUsedWhenNodeReturnedFromReader ()
  39. {
  40. ResXDataNode originalNode, returnedNode;
  41. originalNode = GetNodeEmdeddedBytes1To10 ();
  42. returnedNode = GetNodeFromResXReader (originalNode);
  43. Assert.IsNotNull (returnedNode, "#A1");
  44. object val = returnedNode.GetValue (new ReturnIntITRS ());
  45. Assert.IsInstanceOfType (typeof (byte[]), val, "#A2");
  46. }
  47. [Test]
  48. public void GetValueITRSNotTouchedWhenNodeCreatedNew ()
  49. {
  50. ResXDataNode node;
  51. node = GetNodeEmdeddedBytes1To10 ();
  52. //would raise exception if param used
  53. Object obj = node.GetValue (new ExceptionalITRS ());
  54. Assert.IsInstanceOfType (typeof (byte[]), obj, "#A1");
  55. }
  56. [Test]
  57. public void GetValueTypeNameITRSIsUsedWithNodeFromReader ()
  58. {
  59. ResXDataNode originalNode, returnedNode;
  60. originalNode = GetNodeEmdeddedBytes1To10 ();
  61. returnedNode = GetNodeFromResXReader (originalNode);
  62. Assert.IsNotNull (returnedNode, "#A1");
  63. string returnedType = returnedNode.GetValueTypeName (new ReturnIntITRS ());
  64. Assert.AreEqual ((typeof (int)).AssemblyQualifiedName, returnedType, "#A2");
  65. }
  66. [Test]
  67. public void GetValueTypeNameITRSIsUsedAfterGetValueCalledWithNodeFromReader ()
  68. {
  69. ResXDataNode originalNode, returnedNode;
  70. originalNode = GetNodeEmdeddedBytes1To10 ();
  71. returnedNode = GetNodeFromResXReader (originalNode);
  72. Assert.IsNotNull (returnedNode, "#A1");
  73. object obj = returnedNode.GetValue ((ITypeResolutionService) null);
  74. string returnedType = returnedNode.GetValueTypeName (new ReturnIntITRS ());
  75. Assert.AreEqual ((typeof (int)).AssemblyQualifiedName, returnedType, "#A2");
  76. }
  77. [Test]
  78. public void GetValueTypeNameITRSNotUsedWhenNodeCreatedNew ()
  79. {
  80. ResXDataNode node;
  81. node = GetNodeEmdeddedBytes1To10 ();
  82. string returnedType = node.GetValueTypeName (new ReturnIntITRS ());
  83. Assert.AreEqual ((typeof (byte[])).AssemblyQualifiedName, returnedType, "#A1");
  84. }
  85. }
  86. }