|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Text; |
| 4 | +using ASPNetImage; |
| 5 | +using NUnit.Framework; |
| 6 | + |
| 7 | +namespace UnitTests |
| 8 | +{ |
| 9 | + [TestFixture] |
| 10 | + public class ASPNetImageTest |
| 11 | + { |
| 12 | + [Test] |
| 13 | + public void TestVersion() |
| 14 | + { |
| 15 | + ASPNetImage.NetImage thisImage = new NetImage(); |
| 16 | + |
| 17 | + Assert.That(thisImage.Version == "2.3.1.0 (ASPNetImage v0.2)"); |
| 18 | + } |
| 19 | + |
| 20 | + [Test] |
| 21 | + public void TestRegisteredTo() |
| 22 | + { |
| 23 | + ASPNetImage.NetImage thisImage = new NetImage(); |
| 24 | + thisImage.RegisteredTo = "Registered To Test"; |
| 25 | + |
| 26 | + Assert.That(thisImage.RegisteredTo == "Registered To Test"); |
| 27 | + } |
| 28 | + |
| 29 | + [Test] |
| 30 | + public void TestExpirationDate() |
| 31 | + { |
| 32 | + ASPNetImage.NetImage thisImage = new NetImage(); |
| 33 | + |
| 34 | + Assert.That(Convert.ToDateTime(thisImage.Expires) > DateTime.Now); |
| 35 | + } |
| 36 | + |
| 37 | + [Test] |
| 38 | + public void TestGetImageSize() |
| 39 | + { |
| 40 | + ASPNetImage.NetImage thisImage = new NetImage(); |
| 41 | + thisImage.LoadImage("../../Resources/1024x768.png"); |
| 42 | + |
| 43 | + int width, height; |
| 44 | + thisImage.GetImageSize(out width, out height); |
| 45 | + |
| 46 | + Assert.That(width == 1024 && height == 768, "Image dimensions do not match"); |
| 47 | + } |
| 48 | + |
| 49 | + [Test] |
| 50 | + public void TestAutoClear() |
| 51 | + { |
| 52 | + string outputFilePath = "../../Output/AutoClear.jpg"; |
| 53 | + |
| 54 | + ASPNetImage.NetImage thisImage = new NetImage(); |
| 55 | + thisImage.LoadImage("../../Resources/1024x768.png"); |
| 56 | + thisImage.AutoClear = true; |
| 57 | + thisImage.Filename = outputFilePath; |
| 58 | + thisImage.SaveImage(); |
| 59 | + |
| 60 | + try |
| 61 | + { |
| 62 | + thisImage.RotateImage(90); |
| 63 | + Assert.Fail("Image data not cleared"); |
| 64 | + } |
| 65 | + catch |
| 66 | + { |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + [Test] |
| 71 | + public void TestCrop() |
| 72 | + { |
| 73 | + string outputFilePath = "../../Output/Crop.jpg"; |
| 74 | + |
| 75 | + ASPNetImage.NetImage thisImage = new NetImage(); |
| 76 | + thisImage.LoadImage("../../Resources/1024x768.png"); |
| 77 | + thisImage.Filename = outputFilePath; |
| 78 | + thisImage.CropImage(10, 50, 800, 600); |
| 79 | + thisImage.SaveImage(); |
| 80 | + |
| 81 | + int width, height; |
| 82 | + thisImage.GetImageFileSize(outputFilePath, out width, out height); |
| 83 | + |
| 84 | + Assert.That(width == 800 && height == 600, "Image dimensions do not match"); |
| 85 | + } |
| 86 | + |
| 87 | + [Test] |
| 88 | + public void TestResizeSameAspectRatioWithConstraint() |
| 89 | + { |
| 90 | + string outputFilePath = "../../Output/Resize-Same_aspect_ratio-Constrained.jpg"; |
| 91 | + |
| 92 | + ASPNetImage.NetImage thisImage = new NetImage(); |
| 93 | + thisImage.LoadImage("../../Resources/1024x768.png"); |
| 94 | + thisImage.Filename = outputFilePath; |
| 95 | + thisImage.ConstrainResize = true; |
| 96 | + thisImage.Resize(800, 600); |
| 97 | + thisImage.SaveImage(); |
| 98 | + |
| 99 | + int width, height; |
| 100 | + thisImage.GetImageFileSize(outputFilePath, out width, out height); |
| 101 | + |
| 102 | + Assert.That(width == 800 && height == 600, "Image dimensions do not match"); |
| 103 | + } |
| 104 | + |
| 105 | + [Test] |
| 106 | + public void TestResizeLandscapeWithConstraint() |
| 107 | + { |
| 108 | + string outputFilePath = "../../Output/Resize-Variant_aspect_ratio_landscape-Constrained.jpg"; |
| 109 | + |
| 110 | + ASPNetImage.NetImage thisImage = new NetImage(); |
| 111 | + thisImage.LoadImage("../../Resources/1440x900.png"); |
| 112 | + thisImage.Filename = outputFilePath; |
| 113 | + thisImage.ConstrainResize = true; |
| 114 | + thisImage.Resize(800, 600); |
| 115 | + thisImage.SaveImage(); |
| 116 | + |
| 117 | + int width, height; |
| 118 | + thisImage.GetImageFileSize(outputFilePath, out width, out height); |
| 119 | + |
| 120 | + Assert.That(width == 800 && height == 600, "Image dimensions do not match"); |
| 121 | + } |
| 122 | + |
| 123 | + [Test] |
| 124 | + public void TestResizePortraitWithConstraint() |
| 125 | + { |
| 126 | + string outputFilePath = "../../Output/Resize-Variant_aspect_ratio_portrait-Constrained.jpg"; |
| 127 | + |
| 128 | + ASPNetImage.NetImage thisImage = new NetImage(); |
| 129 | + thisImage.LoadImage("../../Resources/900x1440.png"); |
| 130 | + thisImage.Filename = outputFilePath; |
| 131 | + thisImage.ConstrainResize = true; |
| 132 | + thisImage.Resize(800, 600); |
| 133 | + thisImage.SaveImage(); |
| 134 | + |
| 135 | + int width, height; |
| 136 | + thisImage.GetImageFileSize(outputFilePath, out width, out height); |
| 137 | + |
| 138 | + Assert.That(width == 800 && height == 600, "Image dimensions do not match"); |
| 139 | + } |
| 140 | + |
| 141 | + [Test] |
| 142 | + public void TestResizeLandscapeWithoutConstraint() |
| 143 | + { |
| 144 | + string outputFilePath = "../../Output/Resize-Variant_aspect_ratio_landscape-Unconstrained.jpg"; |
| 145 | + |
| 146 | + ASPNetImage.NetImage thisImage = new NetImage(); |
| 147 | + thisImage.LoadImage("../../Resources/1440x900.png"); |
| 148 | + thisImage.Filename = outputFilePath; |
| 149 | + thisImage.ConstrainResize = false; |
| 150 | + thisImage.Resize(800, 600); |
| 151 | + thisImage.SaveImage(); |
| 152 | + |
| 153 | + int width, height; |
| 154 | + thisImage.GetImageFileSize(outputFilePath, out width, out height); |
| 155 | + |
| 156 | + Assert.That(width == 800 && height == 600, "Image dimensions do not match"); |
| 157 | + } |
| 158 | + |
| 159 | + [Test] |
| 160 | + public void TestResizePortraitWithoutConstraint() |
| 161 | + { |
| 162 | + string outputFilePath = "../../Output/Resize-Variant_aspect_ratio_portrait-Unconstrained.jpg"; |
| 163 | + |
| 164 | + ASPNetImage.NetImage thisImage = new NetImage(); |
| 165 | + thisImage.LoadImage("../../Resources/900x1440.png"); |
| 166 | + thisImage.Filename = outputFilePath; |
| 167 | + thisImage.ConstrainResize = false; |
| 168 | + thisImage.Resize(800, 600); |
| 169 | + thisImage.SaveImage(); |
| 170 | + |
| 171 | + int width, height; |
| 172 | + thisImage.GetImageFileSize(outputFilePath, out width, out height); |
| 173 | + |
| 174 | + Assert.That(width == 800 && height == 600, "Image dimensions do not match"); |
| 175 | + } |
| 176 | + |
| 177 | + [Test] |
| 178 | + public void TestBrightenImage() |
| 179 | + { |
| 180 | + string outputFilePath = "../../Output/Brightness-Brighten_image.jpg"; |
| 181 | + |
| 182 | + ASPNetImage.NetImage thisImage = new NetImage(); |
| 183 | + thisImage.LoadImage("../../Resources/1024x768-black.png"); |
| 184 | + thisImage.Filename = outputFilePath; |
| 185 | + thisImage.BrightenImage(50); |
| 186 | + thisImage.SaveImage(); |
| 187 | + |
| 188 | + Assert.That(true == true); // TODO : Check RGB values |
| 189 | + } |
| 190 | + |
| 191 | + [Test] |
| 192 | + public void TestDarkenImage() |
| 193 | + { |
| 194 | + string outputFilePath = "../../Output/Brightness-Darken_image.jpg"; |
| 195 | + |
| 196 | + ASPNetImage.NetImage thisImage = new NetImage(); |
| 197 | + thisImage.LoadImage("../../Resources/1024x768-white.png"); |
| 198 | + thisImage.Filename = outputFilePath; |
| 199 | + thisImage.DarkenImage(50); |
| 200 | + thisImage.SaveImage(); |
| 201 | + |
| 202 | + Assert.That(true == true); // TODO : Check RGB values |
| 203 | + } |
| 204 | + |
| 205 | + [Test] |
| 206 | + public void TestRotate90Degrees() |
| 207 | + { |
| 208 | + string outputFilePath = "../../Output/Rotate-90_degrees.jpg"; |
| 209 | + |
| 210 | + ASPNetImage.NetImage thisImage = new NetImage(); |
| 211 | + thisImage.LoadImage("../../Resources/1024x768.png"); |
| 212 | + thisImage.Filename = outputFilePath; |
| 213 | + thisImage.RotateImage(90); |
| 214 | + thisImage.SaveImage(); |
| 215 | + |
| 216 | + int width, height; |
| 217 | + thisImage.GetImageFileSize(outputFilePath, out width, out height); |
| 218 | + |
| 219 | + Assert.That(width == 768 && height == 1024, "Image dimensions do not match"); |
| 220 | + } |
| 221 | + |
| 222 | + [Test] |
| 223 | + public void TestRotate90DegreesWithCrop() |
| 224 | + { |
| 225 | + string outputFilePath = "../../Output/Rotate-90_degrees_with_crop.jpg"; |
| 226 | + int originalWidth = 0; |
| 227 | + int originalHeight = 0; |
| 228 | + |
| 229 | + ASPNetImage.NetImage thisImage = new NetImage(); |
| 230 | + thisImage.LoadImage("../../Resources/1024x768.png"); |
| 231 | + thisImage.GetImageSize(out originalWidth, out originalHeight); |
| 232 | + thisImage.Filename = outputFilePath; |
| 233 | + thisImage.RotateImage(90); |
| 234 | + thisImage.ConstrainResize = true; |
| 235 | + thisImage.Resize(originalWidth, originalHeight); |
| 236 | + thisImage.SaveImage(); |
| 237 | + |
| 238 | + int width, height; |
| 239 | + thisImage.GetImageFileSize(outputFilePath, out width, out height); |
| 240 | + |
| 241 | + Assert.That(width == originalWidth && height == originalHeight, "Image dimensions do not match"); |
| 242 | + } |
| 243 | + |
| 244 | + [Test] |
| 245 | + public void TestRotate180Degrees() |
| 246 | + { |
| 247 | + string outputFilePath = "../../Output/Rotate-180_degrees.jpg"; |
| 248 | + |
| 249 | + ASPNetImage.NetImage thisImage = new NetImage(); |
| 250 | + thisImage.LoadImage("../../Resources/1024x768.png"); |
| 251 | + thisImage.Filename = outputFilePath; |
| 252 | + thisImage.RotateImage(180); |
| 253 | + thisImage.SaveImage(); |
| 254 | + |
| 255 | + int width, height; |
| 256 | + thisImage.GetImageFileSize(outputFilePath, out width, out height); |
| 257 | + |
| 258 | + Assert.That(width == 1024 && height == 768, "Image dimensions do not match"); |
| 259 | + } |
| 260 | + |
| 261 | + [Test] |
| 262 | + public void TestFlipHorizontal() |
| 263 | + { |
| 264 | + string outputFilePath = "../../Output/Flip-Horizontal.jpg"; |
| 265 | + |
| 266 | + ASPNetImage.NetImage thisImage = new NetImage(); |
| 267 | + thisImage.LoadImage("../../Resources/1024x768.png"); |
| 268 | + thisImage.Filename = outputFilePath; |
| 269 | + thisImage.FlipImage(NetImage.FlipDirections.Horizontal); |
| 270 | + thisImage.SaveImage(); |
| 271 | + |
| 272 | + int width, height; |
| 273 | + thisImage.GetImageFileSize(outputFilePath, out width, out height); |
| 274 | + |
| 275 | + Assert.That(width == 1024 && height == 768, "Image dimensions do not match"); |
| 276 | + } |
| 277 | + |
| 278 | + [Test] |
| 279 | + public void TestFlipVertical() |
| 280 | + { |
| 281 | + string outputFilePath = "../../Output/Flip-Vertical.jpg"; |
| 282 | + |
| 283 | + ASPNetImage.NetImage thisImage = new NetImage(); |
| 284 | + thisImage.LoadImage("../../Resources/1024x768.png"); |
| 285 | + thisImage.Filename = outputFilePath; |
| 286 | + thisImage.FlipImage(NetImage.FlipDirections.Vertical); |
| 287 | + thisImage.SaveImage(); |
| 288 | + |
| 289 | + int width, height; |
| 290 | + thisImage.GetImageFileSize(outputFilePath, out width, out height); |
| 291 | + |
| 292 | + Assert.That(width == 1024 && height == 768, "Image dimensions do not match"); |
| 293 | + } |
| 294 | + } |
| 295 | +} |
0 commit comments