using System; using UnitTestSharp; namespace Prism.UnitTests { public class RgbaTests : TestFixture { public class ByteCountTests : TestFixture { public void OnePixel_IsFourBytes() { CheckEqual(4, Rgba.ByteCount(1, 1)); } public void WidthAndHeight_MultiplyIntoTheCount() { CheckEqual(24, Rgba.ByteCount(2, 3)); } public void ZeroWidth_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); Rgba.ByteCount(0, 1); } public void ZeroHeight_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); Rgba.ByteCount(1, 0); } } public class CheckBufferTests : TestFixture { public void ABufferOfTheRightLength_Passes() { Rgba.CheckBuffer(new byte[24], width: 2, height: 3); } public void ANullBuffer_Throws() { CheckThrow(typeof(ArgumentNullException)); Rgba.CheckBuffer(null, width: 2, height: 3); } public void ABufferOfAnotherLength_Throws() { CheckThrow(typeof(ArgumentException)); Rgba.CheckBuffer(new byte[23], width: 2, height: 3); } public void ASizeOfNoPixels_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); Rgba.CheckBuffer(new byte[0], width: 0, height: 3); } } public class WriteTests : TestFixture { public void PutsTheFourChannelsAtThePixelsOffset() { var pixels = new byte[8]; Rgba.Write(pixels, pixelIndex: 1, Color.FromArgb(4, 1, 2, 3)); CheckEqual(new byte[] { 0, 0, 0, 0, 1, 2, 3, 4 }, pixels); } } } }