public void Parameters_and_whitespace_are_preserved_when_identifier_is_updated() { const string identifier = "da4d67ed-7b88-4266-881b-ae11cd56145c"; const string filePath = "path"; var file = Substitute.For <ISourceFile>(); file.Path.Returns(filePath); file.ReadAllLines().Returns(new[] { " // Logging message", $" Logger.Log( LogLevel.Error , \"{identifier}\" , obj1 , obj2 );" }); var analyser = new SourceFileAnalyser(false, UpdateMode.All); analyser.Analyse(file); var keys = analyser.LogCallMap.Keys.ToList(); Assert.AreEqual(1, keys.Count); file.Received(1).WriteAllLines(Arg.Is <string[]>(strings => strings.SequenceEqual(new[] { " // Logging message", $" Logger.Log( LogLevel.Error , \"{keys[0]}\" , obj1 , obj2 );" }))); }
public void Analyse_updates_all_identifiers_if_update_mode_is_all() { const string identifier = "da4d67ed-7b88-4266-881b-ae11cd56145c"; const string filePath = "path"; var file = Substitute.For <ISourceFile>(); file.Path.Returns(filePath); file.ReadAllLines().Returns(new[] { $"Logger.Log(LogLevel.Error, \"{identifier}\");", $"Logger.Log(LogLevel.Error, \"{identifier}\");", $"Logger.Log(LogLevel.Error, \"\");" }); var analyser = new SourceFileAnalyser(false, UpdateMode.All); analyser.Analyse(file); var keys = analyser.LogCallMap.Keys.ToList(); Assert.AreEqual(3, keys.Count); Assert.IsFalse(keys.Contains(identifier)); file.Received(1).WriteAllLines(Arg.Is <string[]>(strings => strings.SequenceEqual(new[] { $"Logger.Log(LogLevel.Error, \"{keys[0]}\");", $"Logger.Log(LogLevel.Error, \"{keys[1]}\");", $"Logger.Log(LogLevel.Error, \"{keys[2]}\");" }))); }
public void Analyse_updates_zero_length_identifier_if_update_mode_is_nonunique() { const string filePath = "path"; var file = Substitute.For <ISourceFile>(); file.Path.Returns(filePath); file.ReadAllLines().Returns(new[] { $"Logger.Log(LogLevel.Error, \"\");" }); var analyser = new SourceFileAnalyser(false, UpdateMode.NonUnique); analyser.Analyse(file); var keys = analyser.LogCallMap.Keys.ToList(); Assert.AreEqual(1, keys.Count); Assert.IsFalse(string.IsNullOrWhiteSpace(keys[0])); file.Received(1).WriteAllLines(Arg.Is <string[]>(strings => strings.SequenceEqual(new[] { $"Logger.Log(LogLevel.Error, \"{keys[0]}\");" }))); }
public void Analyse_throws_if_message_is_required_but_no_message_is_found() { const string identifier = "id1"; const string filePath = "path"; var file = Substitute.For <ISourceFile>(); file.Path.Returns(filePath); file.ReadAllLines().Returns(new[] { $"Logger.Log(LogLevel.Error, \"{identifier}\");" }); var analyser = new SourceFileAnalyser(true, UpdateMode.None); Assert.That(() => analyser.Analyse(file), Throws.TypeOf <Exception>()); }
public void Analyse_does_not_update_identifiers_if_they_are_unique_and_update_mode_is_not_all(UpdateMode mode) { const string identifier = "id1"; const string filePath = "path"; var file = Substitute.For <ISourceFile>(); file.Path.Returns(filePath); file.ReadAllLines().Returns(new[] { $"Logger.Log(LogLevel.Error, \"{identifier}\");" }); var analyser = new SourceFileAnalyser(false, mode); analyser.Analyse(file); file.DidNotReceive().WriteAllLines(Arg.Any <string[]>()); }
public void Parameters_and_whitespace_are_preserved_when_identifier_is_updated() { const string identifier = "da4d67ed-7b88-4266-881b-ae11cd56145c"; const string filePath = "path"; var file = Substitute.For<ISourceFile>(); file.Path.Returns(filePath); file.ReadAllLines().Returns(new[] { " // Logging message", $" Logger.Log( LogLevel.Error , \"{identifier}\" , obj1 , obj2 );" }); var analyser = new SourceFileAnalyser(false, UpdateMode.All); analyser.Analyse(file); var keys = analyser.LogCallMap.Keys.ToList(); Assert.AreEqual(1, keys.Count); file.Received(1).WriteAllLines(Arg.Is<string[]>(strings => strings.SequenceEqual(new[] { " // Logging message", $" Logger.Log( LogLevel.Error , \"{keys[0]}\" , obj1 , obj2 );" }))); }
public void Analyse_updates_all_identifiers_if_update_mode_is_all() { const string identifier = "da4d67ed-7b88-4266-881b-ae11cd56145c"; const string filePath = "path"; var file = Substitute.For<ISourceFile>(); file.Path.Returns(filePath); file.ReadAllLines().Returns(new[] { $"Logger.Log(LogLevel.Error, \"{identifier}\");", $"Logger.Log(LogLevel.Error, \"{identifier}\");", $"Logger.Log(LogLevel.Error, \"\");" }); var analyser = new SourceFileAnalyser(false, UpdateMode.All); analyser.Analyse(file); var keys = analyser.LogCallMap.Keys.ToList(); Assert.AreEqual(3, keys.Count); Assert.IsFalse(keys.Contains(identifier)); file.Received(1).WriteAllLines(Arg.Is<string[]>(strings => strings.SequenceEqual(new[] { $"Logger.Log(LogLevel.Error, \"{keys[0]}\");", $"Logger.Log(LogLevel.Error, \"{keys[1]}\");", $"Logger.Log(LogLevel.Error, \"{keys[2]}\");" }))); }
public void Analyse_updates_zero_length_identifier_if_update_mode_is_nonunique() { const string filePath = "path"; var file = Substitute.For<ISourceFile>(); file.Path.Returns(filePath); file.ReadAllLines().Returns(new[] { $"Logger.Log(LogLevel.Error, \"\");" }); var analyser = new SourceFileAnalyser(false, UpdateMode.NonUnique); analyser.Analyse(file); var keys = analyser.LogCallMap.Keys.ToList(); Assert.AreEqual(1, keys.Count); Assert.IsFalse(string.IsNullOrWhiteSpace(keys[0])); file.Received(1).WriteAllLines(Arg.Is<string[]>(strings => strings.SequenceEqual(new[] { $"Logger.Log(LogLevel.Error, \"{keys[0]}\");" }))); }
public void Analyse_does_not_update_identifiers_if_they_are_unique_and_update_mode_is_not_all(UpdateMode mode) { const string identifier = "id1"; const string filePath = "path"; var file = Substitute.For<ISourceFile>(); file.Path.Returns(filePath); file.ReadAllLines().Returns(new[] { $"Logger.Log(LogLevel.Error, \"{identifier}\");" }); var analyser = new SourceFileAnalyser(false, mode); analyser.Analyse(file); file.DidNotReceive().WriteAllLines(Arg.Any<string[]>()); }
public void Analyse_throws_if_message_is_required_but_no_message_is_found() { const string identifier = "id1"; const string filePath = "path"; var file = Substitute.For<ISourceFile>(); file.Path.Returns(filePath); file.ReadAllLines().Returns(new[] { $"Logger.Log(LogLevel.Error, \"{identifier}\");" }); var analyser = new SourceFileAnalyser(true, UpdateMode.None); Assert.That(() => analyser.Analyse(file), Throws.TypeOf<Exception>()); }