public void DefaultSnapshotOptions_Comparer() { SnapshotOptions.Setup(o => { o.SetComparer((newline, savedline) => newline.Value.Replace(" ", string.Empty, StringComparison.OrdinalIgnoreCase).Equals(savedline.Value.Replace(" ", string.Empty, StringComparison.OrdinalIgnoreCase))); }); var options = SnapshotOptions.Create(o => { o.UpdateSavedSnapshot(); }); var sn = new StringBuilder() .AppendLine("Line 1") .AppendLine("Line 2") .AppendLine("Line 3") .ToString(); sn.MatchSnapshot(options); sn = new StringBuilder() .AppendLine("Line 1") .AppendLine(" Line 2") .AppendLine(" Line 3") .ToString(); sn.MatchSnapshot(); // reset SnapshotOptions.Setup(o => { }); }
public void SnapshotOptions_Configure() { var sn = new StringBuilder() .AppendLine("Line 1") .AppendLine("Line 2") .AppendLine("Line 3"); var savedsnap = SnapshotTokenizer.Tokenize(sn.ToString()); var config = new SnapshotOptions(); config.SetComparer((newline, savedline) => newline.Value.Replace(" ", string.Empty, StringComparison.OrdinalIgnoreCase).Equals(savedline.Value.Replace(" ", string.Empty, StringComparison.OrdinalIgnoreCase))); sn = new StringBuilder() .AppendLine("Line 1") .AppendLine(" Line 2") .AppendLine(" Line 3"); var newsnap = SnapshotTokenizer.Tokenize(sn.ToString()); var comparer = new SnapshotCompare(); var result = comparer.Compare(newsnap, savedsnap, config); result.Status.Should().Be(SnapshotStatus.SnapshotsMatch); SnapshotOptions.Setup(o => { }); }
public void DefaultSnapshotOptions_Parser() { SnapshotOptions.Setup(o => { o.AddDirective(line => line.Replace(" ", string.Empty, StringComparison.OrdinalIgnoreCase)); }); var options = SnapshotOptions.Create(o => { o.UpdateSavedSnapshot(); }); var sn = new StringBuilder() .AppendLine("Line1") .AppendLine("Line2") .AppendLine("Line3") .ToString(); sn.MatchSnapshot(options); sn = new StringBuilder() .AppendLine("Line 1") .AppendLine(" Line 2") .AppendLine(" Line 3") .ToString(); sn.MatchSnapshot(); // reset SnapshotOptions.Setup(o => { }); }
public void Snapshot_Options_UseBasicFormatters_Formatter_SimpleString() { // reset SnapshotOptions.Setup(o => { o.UseBasicFormatters(); }); SnapshotOptions.Default.Formatters[typeof(string)].Should().BeOfType <SimpleStringFormatter>(); }
public void Snapshot_Options_AddDirectives_DefaultOptions_Parser() { // ignore Guids when comparing SnapshotOptions.Default.Parser.AddDirective(s => s.ReplaceRegex(@"(?im)[{(]?[0-9A-Fa-f]{8}[-]?(?:[0-9A-Fa-f]{4}[-]?){3}[0-9A-Fa-f]{12}[)}]?", "00000000-0000-0000-0000-000000000000")); new { Value = Guid.NewGuid() }.MatchSnapshot(); // reset SnapshotOptions.Setup(o => { }); }
public void Snapshot_Options_DefaultOptions_Parser_AfterReset() { // ignore Guids when comparing var parser = SnapshotOptions.Default.Parser; // reset SnapshotOptions.Setup(o => { }); Assert.AreNotSame(SnapshotOptions.Default.Parser, parser); }
public void Snapshot_Options_UseBasicFormatters_Formatter_Type() { // reset SnapshotOptions.Setup(o => { o.UseBasicFormatters(); }); SnapshotOptions.Default.Formatters[typeof(Type)].Should().BeOfType <TypeFormatter>(); }
public void Snapshot_Options_UseBasicFormatters_Count() { // reset SnapshotOptions.Setup(o => { o.UseBasicFormatters(); }); SnapshotOptions.Default.Formatters.Count().Should().Be(2); }
public void Snapshot_Options_UseBasicFormatters_CustomOptions_DefaultSet() { SnapshotOptions.Setup(o => { o.UseBasicFormatters(); }); var options = SnapshotOptions.Create(o => { }); options.Formatters.Count().Should().Be(2); }
public void Snapshot_Options_UseBasicFormatters_Types() { // reset SnapshotOptions.Setup(o => { o.UseBasicFormatters(); }); var keys = SnapshotOptions.Default.Formatters.Keys.ToArray(); keys[0].Should().Be(typeof(Type)); keys[1].Should().Be(typeof(string)); }
public void SnapshotOptions_Merge_TypeMappers_MultipleSame() { SnapshotOptions.Setup(o => { o.AddMapper <CustomType>((c, m) => { }); o.AddMapper <CustomOtherType>((c, m) => { }); }); var options = SnapshotOptions.Create(o => { o.AddMapper <CustomType>((c, i) => { }); }); options.MergeDefault(); options.TypeMappers.Count().Should().Be(2); }
public void Mapper_Set_Formatters_UseBasicFormatters_MatchSnapshot() { SnapshotOptions.Default.UseBasicFormatters(); new { Value = new CustomObject { Value = "TesT" }, Str = (string)null }.MatchSnapshot(); // reset SnapshotOptions.Setup(o => { }); }
public void Mapper_Set_Formatters_UseBasicFormatters() { SnapshotOptions.Default.UseBasicFormatters(); new { Value = new CustomObject { Value = "TesT" }, Str = (string)null }.Tokenize().ToString().Should().Be($"Str: {Environment.NewLine}Value:{Environment.NewLine} Id: 0{Environment.NewLine} Value: TesT"); // reset SnapshotOptions.Setup(o => { }); }
public void SnapshotOptions_Merge_TypeMappers() { SnapshotOptions.Setup(o => { o.AddMapper <CustomType>((c, m) => { }); }); var options = new SnapshotOptions(); options.TypeMappers.Count().Should().Be(0); options.MergeDefault(); options.TypeMappers.Count().Should().Be(1); foreach (var key in options.TypeMappers.Keys) { options.TypeMappers[key].Should().BeSameAs(SnapshotOptions.Default.TypeMappers[key]); } }
public void Mapper_Set_Formatters_DefaultOptions_Setup() { SnapshotOptions.Setup(o => { o.AddFormatter(typeof(CustomObject), new CustomObjectFormatter()); }); new { Value = new CustomObject { Value = "TesT" }, Str = (string)null }.Tokenize().ToString().Should().Be($"Str: null{Environment.NewLine}Value: custom - TesT"); // reset SnapshotOptions.Setup(o => { }); }
public void Mapper_Set_Formatters_DefaultOptions_MatchSnapshot() { SnapshotOptions.Setup(o => { o.AddFormatter(typeof(CustomObject), new CustomObjectFormatter()); }); new { Value = new CustomObject { Value = "TesT" }, Str = (string)null }.MatchSnapshot(); // reset SnapshotOptions.Setup(o => { }); }
public void DefaultSnapshotOptions_UpdateSnapshot() { var options = SnapshotOptions.Create(o => { o.UpdateSavedSnapshot(); }); var sn = new StringBuilder() .AppendLine("Line 1") .AppendLine("Line 2") .AppendLine("Line 3") .ToString(); // rewrite the snapshot sn.MatchSnapshot(options); sn = new StringBuilder() .AppendLine("Line 1") .AppendLine(" Line 2") .AppendLine(" Line 3") .ToString(); Action fail = () => sn.MatchSnapshot(); Assert.Throws <SnapshotMatchException>(() => fail.Invoke()); // rewrite snapshot sn.MatchSnapshot(options); sn = new StringBuilder() .AppendLine("Line 1") .AppendLine(" Line 2") .AppendLine(" Line 3") .ToString(); // Final Assert sn.MatchSnapshot(); // reset SnapshotOptions.Setup(o => { }); }
public void SnapshotOptions_Merge_Formatters_MultipleSame() { SnapshotOptions.Setup(o => { o.Formatters = new MapperCollection <Type, IValueFormatter> { { typeof(int), new NumberFormatter() }, { typeof(double), new NumberFormatter() } }; }); var options = SnapshotOptions.Create(o => { o.AddFormatter(typeof(int), new NumberFormatter()); }); options.MergeDefault(); options.Formatters.Count().Should().Be(2); }
public void Snapshot_Options() { var sn = new StringBuilder() .AppendLine("Line 1") .AppendLine("Line 2") .AppendLine("Line 3"); var snapshot = SnapshotTokenizer.Tokenize(sn.ToString()); snapshot.MatchSnapshot(SnapshotOptions.Create(c => { c.UpdateSavedSnapshot(); })); sn = new StringBuilder() .AppendLine("Line 1") .AppendLine(" Line 2") .AppendLine(" Line 3"); snapshot = SnapshotTokenizer.Tokenize(sn.ToString()); var options = new SnapshotOptions { Comparer = new LineCompare((newline, savedline) => newline.Value.Replace(" ", string.Empty, StringComparison.OrdinalIgnoreCase).Equals(savedline.Value.Replace(" ", string.Empty, StringComparison.OrdinalIgnoreCase))) }; snapshot.MatchSnapshot(options); options = SnapshotOptions.Create(o => { o.SetComparer((newline, savedline) => newline.Value.Replace(" ", string.Empty, StringComparison.OrdinalIgnoreCase).Equals(savedline.Value.Replace(" ", string.Empty, StringComparison.OrdinalIgnoreCase))); }); snapshot.MatchSnapshot(options); // reset SnapshotOptions.Setup(o => { }); }
public void TypeMapper_ObjectMapper() { SnapshotOptions.Default.AddMapper <CustomData>((ctx, o) => { //only add Value and Dbl but ignore Id ctx.AddLine("Dbl", o.Dbl); ctx.AddLine("Value", o.Value); }); var snapshot = new { Item = "item", Data = new CustomData { Id = 1, Dbl = 2.2, Value = "value", Inner = new InnerData { Id = 2, Value = "inner" } } }.Tokenize(); var expected = new { Item = "item", Data = new { Value = "value", Dbl = 2.2 } }.Tokenize(); snapshot.ToString().Should().Be(expected.ToString()); SnapshotOptions.Setup(o => { }); }
public void Setup() { SnapshotOptions.Setup(o => { }); }
public void Setup() { // reset SnapshotOptions.Setup(o => { }); }