Exemple #1
0
        public void ParseFromFileExtension_ShouldThrowException_GivenUnsupportedFileFormatExtension()
        {
            // Arrange
            const string fileExtension = ".unsupported";

            // Act
            // Assert
            Assert.That(() => SoundFormatParser.ParseFromFileExtension(fileExtension), Throws.TypeOf <UnsupportedSoundFileFormatException>());
        }
Exemple #2
0
        public void ParseFromFileExtension_ShouldMapStringFileExtensionToEnumSoundFormat(string fileExtension, SoundFormat soundFormat)
        {
            // Arrange
            // Act
            var actual = SoundFormatParser.ParseFromFileExtension(fileExtension);

            // Assert
            Assert.That(actual, Is.EqualTo(soundFormat));
        }
        public object LoadAsset(AssetInfo assetInfo, IAssetStore assetStore)
        {
            using var assetFileStream = _fileSystem.GetFile(assetInfo.AssetFilePath).OpenRead();
            var assetData         = AssetData.Load(assetFileStream);
            var soundAssetContent = assetData.ReadJsonContent <SoundAssetContent>();

            var relativeSiblingPath = soundAssetContent.SoundFilePath ??
                                      throw new InvalidOperationException(
                                                $"{nameof(SoundAssetContent)}.{nameof(SoundAssetContent.SoundFilePath)} cannot be null.");

            var soundFilePath = PathUtils.GetSiblingPath(assetInfo.AssetFilePath, relativeSiblingPath);
            var fileExtension = Path.GetExtension(soundFilePath);
            var soundFormat   = SoundFormatParser.ParseFromFileExtension(fileExtension);

            using var soundFileStream = _fileSystem.GetFile(soundFilePath).OpenRead();
            return(_audioBackend.CreateSound(soundFileStream, soundFormat));
        }