public static MagicNumberMapping GetAllMappings()
        {
            var magicNumberMapping = new MagicNumberMapping();

            foreach (var magicNumber in ImageMagicNumbers.BMPMagicNumbers)
            {
                magicNumberMapping.AddMagicNumber(magicNumber, ImageMagicNumbers.BMP);
            }

            foreach (var magicNumber in ImageMagicNumbers.GIFMagicNumbers)
            {
                magicNumberMapping.AddMagicNumber(magicNumber, ImageMagicNumbers.GIF);
            }

            foreach (var magicNumber in ImageMagicNumbers.JPEGMagicNumbers)
            {
                magicNumberMapping.AddMagicNumber(magicNumber, ImageMagicNumbers.JPEG);
            }

            foreach (var magicNumber in ImageMagicNumbers.PNGMagicNumbers)
            {
                magicNumberMapping.AddMagicNumber(magicNumber, ImageMagicNumbers.PNG);
            }

            foreach (var magicNumber in DocumentMagicNumbers.PDFMagicNumbers)
            {
                magicNumberMapping.AddMagicNumber(magicNumber, DocumentMagicNumbers.PDF);
            }

            return(magicNumberMapping);
        }
        public static MagicNumberMapping CreateMappingWithSingleMagicNumber(byte?[] magicNumber, string fileType)
        {
            var fileMagicNumberMapping = new MagicNumberMapping();

            fileMagicNumberMapping.AddMagicNumber(magicNumber, fileType);
            return(fileMagicNumberMapping);
        }
        public void AddMagicNumber_ArgumentException_Tests(byte?[] magicNumber, string fileType)
        {
            // Arrange
            var magicNumberMapping = new MagicNumberMapping();

            magicNumberMapping.FileMagicNumberMappingTable.Should().BeEmpty("there should not be any existing mappings");

            // Act
            Action act = () => magicNumberMapping.AddMagicNumber(magicNumber, fileType);

            // Assert
            act.Should().Throw <ArgumentException>("the input is bad and should provoke an exception");
        }
        public void AddMagicNumber_Positive()
        {
            // Arrange
            var magicNumber = ValidMagicNumber;
            var fileType    = "test";

            // Act
            var magicNumberMapping = new MagicNumberMapping();

            magicNumberMapping.AddMagicNumber(magicNumber, fileType);

            // Assert
            magicNumberMapping.FileMagicNumberMappingTable.Should().HaveCount(1, "a mapping should have been added");
        }
        public void GetLongestMagicNumber_Positive()
        {
            // Arrange
            var longestMagicNumberToAdd = 10;
            var fileMagicNumberMapping  = new MagicNumberMapping();

            for (var i = 1; i <= longestMagicNumberToAdd; i++)
            {
                var magicNumber = Enumerable.Repeat(new byte?(1), i).ToArray();
                var type        = i.ToString();
                fileMagicNumberMapping.AddMagicNumber(magicNumber, type);
            }

            // Act
            var longestMagicNumber = fileMagicNumberMapping.GetLongestMagicNumber();

            // Assert
            longestMagicNumber.Should().Be(longestMagicNumberToAdd);
        }