public void SizeTrackerNegativeTest()
		{
			NuGenRatioSizeTracker sizeTracker = new NuGenRatioSizeTracker(new Size(-5, -10));
			Assert.AreEqual(0.5, sizeTracker.Ratio);

			sizeTracker.Width = 20;
			Assert.AreEqual(40, sizeTracker.Height);
		}
		public void SizeTrackerDoNotMaintainAspectRatioTest()
		{
			NuGenRatioSizeTracker sizeTracker = new NuGenRatioSizeTracker(new Size(800, 600));

			sizeTracker.Height = 480;
			Assert.AreEqual(800, sizeTracker.Width);

			sizeTracker.Width = 100;
			Assert.AreEqual(480, sizeTracker.Height);
		}
		public void UpdateSizeTrackerTest()
		{
			NuGenRatioSizeTracker sizeTracker = new NuGenRatioSizeTracker(new Size(512, 512));
			Assert.AreEqual(1.0, sizeTracker.Ratio);

			sizeTracker.Width = 1024;
			sizeTracker.Height = 768;

			sizeTracker.UpdateRatio();
			Assert.AreEqual(1024.0 / 768.0, sizeTracker.Ratio);
		}
		public void SizeTrackerEmptyTest()
		{
			NuGenRatioSizeTracker sizeTracker = new NuGenRatioSizeTracker(Size.Empty);
			Assert.AreEqual(1.0, sizeTracker.Ratio);
			
			sizeTracker.Height = 0;
			sizeTracker.Width = 0;
			Assert.AreEqual(1.0, sizeTracker.Ratio);

			sizeTracker.Width = 5;
			Assert.AreEqual(1.0, sizeTracker.Ratio);
		}
		public void SizeTrackerEventTest()
		{
			NuGenRatioSizeTracker sizeTracker = new NuGenRatioSizeTracker(new Size(800, 600));
			SizeTrackerEventSink eventSink = new SizeTrackerEventSink(sizeTracker);

			eventSink.ExpectedWidth = 640;
			eventSink.ExpectedHeight = 480;
			eventSink.ExpectedHeightChangedCallsCount = 1;
			eventSink.ExpectedWidthChangedCallsCount = 0;

			sizeTracker.Width = 640;
			Assert.AreEqual(new Size(640, 480), sizeTracker.Size);

			eventSink.Verify();
		}
Пример #6
0
        private Size GetImageSize(Size originalImageSize)
        {
            NuGenRatioSizeTracker tracker = new NuGenRatioSizeTracker(originalImageSize);

            int maxWidth  = _maxWidthCheckBox.Checked ? _maxWidthSpin.Value : originalImageSize.Width;
            int maxHeight = _maxHeightCheckBox.Checked ? _maxHeightSpin.Value : originalImageSize.Height;

            tracker.MaintainAspectRatio = true;
            tracker.Width = maxWidth;

            if (tracker.Height > maxHeight)
            {
                tracker.Height = maxHeight;
            }

            return(tracker.Size);
        }
		public void SizeTrackerMaintainAspectRatioTest()
		{
			NuGenRatioSizeTracker sizeTracker = new NuGenRatioSizeTracker(new Size(800, 600));

			Assert.AreEqual(800.0 / 600.0, sizeTracker.Ratio);

			sizeTracker.Height = 480;
			Assert.AreEqual(640, sizeTracker.Size.Width);

			sizeTracker.Width = 1280;
			Assert.AreEqual(960, sizeTracker.Size.Height);

			sizeTracker.Height = 240;
			Assert.AreEqual(320, sizeTracker.Size.Width);

			sizeTracker.Width = 100;
			Assert.AreEqual(75, sizeTracker.Size.Height);
		}
			public SizeTrackerEventSink(NuGenRatioSizeTracker sizeTracker)
			{
				if (sizeTracker == null)
				{
					throw new ArgumentNullException("sizeTracker");
				}

				_sizeTracker = sizeTracker;

				_sizeTracker.HeightChanged += delegate
				{
					_expectedHeight.Actual = _sizeTracker.Height;
					_expectedWidth.Actual = _sizeTracker.Width;
					_expectedHeightChangedCallsCount.Inc();
				};

				_sizeTracker.WidthChanged += delegate
				{
					_expectedWidth.Actual = _sizeTracker.Width;
					_expectedHeight.Actual = _sizeTracker.Width;
					_expectedWidthChangedCallsCount.Inc();
				};
			}
		public void SizeTrackerDoNotMaintainAspectRatioEventTest()
		{
			NuGenRatioSizeTracker sizeTracker = new NuGenRatioSizeTracker(new Size(800, 600));
			SizeTrackerEventSink eventSink = new SizeTrackerEventSink(sizeTracker);

			eventSink.ExpectedHeightChangedCallsCount = 0;
			eventSink.ExpectedWidthChangedCallsCount = 0;

			sizeTracker.Height = 800;
			Assert.AreEqual(new Size(800, 800), sizeTracker.Size);

			sizeTracker.Width = 480;
			Assert.AreEqual(new Size(480, 800), sizeTracker.Size);

			eventSink.Verify();
		}