|
| 1 | +using System; |
| 2 | +using System.Text; |
| 3 | +using System.Collections.Generic; |
| 4 | +using System.Linq; |
| 5 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 6 | +using Moq; |
| 7 | +using JSIStudios.SimpleRESTServices.Client; |
| 8 | +using net.openstack; |
| 9 | +using net.openstack.Core; |
| 10 | +using net.openstack.Core.Domain; |
| 11 | +using net.openstack.Core.Exceptions; |
| 12 | +using net.openstack.Providers.Rackspace; |
| 13 | +using net.openstack.Providers.Rackspace.Objects.Response; |
| 14 | + |
| 15 | +namespace OpenStackNet.Testing.Unit.Providers.Rackspace |
| 16 | +{ |
| 17 | + [TestClass] |
| 18 | + public class ObjectProviderValidatorTests |
| 19 | + { |
| 20 | + [TestMethod] |
| 21 | + public void Should_Pass_Validation_For_Container_Name() |
| 22 | + { |
| 23 | + const string containerName = "DarkKnight"; |
| 24 | + var validatorMock = new Mock<IObjectStoreValidator>(); |
| 25 | + |
| 26 | + validatorMock.Setup(v => v.ValidateContainerName(containerName)); |
| 27 | + |
| 28 | + var objectStoreValidator = new ObjectStoreValidator(); |
| 29 | + objectStoreValidator.ValidateContainerName(containerName); |
| 30 | + |
| 31 | + } |
| 32 | + |
| 33 | + //[ExpectedException(typeof(ArgumentNullException),"ERROR: Container Name cannot be Null.")] |
| 34 | + [TestMethod] |
| 35 | + public void Should_Throw_Exception_When_Passing_Empty_Container_Name() |
| 36 | + { |
| 37 | + const string containerName = ""; |
| 38 | + var validatorMock = new Mock<IObjectStoreValidator>(); |
| 39 | + |
| 40 | + validatorMock.Setup(v => v.ValidateContainerName(containerName)); |
| 41 | + |
| 42 | + try |
| 43 | + { |
| 44 | + var objectStoreValidator = new ObjectStoreValidator(); |
| 45 | + objectStoreValidator.ValidateContainerName(containerName); |
| 46 | + Assert.Fail("Expected exception was not thrown."); |
| 47 | + } |
| 48 | + catch (Exception ex) |
| 49 | + { |
| 50 | + |
| 51 | + Assert.AreEqual("ERROR: Container Name cannot be Null.\r\nParameter name: ContainerName", ex.Message); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + [TestMethod] |
| 56 | + public void Should_Throw_Exception_When_Passing_Null_Container_Name() |
| 57 | + { |
| 58 | + const string containerName = null; |
| 59 | + var validatorMock = new Mock<IObjectStoreValidator>(); |
| 60 | + |
| 61 | + validatorMock.Setup(v => v.ValidateContainerName(containerName)); |
| 62 | + |
| 63 | + try |
| 64 | + { |
| 65 | + var objectStoreValidator = new ObjectStoreValidator(); |
| 66 | + objectStoreValidator.ValidateContainerName(containerName); |
| 67 | + Assert.Fail("Expected exception was not thrown."); |
| 68 | + } |
| 69 | + catch (Exception ex) |
| 70 | + { |
| 71 | + |
| 72 | + Assert.AreEqual("ERROR: Container Name cannot be Null.\r\nParameter name: ContainerName", ex.Message); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + [TestMethod] |
| 77 | + public void Should_Throw_Exception_When_Passing_256_Characters_In_Container_Name() |
| 78 | + { |
| 79 | + string containerName = "AaAaAaAaAa"; |
| 80 | + |
| 81 | + while (containerName.Length <= 256) |
| 82 | + { |
| 83 | + containerName += containerName; |
| 84 | + } |
| 85 | + var validatorMock = new Mock<IObjectStoreValidator>(); |
| 86 | + |
| 87 | + validatorMock.Setup(v => v.ValidateContainerName(containerName)); |
| 88 | + |
| 89 | + try |
| 90 | + { |
| 91 | + var objectStoreValidator = new ObjectStoreValidator(); |
| 92 | + objectStoreValidator.ValidateContainerName(containerName); |
| 93 | + Assert.Fail("Expected exception was not thrown."); |
| 94 | + } |
| 95 | + catch (ContainerNameException ex) |
| 96 | + { |
| 97 | + |
| 98 | + Assert.AreEqual(string.Format("ERROR: encoded URL Length greater than 256 char's. Container Name:[{0}]",containerName), ex.Message); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + [TestMethod] |
| 103 | + public void Should_Throw_Exception_When_Passing_Forwar_Slash_In_Container_Name() |
| 104 | + { |
| 105 | + string containerName = "/"; |
| 106 | + |
| 107 | + var validatorMock = new Mock<IObjectStoreValidator>(); |
| 108 | + |
| 109 | + validatorMock.Setup(v => v.ValidateContainerName(containerName)); |
| 110 | + |
| 111 | + try |
| 112 | + { |
| 113 | + var objectStoreValidator = new ObjectStoreValidator(); |
| 114 | + objectStoreValidator.ValidateContainerName(containerName); |
| 115 | + Assert.Fail("Expected exception was not thrown."); |
| 116 | + } |
| 117 | + catch (ContainerNameException ex) |
| 118 | + { |
| 119 | + |
| 120 | + Assert.AreEqual(string.Format("ERROR: Container Name contains a /. Container Name:[{0}]", containerName), ex.Message); |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + |
| 125 | + } |
| 126 | +} |
0 commit comments