public SignUpView() { // The InitializeComponent method is also generated automatically // and lives in the autogenerated part of the partial class. InitializeComponent(); this.WhenActivated(disposables => { this.Bind(ViewModel, x => x.UserName, x => x.UserNameTextBox.Text) .DisposeWith(disposables); this.Bind(ViewModel, x => x.Password, x => x.PasswordTextBox.Text) .DisposeWith(disposables); this.Bind(ViewModel, x => x.ConfirmPassword, x => x.ConfirmPasswordTextBox.Text) .DisposeWith(disposables); this.BindCommand(ViewModel, x => x.SignUp, x => x.SignUpButton) .DisposeWith(disposables); this.BindValidation(ViewModel, x => x.UserName, x => x.UserNameValidation.Text) .DisposeWith(disposables); this.BindValidation(ViewModel, x => x.Password, x => x.PasswordValidation.Text) .DisposeWith(disposables); this.BindValidation(ViewModel, x => x.ConfirmPassword, x => x.ConfirmPasswordValidation.Text) .DisposeWith(disposables); var newLineFormatter = new SingleLineFormatter(Environment.NewLine); this.BindValidation(ViewModel, x => x.CompoundValidation.Text, newLineFormatter) .DisposeWith(disposables); // The references to text boxes below are also auto generated. // Use Ctrl+Click in order to view the generated sources. UserNameTextBox.Text = "Joseph!"; PasswordTextBox.Text = "1234"; ConfirmPasswordTextBox.Text = "1234"; }); }
public void DeleteLog_LogEntryFoundAndDeleted_Pass() { //Arrange var fileHandler = new FileHandler(); LogMessage msg = new LogMessage(Guid.NewGuid(), DateTime.UtcNow, "FileHandlerTest.cs", "LogEntryFoundAndDeleted_Pass()", LogLevels.Levels.None, "Tester", "3", "Testing..."); string fileName = fileHandler.MakeFileNameByDate(msg); string path = Path.Combine(@"D:\LogStorage\", fileName); var formatter = new SingleLineFormatter(); var expected = true; var actual = false; //Act if (fileHandler.WriteLog(msg)) { string[] entries = File.ReadAllLines(path); string message = formatter.FormatLog(msg); var lastEntry = entries.Length - 1; if (entries[lastEntry].Equals(message)) { fileHandler.DeleteLog(msg); } entries = File.ReadAllLines(path); lastEntry = entries.Length - 1; if (!entries[lastEntry].Equals(message)) { actual = true; } } //Assert Assert.IsTrue(expected == actual); }
/// <summary> /// Initializes a new instance of the <see cref="SignUpView"/> class. /// </summary> public SignUpView() { InitializeComponent(); this.WhenActivated(disposables => { // Standard ReactiveUI bindings. this.Bind(ViewModel, x => x.UserName, x => x.UserNameTextBox.Text) .DisposeWith(disposables); this.Bind(ViewModel, x => x.Password, x => x.PasswordTextBox.Text) .DisposeWith(disposables); this.Bind(ViewModel, x => x.ConfirmPassword, x => x.ConfirmPasswordTextBox.Text) .DisposeWith(disposables); this.BindCommand(ViewModel, x => x.SignUp, x => x.SignUpButton) .DisposeWith(disposables); this.OneWayBind(ViewModel, x => x.IsBusy, x => x.BudyIndicator.IsVisible) .DisposeWith(disposables); // ReactiveUI.Validation: Bindings for error messages. this.BindValidation(ViewModel, x => x.UserName, x => x.UserNameValidation.Text) .DisposeWith(disposables); this.BindValidation(ViewModel, x => x.Password, x => x.PasswordValidation.Text) .DisposeWith(disposables); this.BindValidation(ViewModel, x => x.ConfirmPassword, x => x.ConfirmPasswordValidation.Text) .DisposeWith(disposables); // ReactiveUI.Validation: Compound validation bindings. var newLineFormatter = new SingleLineFormatter(Environment.NewLine); this.BindValidation(ViewModel, x => x.CompoundValidation.Text, newLineFormatter) .DisposeWith(disposables); }); }
public void CustomSeparatorTest() { var f = new SingleLineFormatter("+"); var vt = new ValidationText(new[] { new ValidationText(Item1Text), new ValidationText(Item2Text) }); var sl = f.Format(vt); Assert.Equal(Item1Text + "+" + Item2Text, sl); }
public void FormatMethodExit_CallMade_ExceptionIsThrown() { // Arrange var filters = this.GetDefaultFilters(); var formatter = new SingleLineFormatter(); var entry = new MethodExit(1, "Yalf.TestMethod", 345, true, "returnVal"); // Act, Assert var outputText = formatter.FormatMethodExit(1, 2, 33, entry, filters, true); }
public void FormatMethodExitForSingleLineOutput_NestedMethodCalls_CallsAreInCorrectOrder() { // Arrange var formatter = new SingleLineFormatter(); var startDateTime = DateTime.Now; var entries = new BaseEntry[] { new MethodEntry(1, "FirstMethod", null, startDateTime), new MethodEntry(2, "SecondMethod", null, startDateTime.AddSeconds(45)), new MethodEntry(3, "ThirdMethod", null, startDateTime.AddSeconds(75)), new MethodExit(3, "ThirdMethod", 100, false, null), new MethodExit(2, "SecondMethod", 178, false, null), new MethodExit(1, "FirstMethod", 200, false, null) }; var expectedText = (new string[] { string.Format("FirstMethod() started {0:HH:mm:ss.fff} duration 200ms", startDateTime), string.Format("SecondMethod() started {0:HH:mm:ss.fff} duration 178ms", startDateTime.AddSeconds(45)), string.Format("ThirdMethod() started {0:HH:mm:ss.fff} duration 100ms", startDateTime.AddSeconds(75)) } ).ToList(); List <String> output = new List <string>(); var filters = this.GetDefaultFilters(); var lineNo = 0; // Act foreach (var entry in entries) { if (entry is MethodEntry) { formatter.FormatMethodEntry(22, (entry as MethodEntry).StackLevel, ++lineNo, (MethodEntry)entry, filters, true); } else if (entry is MethodExit) { var result = formatter.FormatMethodExitForSingleLineOutput(22, (entry as MethodExit).StackLevel, lineNo, (MethodExit)entry, filters, true); if (result != null) { output.AddRange(result.Select(oo => oo.FormattedLine).ToArray()); } lineNo--; } } // Assert Assert.That(output.Count, Is.EqualTo(3), "Expected only three lines to be returned"); for (int index = 0; index < 3; index++) { Assert.That(output[index], Is.EqualTo(expectedText[index]), "Not the expected text for line {0}", index + 1); } }
public void FormatMethodEntry_ValidLog_NullIsReturned() { // Arrange var filters = this.GetDefaultFilters(); var formatter = new SingleLineFormatter(); var entry = new MethodEntry(1, "Yalf.TestMethod", new[] { "param1", "param2" }, DateTime.Parse("2022-10-22 22:22:31.678")); // Act var outputText = formatter.FormatMethodEntry(1, 2, 33, entry, filters, true); // Assert Assert.That(outputText, Is.Null, "Expected nothing to be returned for a method entry, everything is printed in the methodExit handling."); }
public void FormatMethodExit_NoEntryMethodSupplied_ExceptionIsThrown() { // Arrange var filters = this.GetDefaultFilters(); var formatter = new SingleLineFormatter(); var entry = new MethodExit(1, "Yalf.TestMethod", 345, true, "returnVal"); var relatedEntry = new MethodEntry(1, "Yalf.DifferentMethod", new[] { "param1", "param2" }, DateTime.Parse("2022-10-22 22:22:31.678")); formatter.FormatMethodEntry(1, 2, 33, relatedEntry, filters, true); // Act, Assert var outputText = formatter.FormatMethodExitForSingleLineOutput(1, 2, 33, entry, filters, true); }
/// <summary> /// Initializes a new instance of the <see cref="SignUpView"/> class. /// </summary> public SignUpView() { AvaloniaXamlLoader.Load(this); this.WhenActivated(disposables => { this.BindValidation(ViewModel, x => x.UserName, x => x.UserNameValidation.Text) .DisposeWith(disposables); this.BindValidation(ViewModel, x => x.Password, x => x.PasswordValidation.Text) .DisposeWith(disposables); this.BindValidation(ViewModel, x => x.ConfirmPassword, x => x.ConfirmPasswordValidation.Text) .DisposeWith(disposables); var newLineFormatter = new SingleLineFormatter(Environment.NewLine); this.BindValidation(ViewModel, x => x.CompoundValidation.Text, newLineFormatter) .DisposeWith(disposables); }); }
public void FormatMethodExit_HideMethodDurationIsSet_ExpectedTextIsReturned() { // Arrange var filters = LogFiltersBuilder.Create().WithMethodDurationHidden().Build(); var formatter = new SingleLineFormatter(); var entry = new MethodExit(1, "Yalf.TestMethod", 345, true, "returnVal"); var expectedText = "Yalf.TestMethod(returnVal) started 22:22:31.678"; var relatedEntry = new MethodEntry(1, "Yalf.TestMethod", new[] { "param1", "param2" }, DateTime.Parse("2022-10-22 22:22:31.678")); formatter.FormatMethodEntry(1, 2, 33, relatedEntry, filters, true); // Act var orderedOutput = formatter.FormatMethodExitForSingleLineOutput(1, 2, 33, entry, filters, true); // Assert Assert.That(orderedOutput.Count, Is.EqualTo(1), "Expected one string to be returned"); Assert.That(orderedOutput[0].Level, Is.EqualTo(0), "Not the expected nested level, you may need to adjust the test if the formatter has been changed."); Assert.That(orderedOutput[0].FormattedLine, Is.EqualTo(expectedText), "Not the expected formatted line, you may need to adjust the test if the formatter has been changed."); }
public void FormatMethodExit_ReturnRecordedIsFalse_ExpectedTextIsReturned() { // Arrange var filters = this.GetDefaultFilters(); var formatter = new SingleLineFormatter(); var entry = new MethodExit(1, "Yalf.TestMethod", 345, false, "returnVal"); var expectedText = "Yalf.TestMethod() started 22:22:31.678 duration 345ms"; var relatedEntry = new MethodEntry(1, "Yalf.TestMethod", new[] { "param1", "param2" }, DateTime.Parse("2022-10-22 22:22:31.678")); formatter.FormatMethodEntry(1, 2, 33, relatedEntry, filters, true); // Act var orderedOutput = formatter.FormatMethodExitForSingleLineOutput(1, 2, 33, entry, filters, true); // Assert Assert.That(orderedOutput.Count, Is.EqualTo(1), "Expected one string to be returned"); Assert.That(orderedOutput[0].Level, Is.EqualTo(0), "Not the expected nested level, you may need to adjust the test if the formatter has been changed."); Assert.That(orderedOutput[0].FormattedLine, Is.EqualTo(expectedText), "Not the expected formatted line, you may need to adjust the test if the formatter has been changed."); }
public void SingleLineFormatter_NestedMethodCallsWithSomeMethodsDisabled_ReportDoesNotHaveDisabledLogs() { // Arrange var formatter = new SingleLineFormatter(); var startDateTime = DateTime.Now; var entries = new Tuple <bool, BaseEntry>[] { new Tuple <bool, BaseEntry>(true, new MethodEntry(1, "TopLevelMethod", null, startDateTime)), new Tuple <bool, BaseEntry>(true, new MethodExit(1, "TopLevelMethod", 233, true, "blackSheep")), new Tuple <bool, BaseEntry>(true, new MethodEntry(1, "FirstMethod", null, startDateTime.AddSeconds(12))), new Tuple <bool, BaseEntry>(false, new MethodEntry(2, "SecondMethod", null, startDateTime.AddSeconds(45))), new Tuple <bool, BaseEntry>(true, new LogEvent(LogLevel.Info, startDateTime.AddSeconds(47), "Information log message here")), new Tuple <bool, BaseEntry>(true, new ExceptionTrace(new ArgumentNullException("lineNo", "Test the log"), startDateTime.AddSeconds(53))), new Tuple <bool, BaseEntry>(true, new MethodEntry(3, "ThirdMethod", null, startDateTime.AddSeconds(75))), new Tuple <bool, BaseEntry>(true, new MethodExit(3, "ThirdMethod", 100, false, null)), new Tuple <bool, BaseEntry>(false, new MethodEntry(3, "FourthMethod", null, startDateTime.AddSeconds(80))), new Tuple <bool, BaseEntry>(false, new MethodExit(3, "FourthMethod", 57, false, null)), new Tuple <bool, BaseEntry>(false, new MethodExit(2, "SecondMethod", 178, false, null)), new Tuple <bool, BaseEntry>(true, new MethodExit(1, "FirstMethod", 200, false, null)), new Tuple <bool, BaseEntry>(true, new MethodEntry(1, "TopLevelMethod2", null, startDateTime.AddSeconds(99))), new Tuple <bool, BaseEntry>(true, new MethodExit(1, "TopLevelMethod2", 488, true, "whiteSheep")), }; var expectedText = (new string[] { string.Format("TopLevelMethod(blackSheep) started {0:HH:mm:ss.fff} duration 233ms", startDateTime), string.Format("FirstMethod() started {0:HH:mm:ss.fff} duration 200ms", startDateTime.AddSeconds(12)), string.Format(" [Log] [Info] Information log message here"), string.Format(" [Exception] {0:HH:mm:ss.fff} Test the log", startDateTime.AddSeconds(53)), string.Format("Parameter name: lineNo"), string.Format(" ThirdMethod() started {0:HH:mm:ss.fff} duration 100ms", startDateTime.AddSeconds(75)), string.Format("TopLevelMethod2(whiteSheep) started {0:HH:mm:ss.fff} duration 488ms", startDateTime.AddSeconds(99)) } ).ToList(); var filters = this.GetDefaultFilters(); var indentLevel = 0; // Act var outputter = new DefaultOutputHandler(filters, formatter); outputter.Initialise(); foreach (var entry in entries) { if (entry.Item2 is MethodEntry) { outputter.HandleMethodEntry((entry.Item2 as MethodEntry), indentLevel, entry.Item1); ++indentLevel; } else if (entry.Item2 is MethodExit) { --indentLevel; outputter.HandleMethodExit((entry.Item2 as MethodExit), indentLevel, entry.Item1); } else if (entry.Item2 is LogEvent) { outputter.HandleLogEvent((entry.Item2 as LogEvent), indentLevel, entry.Item1); } else if (entry.Item2 is ExceptionTrace) { outputter.HandleException((entry.Item2 as ExceptionTrace), indentLevel); } } outputter.Complete(); var reportText = outputter.GetReport(); // Assert Console.WriteLine(reportText); List <String> output = reportText.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList(); Assert.That(output.Count, Is.EqualTo(expectedText.Count), "Expected {0} output lines, but have {1}", expectedText.Count, output.Count); Assert.That(reportText, Is.Not.Empty, "Expected report text to be returned."); for (int index = 0; index < expectedText.Count; index++) { Console.WriteLine("Checking actual\r\n\"{0}\" with expected\r\n\"{1}\"", output[index], expectedText[index]); Assert.That(output[index], Is.EqualTo(expectedText[index]), "Not the expected text for line {0}", index + 1); } }
public void SingleLineFormatter_NestedMethodCallsWithSomeMethodsDisabled_ReportDoesNotHaveDisabledLogs() { // Arrange var formatter = new SingleLineFormatter(); var startDateTime = DateTime.Now; var entries = new Tuple <bool, BaseEntry>[] { new Tuple <bool, BaseEntry>(true, new MethodEntry(1, "TopLevelMethod", null, startDateTime)), new Tuple <bool, BaseEntry>(true, new MethodExit(1, "TopLevelMethod", 233, true, "blackSheep")), new Tuple <bool, BaseEntry>(true, new MethodEntry(1, "FirstMethod", null, startDateTime.AddSeconds(12))), new Tuple <bool, BaseEntry>(false, new MethodEntry(2, "SecondMethod", null, startDateTime.AddSeconds(45))), new Tuple <bool, BaseEntry>(true, new LogEvent(LogLevel.Info, startDateTime.AddSeconds(47), "Information log message here")), new Tuple <bool, BaseEntry>(true, new ExceptionTrace(new ArgumentNullException("lineNo", "Test the log"), startDateTime.AddSeconds(53))), new Tuple <bool, BaseEntry>(true, new MethodEntry(3, "ThirdMethod", null, startDateTime.AddSeconds(75))), new Tuple <bool, BaseEntry>(true, new MethodExit(3, "ThirdMethod", 100, false, null)), new Tuple <bool, BaseEntry>(false, new MethodEntry(3, "FourthMethod", null, startDateTime.AddSeconds(80))), new Tuple <bool, BaseEntry>(false, new MethodExit(3, "FourthMethod", 57, false, null)), new Tuple <bool, BaseEntry>(false, new MethodExit(2, "SecondMethod", 178, false, null)), new Tuple <bool, BaseEntry>(true, new MethodExit(1, "FirstMethod", 200, false, null)), new Tuple <bool, BaseEntry>(true, new MethodEntry(1, "TopLevelMethod2", null, startDateTime.AddSeconds(99))), new Tuple <bool, BaseEntry>(true, new MethodExit(1, "TopLevelMethod2", 488, true, "whiteSheep")), }; var expectedText = (new string[] { string.Format("TopLevelMethod(blackSheep) started {0:HH:mm:ss.fff} duration 233ms", startDateTime), string.Format("FirstMethod() started {0:HH:mm:ss.fff} duration 200ms", startDateTime.AddSeconds(12)), string.Format(" [Log] [Info] Information log message here"), string.Format(" [Exception] {0:HH:mm:ss.fff} Test the log\r\nParameter name: lineNo", startDateTime.AddSeconds(53)), string.Format(" ThirdMethod() started {0:HH:mm:ss.fff} duration 100ms", startDateTime.AddSeconds(75)), string.Format("TopLevelMethod2(whiteSheep) started {0:HH:mm:ss.fff} duration 488ms", startDateTime.AddSeconds(99)) } ).ToList(); var filters = this.GetDefaultFilters(); var indentLevel = 0; int threadId = 22; var threadData = new ThreadData(threadId, "cotton", null); var outputter = new ThreadCollectionOutputHandler(filters, formatter); outputter.Initialise(); outputter.HandleThread(threadData); // Act foreach (var entry in entries) { if (entry.Item2 is MethodEntry) { outputter.HandleMethodEntry((entry.Item2 as MethodEntry), indentLevel, entry.Item1); ++indentLevel; } else if (entry.Item2 is MethodExit) { --indentLevel; outputter.HandleMethodExit((entry.Item2 as MethodExit), indentLevel, entry.Item1); } else if (entry.Item2 is LogEvent) { outputter.HandleLogEvent((entry.Item2 as LogEvent), indentLevel, entry.Item1); } else if (entry.Item2 is ExceptionTrace) { outputter.HandleException((entry.Item2 as ExceptionTrace), indentLevel); } } outputter.Complete(); // Assert var reportText = outputter.GetThreadEntries(); Assert.That(reportText.Count, Is.EqualTo(1), "Expected one thread collection"); var output = reportText[threadId]; Assert.That(output.Count, Is.EqualTo(expectedText.Count), "Expected {0} output lines, but have {1}\n{2}", expectedText.Count, output.Count, this.CreateComparisonReport(output, expectedText)); for (int index = 0; index < expectedText.Count; index++) { Assert.That(output[index], Is.EqualTo(expectedText[index]), "Not the expected text for line {0}\n\n{1}", index + 1, this.CreateComparisonReport(output, expectedText)); } }
public void FormatMethodExit_MixedNestting_ExpectedTextIsReturned() { // Arrange var filters = LogFiltersBuilder.Create().Build(); var formatter = new SingleLineFormatter(); var startDateTime = DateTime.Now; int threadId = 22; int lineNo = 0; int indentLevel = 0; var expectedText = (new string[] { string.Format("TopLevelMethod(blackSheep) started {0:HH:mm:ss.fff} duration 233ms", startDateTime), string.Format("FirstMethod() started {0:HH:mm:ss.fff} duration 200ms", startDateTime.AddSeconds(12)), string.Format("SecondMethod() started {0:HH:mm:ss.fff} duration 178ms", startDateTime.AddSeconds(45)), string.Format("[Log] [Info] Information log message here"), string.Format("[Exception] {0:HH:mm:ss.fff} Test the log\r\nParameter name: lineNo", startDateTime.AddSeconds(53)), string.Format("ThirdMethod() started {0:HH:mm:ss.fff} duration 100ms", startDateTime.AddSeconds(75)), string.Format("TopLevelMethod2(whiteSheep) started {0:HH:mm:ss.fff} duration 488ms", startDateTime.AddSeconds(99)) } ).ToList(); var entries = new BaseEntry[] { new MethodEntry(1, "TopLevelMethod", null, startDateTime), new MethodExit(1, "TopLevelMethod", 233, true, "blackSheep"), new MethodEntry(1, "FirstMethod", null, startDateTime.AddSeconds(12)), new MethodEntry(2, "SecondMethod", null, startDateTime.AddSeconds(45)), new LogEvent(LogLevel.Info, startDateTime.AddSeconds(47), "Information log message here"), new ExceptionTrace(new ArgumentNullException("lineNo", "Test the log"), startDateTime.AddSeconds(53)), new MethodEntry(3, "ThirdMethod", null, startDateTime.AddSeconds(75)), new MethodExit(3, "ThirdMethod", 100, false, null), new MethodExit(2, "SecondMethod", 178, false, null), new MethodExit(1, "FirstMethod", 200, false, null), new MethodEntry(1, "TopLevelMethod2", null, startDateTime.AddSeconds(99)), new MethodExit(1, "TopLevelMethod2", 488, true, "whiteSheep"), }; var actualText = new List <String>(); // Act foreach (var entry in entries) { if (entry is MethodEntry) { formatter.FormatMethodEntry(threadId, indentLevel++, ++lineNo, (entry as MethodEntry), filters, true); } else if (entry is MethodExit) { var result = formatter.FormatMethodExitForSingleLineOutput(threadId, indentLevel--, lineNo++, (entry as MethodExit), filters, true); if (result != null) { actualText.AddRange(result.Select(oo => oo.FormattedLine).ToList()); } } else if (entry is LogEvent) { var result = formatter.FormatLogEvent(threadId, indentLevel, lineNo++, (entry as LogEvent), filters, true); if (result != null) { actualText.Add(result); } } else if (entry is ExceptionTrace) { var result = formatter.FormatException(threadId, indentLevel, lineNo++, (entry as ExceptionTrace), filters); if (result != null) { actualText.Add(result); } } } // Assert Assert.That(actualText.Count, Is.EqualTo(expectedText.Count), "Expected {0} lines to be returned overall, but have {1}.", expectedText.Count, actualText.Count); var misMatchedResults = actualText.Where((at, i) => (at != expectedText[i])); Assert.That(misMatchedResults.Count(), Is.EqualTo(0), "{0} of the lines do not match.\nExpected:\n{1}\n\nActual:\n{2}" , misMatchedResults.Count() , String.Join(Environment.NewLine, expectedText.ToArray()) , String.Join(Environment.NewLine, actualText.ToArray()) ); }