public async Task ValidSettings_VerifyFile(string settingsFile, string expectedSha256Hash) { var sha256 = SHA256.Create(); await using var memoryStream = new MemoryStream(); var settings = await SettingsLoader.LoadAndValidateSettings(settingsFile); var container = DependencyConfig.ConfigureContainer(settings, c => { c.AddInstance <IProgressReporter>(new XUnitProgressReporter(testOutputHelper)); c.AddTransient <IOutputDirectoryProvider, CurrentDirectoryProvider>(); }); var mp3Stream = container.Resolve <Mp3Stream>(); await mp3Stream.Write(memoryStream); await memoryStream.FlushAsync(); memoryStream.Seek(0, SeekOrigin.Begin); var hash = sha256.ComputeHash(memoryStream); var hashString = BitConverter.ToString(hash).Replace("-", "").ToUpperInvariant(); if (expectedSha256Hash != hashString) { memoryStream.Seek(0, SeekOrigin.Begin); await using var fileStream = new FileStream(settingsFile + ".mp3", FileMode.Create, FileAccess.Write); await memoryStream.CopyToAsync(fileStream); } Assert.Equal(expectedSha256Hash.Length, hashString.Length); Assert.Equal(expectedSha256Hash, hashString); }
public async Task Mp3ToFile() { var settings = await SettingsLoader.LoadAndValidateSettings("Settings_FrequencyLinked.json"); var container = DependencyConfig.ConfigureContainer(settings, c => { c.AddInstance <IProgressReporter>(new XUnitProgressReporter(testOutputHelper)); c.AddTransient <IOutputDirectoryProvider, CurrentDirectoryProvider>(); }); var mp3Stream = container.Resolve <Mp3Stream>(); await mp3Stream.Write("TestFile.mp3"); }
public static async Task Main(string[] allArgs) { var stopwatch = Stopwatch.StartNew(); try { string[] options = allArgs.Where(a => a.StartsWith("--")).Select(a => a.Substring(2)).ToArray(); string[] args = allArgs.Where(a => !a.StartsWith("--")).ToArray(); acceptName = options.Contains("acceptName", StringComparer.CurrentCultureIgnoreCase); if (args.Length == 0) { await Console.Out.WriteLineAsync($"No settings file passed.\nPlease copy and modify one of the example settings files to <name>.settings.json, then pass the modified file to the program on the command line."); } else if (args.Length > 2) { throw new InvalidOperationException($"Too many files passed. Please only pass one file."); } else { var filePath = args.Single(); var settings = await SettingsLoader.LoadAndValidateSettings(filePath); var container = DependencyConfig.ConfigureContainer(settings, c => { c.AddTransient <IOutputDirectoryProvider, CurrentDirectoryProvider>(); c.AddInstance <IProgressReporter>(new ConsoleProgressReporter()); }); var name = await GetName(settings); Console.WriteLine($"Writing {name}..."); await WriteFile(container, settings, name); stopwatch.Stop(); ConsoleWriter.WriteLine($"File successfully created in {stopwatch.Elapsed}", ConsoleColor.Green); } } catch (Exception ex) { var exceptionToReport = (ex.GetBaseException() as WaveGeneratorException) ?? ex; ConsoleWriter.WriteLine(exceptionToReport.Message, ConsoleColor.Red); Console.WriteLine(); Console.WriteLine($"If the program will not accept the settings file you are using, please go to https://github.com/originalhedonist/waves_dotnet/issues and create an issue, attaching the file, and/or email [email protected], and I will convert the file into a format that can be read by the current version of the program for you. "); } }
public async Task RoundTrip() { var settings = await SettingsLoader.LoadAndValidateSettings("Settings_RoundTrip.json"); var settingsv1 = Assert.IsAssignableFrom <Settings>(settings); var settingsJson = JsonConvert.SerializeObject(settings, new JsonSerializerSettings { ContractResolver = new BaseClassPropertiesFirstContractResolver() }); // convert back to json, to avoid whitespace issues, etc var mappingConfig = Mapping.CreateMapperConfiguration(); var mapper = new Mapper(mappingConfig); var createFileRequest = mapper.Map <Settings, CreateFileRequest>(settingsv1); var roundTrippedSettings = mapper.Map <CreateFileRequest, Settings>(createFileRequest); var roundTrippedSettingsJson = JsonConvert.SerializeObject(roundTrippedSettings, new JsonSerializerSettings { ContractResolver = new BaseClassPropertiesFirstContractResolver() }); Assert.Equal(settingsJson, roundTrippedSettingsJson); }