public void FailedScope_ResultAndFailureDescription_ShouldOutputValueInLogEvent() { FailOnErrors = false; UnitTestTimedScopeLogger unitTestTimedScopeLogger = new UnitTestTimedScopeLogger(); Mock <IReplayEventConfigurator> replyEventConfiguratorMock = new Mock <IReplayEventConfigurator>(); Mock <ICallContextManager> callContextManagerMock = new Mock <ICallContextManager>(); IMachineInformation machineInformation = new UnitTestMachineInformation(); ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(callContextManagerMock.Object, machineInformation); using (TimedScope scope = TestHooks.CreateTestCountersUnitTestTimedScope(machineInformation: machineInformation, scopeLogger: unitTestTimedScopeLogger, replayEventConfigurator: replyEventConfiguratorMock.Object, timedScopeStackManager: timedScopeStackManager)) { scope.Result = TimedScopeResult.ExpectedError; scope.FailureDescription = UnitTestFailureDescription.ExampleDescription; } TimedScopeLogEvent scopeEvent = unitTestTimedScopeLogger.Events.SingleOrDefault(); if (VerifyNotNullAndReturn(scopeEvent, "Scope end event should be logged")) { Assert.Equal(scopeEvent.Result, TimedScopeResult.ExpectedError); Assert.Equal(scopeEvent.FailureDescription, UnitTestFailureDescription.ExampleDescription.ToString()); } }
public void FailedTimedScope_ShouldReplayLogs() { Mock<ITimedScopeLogger> timedScopeLoggerMock = new Mock<ITimedScopeLogger>(); Mock<IReplayEventConfigurator> replyEventConfiguratorMock = new Mock<IReplayEventConfigurator>(); Mock<ILogEventCache> mockCache = new Mock<ILogEventCache>(); Correlation = new Correlation(new MemoryCorrelationHandler(), CallContextManagerInstance, MachineInformation); Correlation.CorrelationStart(new CorrelationData(mockCache.Object)); IMachineInformation machineInformation = new UnitTestMachineInformation(); ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(CallContextManagerInstance, machineInformation); CorrelationData currentCorrelation = Correlation.CurrentCorrelation; Assert.False(currentCorrelation.ShouldReplayUls, "Logs shouldn't be replayed"); using (TimedScope scope = TestHooks.CreateDefaultTimedScope( timedScopeLoggerMock.Object, replyEventConfiguratorMock.Object, machineInformation, timedScopeStackManager, startScope: true)) { scope.Result = TimedScopeResult.SystemError; Mock<IReplayEventDisabledTimedScopes> disabledScopes = new Mock<IReplayEventDisabledTimedScopes>(); disabledScopes.Setup(x => x.IsDisabled(scope.ScopeDefinition)).Returns(false); ReplayEventConfigurator configurator = new ReplayEventConfigurator(disabledScopes.Object, Correlation); configurator.ConfigureReplayEventsOnScopeEnd(scope); } Assert.True(currentCorrelation.ShouldReplayUls, "Logs should be replayed"); }
public void AddLoggingValue_ShouldOutputValueInLogEvent() { Mock <ITimedScopeLogger> timedScopeLoggerMock = new Mock <ITimedScopeLogger>(); Mock <IReplayEventConfigurator> replyEventConfiguratorMock = new Mock <IReplayEventConfigurator>(); Mock <ICallContextManager> callContextManagerMock = new Mock <ICallContextManager>(); IMachineInformation machineInformation = new UnitTestMachineInformation(); ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(callContextManagerMock.Object, machineInformation); using (TimedScope scope = TestHooks.CreateTestCountersUnitTestTimedScope(machineInformation: machineInformation, scopeLogger: timedScopeLoggerMock.Object, replayEventConfigurator: replyEventConfiguratorMock.Object, timedScopeStackManager: timedScopeStackManager)) { scope.AddLoggingValue(TimedScopeDataKeys.Category, "MyCategory"); scope.End(); // There should be one 'Ending' transaction log call with formatted output foreach (LogEventArgs args in LoggedEvents) { if (args.CategoryId == Categories.TimingGeneral) { if (args.FullMessage.Contains("Ending timed scope")) { Assert.Contains("Category:'MyCategory';", args.FullMessage, StringComparison.Ordinal); } } } } }
public void End_WithDisposedTimedScope_ShouldLogError() { FailOnErrors = false; Mock <ITimedScopeLogger> timedScopeLoggerMock = new Mock <ITimedScopeLogger>(); Mock <IReplayEventConfigurator> replyEventConfiguratorMock = new Mock <IReplayEventConfigurator>(); Mock <ICallContextManager> callContextManagerMock = new Mock <ICallContextManager>(); IMachineInformation machineInformation = new UnitTestMachineInformation(); ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(callContextManagerMock.Object, machineInformation); using (TimedScope scope = TestHooks.CreateDefaultTimedScope(timedScopeLoggerMock.Object, replyEventConfiguratorMock.Object, machineInformation, timedScopeStackManager)) { Assert.True(scope.IsScopeActive, "Timer should be active."); scope.Dispose(); Assert.False(scope.IsScopeActive, "Dispose should turn off timer."); scope.End(); Assert.Equal(TraceErrors.Count(), 1); LoggedEvents.Clear(); } }
public void DefaultTimedScopeResult_LogsAsSystemError() { LoggedEvents.Clear(); CorrelationData data = new CorrelationData(); UnitTestTimedScopeLogger unitTestTimedScopeLogger = new UnitTestTimedScopeLogger(); Mock <IReplayEventConfigurator> replyEventConfiguratorMock = new Mock <IReplayEventConfigurator>(); Mock <ICallContextManager> callContextManagerMock = new Mock <ICallContextManager>(); IMachineInformation machineInformation = new UnitTestMachineInformation(); ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(callContextManagerMock.Object, machineInformation); using (TestHooks.CreateTimedScopeProvider(machineInformation, unitTestTimedScopeLogger, replyEventConfiguratorMock.Object, timedScopeStackManager) .Create(new TimedScopeDefinition(TestHooks.DefaultTimedScopeName, "description"), TimedScopeResult.SystemError)) { } TimedScopeLogEvent evt = unitTestTimedScopeLogger.SingleTimedScopeEvent(TestHooks.DefaultTimedScopeName); if (VerifyNotNullAndReturn(evt, "A scope event has been logged")) { Assert.Equal(TimedScopeResult.SystemError, evt.Result); } }
public void ThenICloseAndReopenTheApp() { // Mocking Relaunching of the app TestHooks hooks = new TestHooks(); hooks.BeforeScenario(); // App Relaunched }
private static Participant DoADLookup(IExchangePrincipal exchangePrincipal, Participant participant) { if (TestHooks.EmailAddressConverter_ADLookup != null) { return(TestHooks.EmailAddressConverter_ADLookup(participant)); } Participant[] array = Participant.TryConvertTo(new Participant[] { participant }, "SMTP", exchangePrincipal, null); if (array == null || array.Length == 0) { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.CommonTracer, null, ("Convert to SMTP failed. Received null smtpParticipant for participant: " + participant.EmailAddress) ?? "<NULL>"); return(null); } return(array[0]); }
public void AbortTimer_ShouldDisableTimerActive() { Mock <ITimedScopeLogger> timedScopeLoggerMock = new Mock <ITimedScopeLogger>(); Mock <IReplayEventConfigurator> replyEventConfiguratorMock = new Mock <IReplayEventConfigurator>(); Mock <ICallContextManager> callContextManagerMock = new Mock <ICallContextManager>(); IMachineInformation machineInformation = new UnitTestMachineInformation(); ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(callContextManagerMock.Object, machineInformation); using (TimedScope scope = TestHooks.CreateDefaultTimedScope(timedScopeLoggerMock.Object, replyEventConfiguratorMock.Object, machineInformation: machineInformation, timedScopeStackManager: timedScopeStackManager)) { Assert.True(scope.IsScopeActive, "Default scope should have timer active."); scope.AbortTimer(); Assert.False(scope.IsScopeActive, "Aborting timer should stop timer."); } }
public void Create_ShouldConstructTimedScope_WithTimerInactive() { Mock <ITimedScopeLogger> timedScopeLoggerMock = new Mock <ITimedScopeLogger>(); Mock <IReplayEventConfigurator> replyEventConfiguratorMock = new Mock <IReplayEventConfigurator>(); Mock <ICallContextManager> callContextManagerMock = new Mock <ICallContextManager>(); IMachineInformation machineInformation = new UnitTestMachineInformation(); ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(callContextManagerMock.Object, machineInformation); using (TimedScope scope = TestHooks.CreateTestCountersUnitTestTimedScope(true, false, machineInformation, timedScopeLoggerMock.Object, replyEventConfiguratorMock.Object, timedScopeStackManager)) { Assert.False(scope.IsScopeActive, "Creating a scope should not start the timer."); Assert.True(scope.IsSuccessful.HasValue, "IsSuccessful should be set."); Assert.True(scope.IsSuccessful.Value, "IsSuccessful should be set to true."); } }
public void AddLoggingValue_WithNullKey_ShouldLogError() { FailOnErrors = false; Mock <ITimedScopeLogger> timedScopeLoggerMock = new Mock <ITimedScopeLogger>(); Mock <IReplayEventConfigurator> replyEventConfiguratorMock = new Mock <IReplayEventConfigurator>(); Mock <ICallContextManager> callContextManagerMock = new Mock <ICallContextManager>(); IMachineInformation machineInformation = new UnitTestMachineInformation(); ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(callContextManagerMock.Object, machineInformation); using (TimedScope scope = TestHooks.CreateDefaultTimedScope(timedScopeLoggerMock.Object, replyEventConfiguratorMock.Object, machineInformation, timedScopeStackManager)) { scope.AddLoggingValue(null, "My Application."); Assert.Equal(TraceErrors.Count(), 1); LoggedEvents.Clear(); } }
public void Start_DisposedTimedScope_ShoudLogError() { FailOnErrors = false; Mock <ITimedScopeLogger> timedScopeLoggerMock = new Mock <ITimedScopeLogger>(); Mock <IReplayEventConfigurator> replyEventConfiguratorMock = new Mock <IReplayEventConfigurator>(); Mock <ICallContextManager> callContextManagerMock = new Mock <ICallContextManager>(); IMachineInformation machineInformation = new UnitTestMachineInformation(); ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(callContextManagerMock.Object, machineInformation); TimedScope scope = TestHooks.CreateDefaultTimedScope(timedScopeLoggerMock.Object, replyEventConfiguratorMock.Object, machineInformation, timedScopeStackManager); scope.Dispose(); scope.Start(); Assert.Equal(TraceErrors.Count(), 1); LoggedEvents.Clear(); }
public void Scope_TimedScopeLogger_IsCalled() { Mock <ITimedScopeLogger> timedScopeLoggerMock = new Mock <ITimedScopeLogger>(); Mock <IReplayEventConfigurator> replyEventConfiguratorMock = new Mock <IReplayEventConfigurator>(); Mock <ICallContextManager> callContextManagerMock = new Mock <ICallContextManager>(); IMachineInformation machineInformation = new UnitTestMachineInformation(); ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(callContextManagerMock.Object, machineInformation); TimedScope scope; CorrelationData data = new CorrelationData(); using (scope = TestHooks.CreateTimedScopeProvider(machineInformation, timedScopeLoggerMock.Object, replyEventConfiguratorMock.Object, timedScopeStackManager) .Create(new TimedScopeDefinition("TestScope"), TimedScopeResult.SystemError)) { timedScopeLoggerMock.Verify(x => x.LogScopeStart(scope), Times.Once); timedScopeLoggerMock.Verify(x => x.LogScopeEnd(scope, It.IsAny <CorrelationData>()), Times.Never); } timedScopeLoggerMock.Verify(x => x.LogScopeEnd(scope, It.IsAny <CorrelationData>()), Times.Once); }
public void NotSettingTimedScopeResult_ChangesToSystemError() { LoggedEvents.Clear(); UnitTestTimedScopeLogger unitTestTimedScopeLogger = new UnitTestTimedScopeLogger(); Mock <IReplayEventConfigurator> replyEventConfiguratorMock = new Mock <IReplayEventConfigurator>(); Mock <ICallContextManager> callContextManagerMock = new Mock <ICallContextManager>(); IMachineInformation machineInformation = new UnitTestMachineInformation(); ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(callContextManagerMock.Object, machineInformation); using (TimedScope scope = TestHooks.CreateDefaultTimedScope(unitTestTimedScopeLogger, replyEventConfiguratorMock.Object, machineInformation, timedScopeStackManager)) { } TimedScopeLogEvent evt = unitTestTimedScopeLogger.SingleTimedScopeEvent(TestHooks.DefaultTimedScopeName); if (VerifyNotNullAndReturn(evt, "A scope event has been logged")) { Assert.Equal(evt.Result, TimedScopeResult.SystemError); } }
public void SucceededScope_Result_ShouldOutputValueInLogEvent() { UnitTestTimedScopeLogger unitTestTimedScopeLogger = new UnitTestTimedScopeLogger(); Mock <IReplayEventConfigurator> replyEventConfiguratorMock = new Mock <IReplayEventConfigurator>(); Mock <ICallContextManager> callContextManagerMock = new Mock <ICallContextManager>(); IMachineInformation machineInformation = new UnitTestMachineInformation(); ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(callContextManagerMock.Object, machineInformation); using (TimedScope scope = TestHooks.CreateTestCountersUnitTestTimedScope(machineInformation: machineInformation, scopeLogger: unitTestTimedScopeLogger, replayEventConfigurator: replyEventConfiguratorMock.Object, timedScopeStackManager: timedScopeStackManager)) { scope.Result = TimedScopeResult.Success; } TimedScopeLogEvent scopeEvent = unitTestTimedScopeLogger.Events.SingleOrDefault(); if (VerifyNotNullAndReturn(scopeEvent, "Timed scope should be logged")) { Assert.Equal(scopeEvent.Result, TimedScopeResult.Success); } }
/// <summary> /// Deletes a given array files in parallel. /// Deletion failures are handled gracefully (by logging a warning). /// Returns the number of successfully deleted files. /// </summary> public int DeleteFiles( IReadOnlyList <string> filePaths, bool logDeletedFiles = true, TestHooks testHook = null) { int numRemoved = 0; using (var timer = new Timer( _ => Tracing.Logger.Log.ScrubbingProgress(m_loggingContext, "", numRemoved, filePaths.Count), null, dueTime: m_loggingConfiguration.GetTimerUpdatePeriodInMs(), period: m_loggingConfiguration.GetTimerUpdatePeriodInMs())) { try { filePaths .AsParallel() .WithDegreeOfParallelism(m_maxDegreeParallelism) .WithCancellation(m_cancellationToken) .ForAll(path => { testHook?.OnDeletion?.Invoke(path, numRemoved); if (!m_cancellationToken.IsCancellationRequested && FileUtilities.FileExistsNoFollow(path) && TryDeleteFile(m_loggingContext, path, logDeletedFiles)) { Interlocked.Increment(ref numRemoved); } }); Tracing.Logger.Log.ScrubbingFinished(m_loggingContext, 0, filePaths.Count, numRemoved, 0); } catch (OperationCanceledException) { Tracing.Logger.Log.ScrubbingCancelled(m_loggingContext, filePaths.Count, numRemoved); } return(numRemoved); } }
public void AbortTimer_ShouldDisableTimerActive_AndSetResultsToFalse() { Mock <ITimedScopeLogger> timedScopeLoggerMock = new Mock <ITimedScopeLogger>(); Mock <IReplayEventConfigurator> replyEventConfiguratorMock = new Mock <IReplayEventConfigurator>(); Mock <ICallContextManager> callContextManagerMock = new Mock <ICallContextManager>(); IMachineInformation machineInformation = new UnitTestMachineInformation(); ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(callContextManagerMock.Object, machineInformation); using (TimedScope scope = TestHooks.CreateDefaultTimedScope(scopeLogger: timedScopeLoggerMock.Object, replayEventConfigurator: replyEventConfiguratorMock.Object, machineInformation: machineInformation, timedScopeStackManager: timedScopeStackManager, startScope: false)) { Assert.False(scope.IsScopeActive, "Default scope started without an active scope should have timer active."); scope.Start(); Assert.True(scope.IsScopeActive, "Default scope should have timer active."); scope.AbortTimer(false); Assert.False(scope.IsScopeActive, "Aborting timer should stop timer."); Assert.True(scope.IsSuccessful.HasValue, "IsSuccessful should be set."); Assert.False(scope.IsSuccessful.Value, "IsSuccesful should be set to false."); } }
public void Object_EqualsがIEquitableT_Equalsに移譲される() { const string source = @" using System; using Aetos.ComparisonGenerator; using Aetos.ComparisonGenerator.IntegrationTests.Injection; [Comparable] public partial class Person : IEquatable<Person> { private readonly ITestHooks _hooks; public Person( ITestHooks hooks) { this._hooks = hooks; } [CompareBy(Order = 0)] public string FirstName { get; set; } [CompareBy(Order = 1)] public string LastName { get; set; } bool IEquatable<Person>.Equals( Person? other) { return this._hooks.EqualsHook(this, other); } }"; var options = new GenerateOptions( overrideObjectMethods: true, generateEquatable: false); var generator = new ComparableObjectGenerator(options); var assembly = RunGeneratorAndGenerateAssembly( generator, source, out _); Assert.That(assembly, Is.Not.Null); var type = assembly.GetType("Person"); Assert.That(type, Is.Not.Null); var equals = GetMethod(type, "Equals", typeof(object)); Assert.That(equals, Is.Not.Null); var hook = Substitute.For <ITestHooks>(); var hook2 = new TestHooks(hook); var instance = Activator.CreateInstance(type, hook2); hook .EqualsHook(Arg.Any <object>(), Arg.Any <object>()) .Returns(true); var result = equals.Invoke(instance, new[] { instance }); Assert.That(result, Is.True); hook.Received().EqualsHook(Arg.Any <object>(), Arg.Any <object>()); }