public void MipMapsHaveCorrectDimensionsForNonPowerOfTwoTexture(int mipLevel, int expectedWidth, int expectedHeight)
        {
            // Arrange.
            var texture = new Texture2D(new Device(), new Texture2DDescription
            {
                Width = 5,
                Height = 16,
                ArraySize = 1
            });

            // Act / Assert.
            int actualWidth, actualHeight;
            texture.GetDimensions(mipLevel, out actualWidth, out actualHeight);
            Assert.That(actualWidth, Is.EqualTo(expectedWidth));
            Assert.That(actualHeight, Is.EqualTo(expectedHeight));
        }
		public void TextureHasCorrectNumberOfMipMapLevels(int width, int height, int expectedNumberOfLevels)
		{
			// Arrange.
			var texture = new Texture2D(new Device(), new Texture2DDescription
			{
				Width = width,
				Height = height,
				ArraySize = 1
			});
			int actualWidth, actualHeight, numberOfLevels;

			// Act.
            texture.GetDimensions(0, out actualWidth, out actualHeight, out numberOfLevels);

			// Assert.
            Assert.That(actualWidth, Is.EqualTo(width));
            Assert.That(actualHeight, Is.EqualTo(height));
            Assert.That(numberOfLevels, Is.EqualTo(expectedNumberOfLevels));
		}
		public static WriteableBitmap CreateBitmapFromTexture(Texture2D texture, int arraySlice, int mipLevel)
		{
		    var subresource = Resource.CalculateSubresource(mipLevel, arraySlice, texture.Description.MipLevels);
            var colors = texture.GetData(subresource);

            var pixelData = new byte[colors.Length * 4];
            for (int i = 0; i < colors.Length; i++)
            {
                pixelData[(i * 4) + 0] = (byte) (colors[i].B * 255.0f);
                pixelData[(i * 4) + 1] = (byte) (colors[i].G * 255.0f);
                pixelData[(i * 4) + 2] = (byte) (colors[i].R * 255.0f);
                pixelData[(i * 4) + 3] = (byte) (colors[i].A * 255.0f);
            }

            int width, height;
            texture.GetDimensions(mipLevel, out width, out height);

            var bitmapSouce = BitmapSource.Create(width, height, 96, 96, PixelFormats.Bgra32, null,
                pixelData, width * PixelFormats.Bgra32.BitsPerPixel / 8);

            return new WriteableBitmap(bitmapSouce);
		}