public void ExampleSpaces() { var seeds = Enumerable.Range(0, 5); var gens = new Dictionary <string, IIntGen <long> > { { "Between_0_And_10", Gen.Int64().Between(0, 10) }, { "Between_0_And_100", Gen.Int64().Between(0, 100) }, }; var biases = new[] { Gen.Bias.None, Gen.Bias.WithSize }; foreach (var seed in seeds) { foreach (var(betweenDescription, gen) in gens) { foreach (var bias in biases) { var sample = gen .WithBias(bias) .Advanced.SampleOneExampleSpace(seed: seed, size: 75) .Take(500) .Render(x => x.ToString()); var nameExtension = string.Join("_", new[] { betweenDescription, $"Bias_{bias}", $"Seed_{seed}" }); Snapshot.Match(sample, SnapshotNameExtension.Create(nameExtension)); } } } }
/// <summary> /// Creates a json snapshot of the given object and compares it with the /// already existing snapshot of the test. /// If no snapshot exists, a new snapshot will be created from the current result /// and saved under a certain file path, which will shown within the test message. /// </summary> /// <typeparam name="T">The type of the result/object to match.</typeparam> /// <param name="currentResult">The object to match.</param> /// <param name="snapshotNameExtension"> /// The snapshot name extension will extend the generated snapshot name with /// this given extensions. It can be used to make a snapshot name even more /// specific. /// Example: /// Generated Snapshotname = 'NumberAdditionTest' /// Snapshot name extension = '5', '6', 'Result', '11' /// Result: 'NumberAdditionTest_5_6_Result_11' /// </param> /// <param name="matchOptions"> /// Additional compare actions, which can be applied during the snapshot comparison /// </param> public static void Match <T>(T currentResult, SnapshotNameExtension snapshotNameExtension, Func <MatchOptions, MatchOptions> matchOptions = null) { Match((object)currentResult, snapshotNameExtension, matchOptions); }
/// <summary> /// Resolves the snapshot name for the running unit test. /// The default generated snapshot name can either be overwritten /// with a given snapshot name, or can be extended by the snapshot name extensions, /// or both. /// </summary> /// <param name="snapshotName"> /// The snapshot name given by the user, this snapshot name will overwrite /// the automatically generated snapshot name. /// </param> /// <param name="snapshotNameExtension"> /// The snapshot name extension will extend the snapshot name with /// this given extensions. It can be used to make a snapshot name even more /// specific. /// Example: /// Snapshot name = 'NumberAdditionTest' /// Snapshot name extension = '5', '6', 'Result', '11' /// Result: 'NumberAdditionTest_5_6_Result_11' /// </param> /// <returns>The full name of a snapshot.</returns> public static SnapshotFullName FullName( string snapshotName, SnapshotNameExtension snapshotNameExtension) { return(Snapshooter.ResolveSnapshotFullName(snapshotName, snapshotNameExtension)); }
/// <summary> /// Creates a json snapshot of the given object and compares it with the /// already existing snapshot of the test. /// If no snapshot exists, a new snapshot will be created from the current result /// and saved under a certain file path, which will shown within the test message. /// </summary> /// <param name="currentResult">The object to match.</param> /// <param name="snapshotNameExtension"> /// The snapshot name extension will extend the generated snapshot name with /// this given extensions. It can be used to make a snapshot name even more /// specific. /// Example: /// Generated Snapshotname = 'NumberAdditionTest' /// Snapshot name extension = '5', '6', 'Result', '11' /// Result: 'NumberAdditionTest_5_6_Result_11' /// </param> /// <param name="matchOptions"> /// Additional compare actions, which can be applied during the snapshot comparison /// </param> public static void Match(object currentResult, SnapshotNameExtension snapshotNameExtension, Func <MatchOptions, MatchOptions> matchOptions = null) { Match(currentResult, FullName(snapshotNameExtension), matchOptions); }
public void Snapshots(int numberOfSamples) { var sample = SampleSize(numberOfSamples); Snapshot.Match(sample, SnapshotNameExtension.Create($"NumberOfSamples={numberOfSamples}")); }
/// <summary> /// Creates a json snapshot of the given object and compares it with the /// already existing snapshot of the test. /// If no snapshot exists, a new snapshot will be created from the current result /// and saved under a certain file path, which will shown within the test message. /// </summary> /// <param name="currentResult">The object to match.</param> /// <param name="snapshotNameExtension"> /// The snapshot name extension will extend the generated snapshot name with /// this given extensions. It can be used to make a snapshot name even more /// specific. /// Example: /// Generated Snapshotname = 'NumberAdditionTest' /// Snapshot name extension = '5', '6', 'Result', '11' /// Result: 'NumberAdditionTest_5_6_Result_11' /// </param> /// <param name="matchOptions"> /// Additional compare actions, which can be applied during the snapshot comparison /// </param> public static void MatchSnapshot(this object currentResult, SnapshotNameExtension snapshotNameExtension, Func <MatchOptions, MatchOptions> matchOptions = null) { Snapshot.Match(currentResult, snapshotNameExtension, matchOptions); }