public void TestInitialise() { _OriginalClassFactory = Factory.TakeSnapshot(); _HeartbeatService = TestUtilities.CreateMockSingleton<IHeartbeatService>(); _StandingDataManager = TestUtilities.CreateMockSingleton<IStandingDataManager>(); _StandingDataManager.Setup(r => r.FindCodeBlock(It.IsAny<string>())).Returns(new CodeBlock() { Country = "X" }); _StandingDataManager.Setup(r => r.CodeBlocksLoaded).Returns(true); _Statistics = Factory.Singleton.Resolve<IStatistics>().Singleton; _Statistics.Initialise(); _Statistics.ResetConnectionStatistics(); _Statistics.ResetMessageCounters(); _Translator = Factory.Singleton.Resolve<IRawMessageTranslator>(); _Provider = new Mock<IRawMessageTranslatorProvider>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Provider.Setup(r => r.UtcNow).Returns(new DateTime(1999, 12, 31)); _Translator.Provider = _Provider.Object; _PositionResetEvent = new EventRecorder<EventArgs<string>>(); _Translator.PositionReset += _PositionResetEvent.Handler; _NowUtc = new DateTime(2012, 1, 2, 3, 4, 5, 6); _ModeSMessage = new ModeSMessage() { DownlinkFormat = DownlinkFormat.AllCallReply, Icao24 = 0x112233, ParityInterrogatorIdentifier = 0 }; _AdsbMessage = new AdsbMessage(_ModeSMessage); _RandomIcaos = new List<int>(); }
private static EventRecorder[] BuildRecorders(object eventSource) { var eventRecorder = new EventRecorder(eventSource, PropertyChangedEventName); ((INotifyPropertyChanged)eventSource).PropertyChanged += (sender, args) => eventRecorder.RecordEvent(sender, args); return(new[] { eventRecorder }); }
public void Raise_Exception_Thrown_In_Handler_Does_Not_Stop_Event_Propagation_When_Exception_Callback_Supplied() { var recorder1 = new EventRecorder <EventArgs>(); var recorder2 = new EventRecorder <EventArgs>(); _Raise_Exception_Thrown_In_Handler_Does_Not_Stop_Event_Propagation_When_Exception_Callback_Supplied += recorder1.Handler; _Raise_Exception_Thrown_In_Handler_Does_Not_Stop_Event_Propagation_When_Exception_Callback_Supplied += recorder2.Handler; var exception1 = new Exception("1"); var exception2 = new Exception("2"); recorder1.EventRaised += (sender, args) => { throw exception1; }; recorder2.EventRaised += (sender, args) => { throw exception2; }; var seenException1 = false; var seenException2 = false; EventHelper.Raise(_Raise_Exception_Thrown_In_Handler_Does_Not_Stop_Event_Propagation_When_Exception_Callback_Supplied, new object(), EventArgs.Empty, ex => { if (Object.ReferenceEquals(ex, exception1)) { seenException1 = true; } else if (Object.ReferenceEquals(ex, exception2)) { seenException2 = true; } }); Assert.IsTrue(seenException1); Assert.IsTrue(seenException2); Assert.AreEqual(1, recorder1.CallCount); Assert.AreEqual(1, recorder2.CallCount); }
public void TestInitialise() { _OriginalFactory = Factory.TakeSnapshot(); _ConfigurationStorage = TestUtilities.CreateMockSingleton<IConfigurationStorage>(); _Configuration = new Configuration(); _ConfigurationStorage.Setup(cs => cs.Load()).Returns(_Configuration); _Log = TestUtilities.CreateMockSingleton<ILog>(); _HeartbeatService = TestUtilities.CreateMockSingleton<IHeartbeatService>(); _WebServer = new Mock<IWebServer>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _AutoConfigWebServer = TestUtilities.CreateMockSingleton<IAutoConfigWebServer>(); _AutoConfigWebServer.Setup(s => s.WebServer).Returns(_WebServer.Object); _UPnpManager = new Mock<IUniversalPlugAndPlayManager>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _NewVersionChecker = TestUtilities.CreateMockSingleton<INewVersionChecker>(); _HeartbeatTick = new EventRecorder<EventArgs>(); _BaseStationAircraftList = new Mock<IBaseStationAircraftList>(); _PluginManager = TestUtilities.CreateMockSingleton<IPluginManager>(); _RebroadcastServerManager = TestUtilities.CreateMockSingleton<IRebroadcastServerManager>(); _SelfConfiguringListener = TestUtilities.CreateMockSingleton<IAutoConfigListener>(); _Listener = new Mock<IListener>(MockBehavior.Default) { DefaultValue = DefaultValue.Mock }; _SelfConfiguringListener.Setup(r => r.Listener).Returns(_Listener.Object); _Presenter = Factory.Singleton.Resolve<IMainPresenter>(); _Provider = new Mock<IMainPresenterProvider>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Provider.Setup(p => p.UtcNow).Returns(DateTime.UtcNow); _Presenter.Provider = _Provider.Object; _View = new Mock<IMainView>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); }
public void RemovePage_LastPage() { var eventRecorder = new EventRecorder(); var contentPageMock1 = new ContentPageMock(eventRecorder); var navigationPage = new NavigationPage(contentPageMock1); navigationPage.Behaviors.Add(new NavigationPageBehavior()); var contentPageMock2 = new ContentPageMock(eventRecorder); contentPageMock1.Navigation.PushAsync(contentPageMock2); var navigator = new Navigator(contentPageMock2); navigator.RemovePage(contentPageMock2); Assert.Equal(contentPageMock1, navigationPage.CurrentPage); Assert.Equal(2, eventRecorder.Count); Assert.Equal(contentPageMock1, eventRecorder[0].Sender); Assert.Equal("OnLoaded", eventRecorder[0].CallerMemberName); Assert.Null(eventRecorder[0].Parameter); Assert.Equal(contentPageMock2, eventRecorder[1].Sender); Assert.Equal("OnClosed", eventRecorder[1].CallerMemberName); Assert.Null(eventRecorder[1].Parameter); }
public void TestInitialise() { _ClassFactorySnapshot = Factory.TakeSnapshot(); _HeartbeatService = TestUtilities.CreateMockSingleton <IHeartbeatService>(); _WebServer = new Mock <IWebServer>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _LogDatabase = new Mock <ILogDatabase>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _LogSession = new Mock <LogSession>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _ExceptionCaughtEvent = new EventRecorder <EventArgs <Exception> >(); _Clock = new ClockMock(); Factory.Singleton.RegisterInstance <IClock>(_Clock.Object); _ConnectionLogger = Factory.Singleton.Resolve <IConnectionLogger>(); _ConnectionLogger.WebServer = _WebServer.Object; _ConnectionLogger.LogDatabase = _LogDatabase.Object; }
public void OnCurrentPageChanged() { var eventRecoder = new EventRecorder(); var contentPageMock1 = new ContentPageMock(eventRecoder) { Title = "contentPageMock1" }; var contentPageMock2 = new ContentPageMock(eventRecoder) { Title = "contentPageMock2" }; var tabbedPageMock = new TabbedPageMock(eventRecoder); tabbedPageMock.Children.Add(contentPageMock1); tabbedPageMock.Children.Add(contentPageMock2); tabbedPageMock.Behaviors.Add(new MultiPageBehavior <Page>()); tabbedPageMock.CurrentPage = contentPageMock2; Assert.Equal(2, eventRecoder.Count); Assert.NotNull(eventRecoder[0]); Assert.Equal(contentPageMock2, eventRecoder[0].Sender); Assert.Equal("OnLoaded", eventRecoder[0].CallerMemberName); Assert.Null(eventRecoder[0].Parameter); Assert.NotNull(eventRecoder[1]); Assert.Equal(contentPageMock1, eventRecoder[1].Sender); Assert.Equal("OnUnloaded", eventRecoder[1].CallerMemberName); Assert.Null(eventRecoder[1].Parameter); }
public async Task PopToRootAsync_WhenParentIsNotNavigationPage() { var eventRecorder = new EventRecorder(); var contentPageMock1 = new ContentPageMock(eventRecorder) { Title = "contentPageMock1" }; var contentPageMock2 = new ContentPageMock(eventRecorder) { Title = "contentPageMock2" }; var contentPageMock3 = new ContentPageMock(eventRecorder) { Title = "contentPageMock3" }; var tabbedPage = new TabbedPage(); tabbedPage.Children.Add(contentPageMock1); tabbedPage.Children.Add(contentPageMock2); tabbedPage.Children.Add(contentPageMock3); var navigationMock = new Mock <INavigation>(); var navigator = new Navigator(contentPageMock3, navigationMock.Object); await navigator.PopToRootAsync(); Assert.Equal(0, eventRecorder.Count); navigationMock.Verify(m => m.PopToRootAsync(It.IsAny <bool>()), Times.Never); }
public void TestInitialise() { _OriginalFactory = Factory.TakeSnapshot(); _Clock = new ClockMock(); Factory.RegisterInstance <IClock>(_Clock.Object); _HeartbeatService = TestUtilities.CreateMockSingleton <IHeartbeatService>(); _RuntimeEnvironment = TestUtilities.CreateMockSingleton <IRuntimeEnvironment>(); _RuntimeEnvironment.Setup(r => r.IsTest).Returns(true); _MergedFeed = Factory.Resolve <IMergedFeedListener>(); _Listener1 = TestUtilities.CreateMockInstance <IListener>(); _Listener1.Setup(r => r.ReceiverId).Returns(1); _Listener2 = TestUtilities.CreateMockInstance <IListener>(); _Listener2.Setup(r => r.ReceiverId).Returns(2); _Listeners = new List <IListener>(new IListener[] { _Listener1.Object, _Listener2.Object }); _Component1 = TestUtilities.CreateMockInstance <IMergedFeedComponentListener>(); _Component1.Setup(r => r.Listener).Returns(_Listener1.Object); _Component2 = TestUtilities.CreateMockInstance <IMergedFeedComponentListener>(); _Component2.Setup(r => r.Listener).Returns(_Listener2.Object); _Components = new List <IMergedFeedComponentListener>(new IMergedFeedComponentListener[] { _Component1.Object, _Component2.Object }); _BaseStationMessageEventRecorder = new EventRecorder <BaseStationMessageEventArgs>(); _PositionResetRecorder = new EventRecorder <EventArgs <string> >(); _ExceptionCaughtRecorder = new EventRecorder <EventArgs <Exception> >(); }
public void RaceConditionTest() { var correctObject = new object(); var eventRecorder = new EventRecorder(); var test = new TestClass(); test.SetEventRecorder(eventRecorder); for (int i = 0; i < 1000; i++) { test.Write(correctObject); var assertTask = Task.Run(() => { var actualObj = test.Read(); if (eventRecorder.Events.StartsWith("WriteRead")) { Assert.True(object.ReferenceEquals(correctObject, actualObj), $"Failed on {i} iteration"); } }); var failTask = Task.Run(() => test.Write(new object())); Task.WaitAll(assertTask, failTask); eventRecorder.Reset(); } }
/// <summary> /// Batch job to send all of the nightly/monthly email. /// </summary> public async void NightlyRun() { EventRecorder.LogCall("Starting nightly run"); try { if (ActiveBrand == null) { ActiveBrand = Branding.CurrentBrand; } if (TasksToRun == SelectedTasks.All || TasksToRun == SelectedTasks.EmailOnly) { SendNightlyEmails(); } // Do any Cloud Storage updates if (TasksToRun == SelectedTasks.All || TasksToRun == SelectedTasks.CloudStorageOnly) { await BackupToCloud().ConfigureAwait(false); // we have no httpcontext.current, so no need to save } // Send out any notices of pending gratuity expirations EarnedGratuity.SendRemindersOfExpiringGratuities(UserRestriction); if (DateTime.Now.Day == 1) { Clubs.Club.SendMonthlyClubReports(); } } catch (Exception ex) when(!(ex is OutOfMemoryException)) { EventRecorder.LogCall("Nightly run had exception: {msg}, {stacktrace} ", ex.Message, ex.StackTrace); } EventRecorder.LogCall("Ended nightly run"); }
private static EventRecorder[] BuildRecorders(INotifyPropertyChanged eventSource) { var eventRecorder = new EventRecorder(eventSource, "PropertyChanged"); eventSource.PropertyChanged += (sender, args) => eventRecorder.RecordEvent(sender, args); return(new[] { eventRecorder }); }
public void Dispose() { using var src = new EventSource <String>(); var rec = EventRecorder.From(src.Event); src.Invoke("aaa"); rec.Dispose(); src.Invoke("bbb"); Check.That(rec.Count) .IsEqualTo(1); Check.That(rec.Events) .ContainsExactly("aaa"); Check.That(rec.EventInfos) .HasSize(1); var info1 = rec.EventInfos[0]; Check.That(info1.Value) .IsEqualTo("aaa"); Check.That(info1.Index) .IsEqualTo(0); Check.That(info1.Timestamp - DateTimeOffset.Now) .IsLessThan(TimeSpan.FromMilliseconds(500)); Check.That(info1.TimeOffset) .IsEqualTo(TimeSpan.Zero); Check.That(info1.Thread) .IsEqualTo(Thread.CurrentThread); }
public void TestInitialise() { _OriginalFactory = Factory.TakeSnapshot(); _RuntimeEnvironment = TestUtilities.CreateMockSingleton <IRuntimeEnvironment>(); _ConfigurationStorage = TestUtilities.CreateMockSingleton <IConfigurationStorage>(); _Configuration = new Configuration(); _ConfigurationStorage.Setup(c => c.Load()).Returns(_Configuration); _PortMappings = new List <IPortMapping>(); _Manager = Factory.Resolve <IUniversalPlugAndPlayManager>(); _Provider = new Mock <IUniversalPlugAndPlayManagerProvider>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Provider.Setup(p => p.GetPortMappings()).Returns(_PortMappings); _Manager.Provider = _Provider.Object; _WebServer = new Mock <IWebServer>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Manager.WebServer = _WebServer.Object; _StateChangedEvent = new EventRecorder <EventArgs>(); }
public void OnPagesChanged_WhenAddChild() { var eventRecoder = new EventRecorder(); var contentPageMock1 = new ContentPageMock(eventRecoder) { Title = "contentPageMock1" }; var tabbedPageMock = new TabbedPageMock(eventRecoder); tabbedPageMock.Children.Add(contentPageMock1); tabbedPageMock.Behaviors.Add(new MultiPageBehavior <Page>()); var contentPageMock2 = new ContentPageMock(eventRecoder) { Title = "contentPageMock2" }; tabbedPageMock.Children.Add(contentPageMock2); Assert.Equal(1, eventRecoder.Count); Assert.NotNull(eventRecoder[0]); Assert.Equal(contentPageMock2, eventRecoder[0].Sender); Assert.Equal("OnInitialize", eventRecoder[0].CallerMemberName); Assert.Null(eventRecoder[0].Parameter); }
public async Task PopToRootAsync_WhenAnimatedIsFalse() { var eventRecorder = new EventRecorder(); var contentPageMock1 = new ContentPageMock(eventRecorder) { Title = "contentPageMock1" }; var contentPageMock2 = new ContentPageMock(eventRecorder) { Title = "contentPageMock2" }; var contentPageMock3 = new ContentPageMock(eventRecorder) { Title = "contentPageMock3" }; // ReSharper disable once UnusedVariable var navigationPage = new NavigationPageMock(contentPageMock1, eventRecorder); await contentPageMock1.Navigation.PushAsync(contentPageMock2); await contentPageMock2.Navigation.PushAsync(contentPageMock3); var navigationMock = new Mock <INavigation>(); navigationMock .Setup(m => m.PopToRootAsync(false)) .Returns(() => Task.FromResult(false)) .Callback(() => contentPageMock3.Navigation.PopToRootAsync(false).Wait()); var navigator = new Navigator(contentPageMock3, navigationMock.Object); await navigator.PopToRootAsync(false); navigationMock.Verify(x => x.PopToRootAsync(false), Times.Once); }
static void Main(string[] args) { IConfiguration config = new ConfigurationBuilder() .AddJsonFile("appsettings.json", true, true) .Build(); // NLog: setup the logger first to catch all errors NLog.LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration("nlog.config"); NLog.ILogger logger = NLog.LogManager.Configuration.LogFactory.GetLogger(""); string connection_string = config.GetConnectionString("mysql"); IBackgroundTaskQueue <EventSummary> queue = new BackgroundTaskQueue <EventSummary>(); EventHavestor eventHavestor = new EventHavestor(queue); MqttAddress queue_address = config.GetSection("MQTTBrokers").Get <MqttAddress>(); Console.CancelKeyPress += Console_CancelKeyPress; EventRecorder eventRecorder = new EventRecorder(logger, queue, connection_string); Task T = eventHavestor.ConnectionAsync(queue_address.ClientId, queue_address.BindAddress, queue_address.Port, queue_address.QosLevel, queue_address.Topic); T.Wait(); Task t1 = eventRecorder.RunAsync(cancellationTokenSource.Token); t1.Wait(); }
public async Task PushModalAsync_WithParameter() { var eventRecorder = new EventRecorder(); var contentPageMock1 = new ContentPageMock(eventRecorder); var navigationMock = new Mock <INavigation>(); var navigator = new Navigator(contentPageMock1, navigationMock.Object); var behaviorInjectorMock = new Mock <IBehaviorInjector>(); navigator.BehaviorInjector = behaviorInjectorMock.Object; var contentPageMock2 = new ContentPageMock(eventRecorder); var parameter = new object(); await navigator.PushModalAsync(contentPageMock2, parameter); behaviorInjectorMock.Verify(x => x.Inject(contentPageMock2), Times.Once); navigationMock.Verify(x => x.PushModalAsync(contentPageMock2, true), Times.Once); Assert.Equal(3, eventRecorder.Count); Assert.Equal(contentPageMock2, eventRecorder[0].Sender); Assert.Equal("OnInitialize", eventRecorder[0].CallerMemberName); Assert.Equal(parameter, eventRecorder[0].Parameter); Assert.Equal(contentPageMock2, eventRecorder[1].Sender); Assert.Equal("OnLoaded", eventRecorder[1].CallerMemberName); Assert.Null(eventRecorder[1].Parameter); Assert.Equal(contentPageMock1, eventRecorder[2].Sender); Assert.Equal("OnUnloaded", eventRecorder[2].CallerMemberName); Assert.Null(eventRecorder[2].Parameter); }
public void TestInitialise() { _Service = Factory.Singleton.Resolve<IExternalIPAddressService>(); _Provider = new Mock<IExternalIPAddressServiceProvider>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Service.Provider = _Provider.Object; _AddressUpdated = new EventRecorder<EventArgs<string>>(); }
public void ContentPage() { var eventRecoder = new EventRecorder(); var viewModelMock = new ViewModelMock(eventRecoder); var contentPageMock = new ContentPageMock(eventRecoder) { BindingContext = viewModelMock }; LifecycleNoticeService.OnResume(new ApplicationMock { MainPage = contentPageMock }); Assert.Equal(2, eventRecoder.Count); Assert.NotNull(eventRecoder[0]); Assert.Equal(contentPageMock, eventRecoder[0].Sender); Assert.Equal("OnResume", eventRecoder[0].CallerMemberName); Assert.Null(eventRecoder[0].Parameter); Assert.NotNull(eventRecoder[1]); Assert.Equal(viewModelMock, eventRecoder[1].Sender); Assert.Equal("OnResume", eventRecoder[1].CallerMemberName); Assert.Null(eventRecoder[1].Parameter); }
public void TestInitialise() { _Server = Factory.Singleton.Resolve <IRebroadcastServer>(); _Listener = new Mock <IListener>(MockBehavior.Default) { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _BroadcastProvider = new Mock <IBroadcastProvider>(MockBehavior.Default) { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _SentBytes = new List <byte[]>(); _BroadcastProvider.Setup(r => r.Send(It.IsAny <byte[]>())).Callback((byte[] bytes) => _SentBytes.Add(bytes)); _Server.Listener = _Listener.Object; _Server.BroadcastProvider = _BroadcastProvider.Object; _ExceptionCaughtEvent = new EventRecorder <EventArgs <Exception> >(); _ExceptionCaughtEvent.EventRaised += DefaultExceptionCaughtHandler; _OnlineChangedEvent = new EventRecorder <EventArgs>(); _Server.ExceptionCaught += _ExceptionCaughtEvent.Handler; _Server.OnlineChanged += _OnlineChangedEvent.Handler; _Port30003Message = new BaseStationMessage() { Icao24 = "313233" }; }
public void Raise_Exception_Thrown_In_ExceptionCallback_Exposed_As_EventHandlerException() { var recorder1 = new EventRecorder <EventArgs>(); var recorder2 = new EventRecorder <EventArgs>(); _Raise_Exception_Thrown_In_ExceptionCallback_Exposed_As_EventHandlerException += recorder1.Handler; _Raise_Exception_Thrown_In_ExceptionCallback_Exposed_As_EventHandlerException += recorder2.Handler; recorder1.EventRaised += (sender, args) => { throw new NotImplementedException(); }; recorder2.EventRaised += (sender, args) => { throw new NotImplementedException(); }; var exceptionWrapperBubbled = false; try { EventHelper.Raise(_Raise_Exception_Thrown_In_ExceptionCallback_Exposed_As_EventHandlerException, new object(), EventArgs.Empty, ex => { throw new InvalidOperationException(); }); } catch (EventHelperException ex) { exceptionWrapperBubbled = true; Assert.AreEqual(2, ex.HandlerExceptions.Length); Assert.AreEqual(2, ex.HandlerExceptions.Where(r => r is InvalidOperationException).Count()); } Assert.IsTrue(exceptionWrapperBubbled); Assert.AreEqual(1, recorder1.CallCount); Assert.AreEqual(1, recorder2.CallCount); }
public void SetMainPage_WithParameter() { var behaviorInjector = new Mock <IBehaviorInjector>(); var eventRecorder = new EventRecorder(); var contentPageMock = new ContentPageMock(eventRecorder); behaviorInjector.Setup(m => m.Inject(contentPageMock)) .Callback(() => eventRecorder.Record(behaviorInjector)); ApplicationService.BehaviorInjector = behaviorInjector.Object; var parameter = new object(); ApplicationService.SetMainPage(contentPageMock, parameter); ApplicationMock.VerifySet(m => m.MainPage = contentPageMock); Assert.Equal(3, eventRecorder.Count); // BehaviorInjector Assert.NotNull(eventRecorder[0]); Assert.Equal(behaviorInjector, eventRecorder[0].Sender); // OnInitialize Assert.NotNull(eventRecorder[1]); Assert.Equal(contentPageMock, eventRecorder[1].Sender); Assert.Equal("OnInitialize", eventRecorder[1].CallerMemberName); Assert.Equal(parameter, eventRecorder[1].Parameter); // OnLoaded Assert.NotNull(eventRecorder[2]); Assert.Equal(contentPageMock, eventRecorder[2].Sender); Assert.Equal("OnLoaded", eventRecorder[2].CallerMemberName); }
public void Raise_Calls_All_Handlers_When_ThrowEventHelperException_Is_True() { var recorder1 = new EventRecorder <EventArgs>(); var recorder2 = new EventRecorder <EventArgs>(); _Raise_Calls_All_Handlers_When_ThrowEventHelperException_Is_True += recorder1.Handler; _Raise_Calls_All_Handlers_When_ThrowEventHelperException_Is_True += recorder2.Handler; var exception1 = new NotImplementedException("1"); var exception2 = new NotImplementedException("2"); recorder1.EventRaised += (sender, args) => { throw exception1; }; recorder2.EventRaised += (sender, args) => { throw exception2; }; var exceptionBubbled = false; var exceptionWrapperBubbled = false; try { EventHelper.Raise(_Raise_Calls_All_Handlers_When_ThrowEventHelperException_Is_True, new object(), EventArgs.Empty, null, true); } catch (NotImplementedException) { exceptionBubbled = true; } catch (EventHelperException ex) { exceptionWrapperBubbled = true; Assert.AreEqual(2, ex.HandlerExceptions.Length); Assert.IsTrue(ex.HandlerExceptions.Any(r => Object.ReferenceEquals(r, exception1))); Assert.IsTrue(ex.HandlerExceptions.Any(r => Object.ReferenceEquals(r, exception2))); } Assert.IsFalse(exceptionBubbled); Assert.IsTrue(exceptionWrapperBubbled); Assert.AreEqual(1, recorder1.CallCount); Assert.AreEqual(1, recorder2.CallCount); }
public void NavigationPage() { var eventRecoder = new EventRecorder(); var contentPageMock1 = new ContentPageMock(eventRecoder); var contentPageMock2 = new ContentPageMock(eventRecoder); var viewModelMock = new ViewModelMock(eventRecoder); var navigationPageMock = new NavigationPageMock(contentPageMock1, eventRecoder) { BindingContext = viewModelMock }; contentPageMock1.Navigation.PushAsync(contentPageMock2); LifecycleNoticeService.OnUnloaded(navigationPageMock); Assert.Equal(3, eventRecoder.Count); Assert.NotNull(eventRecoder[0]); Assert.Equal(contentPageMock2, eventRecoder[0].Sender); Assert.Equal("OnUnloaded", eventRecoder[0].CallerMemberName); Assert.Null(eventRecoder[0].Parameter); Assert.NotNull(eventRecoder[1]); Assert.Equal(viewModelMock, eventRecoder[1].Sender); Assert.Equal("OnUnloaded", eventRecoder[1].CallerMemberName); Assert.Null(eventRecoder[1].Parameter); Assert.NotNull(eventRecoder[2]); Assert.Equal(navigationPageMock, eventRecoder[2].Sender); Assert.Equal("OnUnloaded", eventRecoder[2].CallerMemberName); Assert.Null(eventRecoder[2].Parameter); }
public void OnCurrentPageChanged() { var eventRecoder = new EventRecorder(); var contentPageMock1 = new ContentPageMock(eventRecoder) { Title = "contentPageMock1" }; var contentPageMock2 = new ContentPageMock(eventRecoder) { Title = "contentPageMock2" }; var navigationPageMock = new NavigationPageMock(contentPageMock1, eventRecoder); contentPageMock1.Navigation.PushAsync(contentPageMock2); navigationPageMock.Behaviors.Add(new NavigationPageBehavior()); contentPageMock2.Navigation.PopAsync(); Assert.Equal(2, eventRecoder.Count); Assert.NotNull(eventRecoder[0]); Assert.Equal(contentPageMock1, eventRecoder[0].Sender); Assert.Equal("OnLoaded", eventRecoder[0].CallerMemberName); Assert.Null(eventRecoder[0].Parameter); Assert.NotNull(eventRecoder[1]); Assert.Equal(contentPageMock2, eventRecoder[1].Sender); Assert.Equal("OnClosed", eventRecoder[1].CallerMemberName); Assert.Null(eventRecoder[1].Parameter); }
public void OnResume_WithModalStackPages() { var eventRecorder = new EventRecorder(); var contentPageMock1 = new ContentPageMock(eventRecorder); var application = new ApplicationMock { MainPage = contentPageMock1 }; var contentPageMock2 = new ContentPageMock(eventRecorder); contentPageMock1.Navigation.PushModalAsync(contentPageMock2); var contentPageMock3 = new ContentPageMock(eventRecorder); contentPageMock2.Navigation.PushModalAsync(contentPageMock3); LifecycleNoticeService.OnResume(application); Assert.Equal(3, eventRecorder.Count); Assert.Equal(contentPageMock1, eventRecorder[0].Sender); Assert.Equal("OnResume", eventRecorder[0].CallerMemberName); Assert.Null(eventRecorder[0].Parameter); Assert.Equal(contentPageMock2, eventRecorder[1].Sender); Assert.Equal("OnResume", eventRecorder[1].CallerMemberName); Assert.Null(eventRecorder[1].Parameter); Assert.Equal(contentPageMock3, eventRecorder[2].Sender); Assert.Equal("OnResume", eventRecorder[2].CallerMemberName); Assert.Null(eventRecorder[2].Parameter); }
public void TestInitialise() { _OriginalClassFactory = Factory.TakeSnapshot(); _RuntimeEnvironment = TestUtilities.CreateMockSingleton<IRuntimeEnvironment>(); _ConfigurationStorage = TestUtilities.CreateMockSingleton<IConfigurationStorage>(); _Configuration = new Configuration(); _ConfigurationStorage.Setup(s => s.Load()).Returns(_Configuration); _CreateDatabaseFileName = Path.Combine(TestContext.TestDeploymentDir, "CreatedDatabase.sqb"); if(File.Exists(_CreateDatabaseFileName)) File.Delete(_CreateDatabaseFileName); _EmptyDatabaseFileName = Path.Combine(TestContext.TestDeploymentDir, "TestCopyBaseStation.sqb"); File.Copy(Path.Combine(TestContext.TestDeploymentDir, "BaseStation.sqb"), _EmptyDatabaseFileName, true); _Database = Factory.Singleton.Resolve<IBaseStationDatabase>(); _Database.FileName = _EmptyDatabaseFileName; _Provider = new Mock<IBaseStationDatabaseProvider>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Database.Provider = _Provider.Object; _Provider.Setup(p => p.UtcNow).Returns(DateTime.UtcNow); _ConnectionStringBuilder = new SQLiteConnectionStringBuilder() { DataSource = _EmptyDatabaseFileName }; _Criteria = new SearchBaseStationCriteria() { FromDate = DateTime.MinValue, ToDate = DateTime.MaxValue, }; _FileNameChangingEvent = new EventRecorder<EventArgs>(); _FileNameChangedEvent = new EventRecorder<EventArgs>(); }
public void DeletingACounterShouldRaiseTheCollectionChangedEvent() { var dbfile = Path.Combine(RootPath, Guid.NewGuid().ToString("N") + ".db3"); DatabaseHelper.CreateDatabase(dbfile); var db = new DatabaseHelper(); var counter = new Counter { Name = "TestCounter", Description = "A test counter" }; var res = Task.Run(async() => { await db.AddOrUpdateCounterAsync(counter); return(0); }).Result; var eventRecorder = new EventRecorder(db, nameof(DatabaseHelper.CountersChanged)); eventRecorder.RecordEvent(); res = Task.Run(async() => { await db.DeleteCounterAsync(counter); return(0); }).Result; eventRecorder.Should().HaveCount(1); }
public void Resume() { using var src = new EventSource <String>(); var rec = EventRecorder.From(src.Event); rec.Pause(); src.Invoke("aaa"); Check.That(rec.IsPaused) .IsTrue(); Check.That(rec.Count) .IsEqualTo(0); rec.Resume(); src.Invoke("bbb"); Check.That(rec.IsPaused) .IsFalse(); Check.That(rec.Count) .IsEqualTo(1); Check.That(rec.Events) .ContainsExactly("bbb"); }
public void TestInitialise() { _ClassFactorySnapshot = Factory.TakeSnapshot(); CreateBackgroundWorkerMock(); _HeartbeatService = TestUtilities.CreateMockSingleton <IHeartbeatService>(); _Log = TestUtilities.CreateMockSingleton <ILog>(); _Log.Setup(g => g.WriteLine(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Callback(() => { throw new InvalidOperationException("Log was unexpectedly written"); }); _CacheChangedEvent = new EventRecorder <EventArgs>(); _Now = new DateTime(2001, 2, 3, 4, 5, 6, 789); _LastModifiedUtc = new DateTime(2009, 8, 7, 6, 5, 4, 321); _Files = new List <TestFileInfo>(); _Provider = new Mock <IDirectoryCacheProvider>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Provider.Setup(p => p.FolderExists(It.IsAny <string>())).Returns(true); _Provider.Setup(p => p.UtcNow).Returns(() => { return(_Now); }); _Provider.Setup(p => p.GetFilesInFolder(It.IsAny <string>())).Returns(new List <TestFileInfo>()); _DirectoryCache = Factory.Singleton.Resolve <IDirectoryCache>(); _DirectoryCache.Provider = _Provider.Object; }
public void Execute_Does_Not_Publish_Events_Given_Invalid_Command(AddFiscalReceiptCommand invalidCommand) { var handler = Handler(); var eventRecorder = new EventRecorder(); handler.Execute(invalidCommand, eventRecorder); eventRecorder.AssertRecordedNoEvents(); }
/// <summary> /// Initializes a new instance of the <see cref="ObservableAggregateRootEntity"/> class. /// </summary> protected ObservableAggregateRootEntity() { _router = new InstanceEventRouter(); _recorder = new EventRecorder(); _observers = ImmutableObserverList.Empty; _disposed = false; }
public EventRecorderWithRecordedEvents() { _sut = new EventRecorder(); foreach (var record in _recorded) { _sut.Record(record); } }
public void TestInitialise() { _Provider = new TestProvider(); _Provider.Folder = TestContext.TestDeploymentDir; _Implementation = Factory.Singleton.Resolve<IConfigurationStorage>(); _Implementation.Provider = _Provider; _ConfigurationChangedEvent = new EventRecorder<EventArgs>(); }
public void TestCreating() { EventRecorder recorder = new EventRecorder(Db()); Store(new Item()); Assert.AreEqual(0, Db().QueryByExample(typeof(Item)).Count); Assert.AreEqual("Creating", recorder[0]); }
public void TestInitialise() { _ClassFactorySnapshot = Factory.TakeSnapshot(); _NewVersionChecker = Factory.Singleton.Resolve<INewVersionChecker>(); _Provider = new Mock<INewVersionCheckerProvider>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _NewVersionChecker.Provider = _Provider.Object; _NewVersionAvailable = new EventRecorder<EventArgs>(); _ApplicationInformation = TestUtilities.CreateMockImplementation<IApplicationInformation>(); }
public static EventRecorder GetManager() { if( s_manager == null ) { EventRecorder obj = Component.FindObjectOfType(typeof(EventRecorder)) as EventRecorder; if(obj) { s_manager = obj; } else { Debug.LogError("EventRecorder does not exist in scene"); } } return s_manager; }
public void TestInitialise() { _OriginalClassFactory = Factory.TakeSnapshot(); _ConfigurationStorage = TestUtilities.CreateMockSingleton<IConfigurationStorage>(); _Configuration = new Configuration(); _ConfigurationStorage.Setup(c => c.Load()).Returns(_Configuration); _DirectoryCache = new Mock<IDirectoryCache>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _CacheCleared = new EventRecorder<EventArgs>(); _PictureManager = Factory.Singleton.Resolve<IAircraftPictureManager>(); }
public void TestInitialise() { _ClassFactorySnapshot = Factory.TakeSnapshot(); _ConfigurationStorage = TestUtilities.CreateMockSingleton<IConfigurationStorage>(); _ConfigurationStorage.Setup(c => c.Folder).Returns("configFolder"); _Storage = Factory.Singleton.Resolve<IPluginSettingsStorage>(); _Provider = new Mock<IPluginSettingsStorageProvider>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Provider.Setup(p => p.FileExists(It.IsAny<string>())).Returns(true); _Storage.Provider = _Provider.Object; _ConfigurationChangedEvent = new EventRecorder<EventArgs>(); }
public void TestInitialise() { _ClassFactorySnapshot = Factory.TakeSnapshot(); _HeartbeatService = TestUtilities.CreateMockSingleton<IHeartbeatService>(); _WebServer = new Mock<IWebServer>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _LogDatabase = new Mock<ILogDatabase>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _LogSession = new Mock<LogSession>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _ExceptionCaughtEvent = new EventRecorder<EventArgs<Exception>>(); _ConnectionLogger = Factory.Singleton.Resolve<IConnectionLogger>(); _ConnectionLogger.WebServer = _WebServer.Object; _ConnectionLogger.LogDatabase = _LogDatabase.Object; _Provider = new Mock<IConnectionLoggerProvider>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _ConnectionLogger.Provider = _Provider.Object; }
public void TestInitialise() { _OriginalFactory = Factory.TakeSnapshot(); _RuntimeEnvironment = TestUtilities.CreateMockSingleton<IRuntimeEnvironment>(); _ConfigurationStorage = TestUtilities.CreateMockSingleton<IConfigurationStorage>(); _Configuration = new Configuration(); _ConfigurationStorage.Setup(c => c.Load()).Returns(_Configuration); _PortMappings = new List<IPortMapping>(); _Manager = Factory.Singleton.Resolve<IUniversalPlugAndPlayManager>(); _Provider = new Mock<IUniversalPlugAndPlayManagerProvider>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Provider.Setup(p => p.GetPortMappings()).Returns(_PortMappings); _Manager.Provider = _Provider.Object; _WebServer = new Mock<IWebServer>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Manager.WebServer = _WebServer.Object; _StateChangedEvent = new EventRecorder<EventArgs>(); }
public void TestInitialise() { _Server = Factory.Singleton.Resolve<IRebroadcastServer>(); _Listener = new Mock<IListener>(MockBehavior.Default) { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _BroadcastProvider = new Mock<IBroadcastProvider>(MockBehavior.Default) { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _SentBytes = new List<byte[]>(); _BroadcastProvider.Setup(r => r.Send(It.IsAny<byte[]>())).Callback((byte[] bytes) => _SentBytes.Add(bytes)); _Server.Listener = _Listener.Object; _Server.BroadcastProvider = _BroadcastProvider.Object; _ExceptionCaughtEvent = new EventRecorder<EventArgs<Exception>>(); _ExceptionCaughtEvent.EventRaised += DefaultExceptionCaughtHandler; _OnlineChangedEvent = new EventRecorder<EventArgs>(); _Server.ExceptionCaught += _ExceptionCaughtEvent.Handler; _Server.OnlineChanged += _OnlineChangedEvent.Handler; _Port30003Message = new BaseStationMessage() { Icao24 = "313233" }; }
public void TestInitialise() { _ClassFactorySnapshot = Factory.TakeSnapshot(); CreateBackgroundWorkerMock(); _HeartbeatService = TestUtilities.CreateMockSingleton<IHeartbeatService>(); _Log = TestUtilities.CreateMockSingleton<ILog>(); _Log.Setup(g => g.WriteLine(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Callback(() => { throw new InvalidOperationException("Log was unexpectedly written"); }); _CacheChangedEvent = new EventRecorder<EventArgs>(); _Now = new DateTime(2001, 2, 3, 4, 5, 6, 789); _LastModifiedUtc = new DateTime(2009, 8, 7, 6, 5, 4, 321); _Files = new List<TestFileInfo>(); _Provider = new Mock<IDirectoryCacheProvider>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Provider.Setup(p => p.FolderExists(It.IsAny<string>())).Returns(true); _Provider.Setup(p => p.UtcNow).Returns(() => { return _Now; }); _Provider.Setup(p => p.GetFilesInFolder(It.IsAny<string>())).Returns(new List<TestFileInfo>()); _DirectoryCache = Factory.Singleton.Resolve<IDirectoryCache>(); _DirectoryCache.Provider = _Provider.Object; }
public ProcessingResult Process(Resource resource) { var eventRecorder = new EventRecorder(); var stubTarget = new StubTarget(); var concordion = new ConcordionBuilder() .WithAssertEqualsListener(eventRecorder) .WithExceptionListener(eventRecorder) .WithSource(Source) .WithEvaluatorFactory(EvaluatorFactory) .WithTarget(stubTarget) .Build(); try { IResultSummary resultSummary = concordion.Process(resource, Fixture); string xml = stubTarget.GetWrittenString(resource); return new ProcessingResult(resultSummary, eventRecorder, xml); } catch (Exception e) { throw new Exception("Test rig failed to process specification", e); } }
public void TestInitialise() { _OriginalFactory = Factory.TakeSnapshot(); _WebServer = Factory.Singleton.Resolve<IWebServer>(); _Now = DateTime.UtcNow; _Provider = new Mock<IWebServerProvider>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Provider.Setup(m => m.IsListening).Returns(true); _Provider.Setup(m => m.UtcNow).Returns(() => { return _Now; }); _Provider.Object.AuthenticationSchemes = AuthenticationSchemes.Anonymous; _WebServer.Provider = _Provider.Object; _Context = new Mock<IContext>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Request = new Mock<IRequest>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Request.Setup(m => m.RemoteEndPoint).Returns(new IPEndPoint(0x0100007fL, 12000)); _Response = new Mock<IResponse>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _OutputStream = new MemoryStream(); _Response.Setup(m => m.OutputStream).Returns(_OutputStream); _Context.Setup(m => m.Request).Returns(_Request.Object); _Context.Setup(m => m.Response).Returns(_Response.Object); _OnlineChangedEvent = new EventRecorder<EventArgs>(); _AuthenticationRequiredEvent = new EventRecorder<AuthenticationRequiredEventArgs>(); _BeforeRequestReceivedEvent = new EventRecorder<RequestReceivedEventArgs>(); _RequestReceivedEvent = new EventRecorder<RequestReceivedEventArgs>(); _AfterRequestReceivedEvent = new EventRecorder<RequestReceivedEventArgs>(); _ResponseSentEvent = new EventRecorder<ResponseSentEventArgs>(); _ExceptionCaughtEvent = new EventRecorder<EventArgs<Exception>>(); _ExternalAddressChangedEvent = new EventRecorder<EventArgs>(); _WebServer.ExceptionCaught += DefaultExceptionCaughtHandler; }
public void TestInitialise() { _ClassFactorySnapshot = Factory.TakeSnapshot(); _ConfigurationStorage = TestUtilities.CreateMockSingleton<IConfigurationStorage>(); _Configuration = new Configuration(); _ConfigurationStorage.Setup(c => c.Load()).Returns(_Configuration); _AutoConfigListener = TestUtilities.CreateMockSingleton<IAutoConfigListener>(); _AutoConfigListener.Setup(r => r.Listener).Returns((IListener)null); _AutoConfigListener.Setup(r => r.Initialise()).Callback(() => { _AutoConfigListener.Setup(r => r.Listener).Returns(_Listener.Object); }); _Log = TestUtilities.CreateMockSingleton<ILog>(); _HearbeatService = TestUtilities.CreateMockSingleton<IHeartbeatService>(); _StandingDataManager = TestUtilities.CreateMockSingleton<IStandingDataManager>(); _Listener = new Mock<IListener>(MockBehavior.Default) { DefaultValue = DefaultValue.Mock }; _BaseStationAircraftList = TestUtilities.CreateMockImplementation<IBaseStationAircraftList>(); _AutoConfigWebServer = TestUtilities.CreateMockSingleton<IAutoConfigWebServer>(); _WebServer = new Mock<IWebServer>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _AutoConfigWebServer.Setup(s => s.WebServer).Returns(_WebServer.Object); _WebSite = TestUtilities.CreateMockImplementation<IWebSite>(); _FlightSimulatorXAircraftList = TestUtilities.CreateMockImplementation<ISimpleAircraftList>(); _UniversalPlugAndPlayManager = TestUtilities.CreateMockImplementation<IUniversalPlugAndPlayManager>(); _ConnectionLogger = TestUtilities.CreateMockSingleton<IConnectionLogger>(); _LogDatabase = TestUtilities.CreateMockSingleton<ILogDatabase>(); _BackgroundDataDownloader = TestUtilities.CreateMockSingleton<IBackgroundDataDownloader>(); _PluginManager = TestUtilities.CreateMockSingleton<IPluginManager>(); _ApplicationInformation = TestUtilities.CreateMockImplementation<IApplicationInformation>(); _AutoConfigPictureFolderCache = TestUtilities.CreateMockSingleton<IAutoConfigPictureFolderCache>(); _RebroadcastServerManager = TestUtilities.CreateMockSingleton<IRebroadcastServerManager>(); _Statistics = TestUtilities.CreateMockSingleton<IStatistics>(); _BackgroundExceptionEvent = new EventRecorder<EventArgs<Exception>>(); _BaseStationDatabase = new Mock<IBaseStationDatabase>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _AutoConfigBaseStationDatabase = TestUtilities.CreateMockSingleton<IAutoConfigBaseStationDatabase>(); _AutoConfigBaseStationDatabase.Setup(a => a.Database).Returns(_BaseStationDatabase.Object); _BaseStationDatabase.Setup(d => d.FileName).Returns("x"); _BaseStationDatabase.Setup(d => d.TestConnection()).Returns(true); _Provider = new Mock<ISplashPresenterProvider>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Provider.Setup(p => p.FolderExists(It.IsAny<string>())).Returns(true); _Presenter = Factory.Singleton.Resolve<ISplashPresenter>(); _Presenter.Provider = _Provider.Object; _View = new Mock<ISplashView>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); }
public void Listener_Connect_Raises_RawBytesReceived_When_Bytes_Are_Received() { var bytes = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 }; _Provider.ConfigureForConnect(); _Provider.ConfigureForReadStream(bytes, 3); var eventRecorder = new EventRecorder<EventArgs<byte[]>>(); _Listener.RawBytesReceived += eventRecorder.Handler; ChangeSourceAndConnect(); Assert.AreEqual(1, eventRecorder.CallCount); Assert.AreSame(_Listener, eventRecorder.Sender); Assert.IsTrue(new byte[] { 0x01, 0x02, 0x03}.SequenceEqual(eventRecorder.Args.Value)); }
public void TestInitialise() { _Statistics = Factory.Singleton.Resolve<IStatistics>().Singleton; _Statistics.Initialise(); _Statistics.ResetConnectionStatistics(); _Statistics.ResetMessageCounters(); _OriginalClassFactory = Factory.TakeSnapshot(); _RuntimeEnvironment = TestUtilities.CreateMockSingleton<IRuntimeEnvironment>(); _RuntimeEnvironment.Setup(r => r.IsTest).Returns(true); _Port30003Translator = TestUtilities.CreateMockImplementation<IBaseStationMessageTranslator>(); _ModeSTranslator = TestUtilities.CreateMockImplementation<IModeSTranslator>(); _AdsbTranslator = TestUtilities.CreateMockImplementation<IAdsbTranslator>(); _RawMessageTranslator = new Mock<IRawMessageTranslator>(MockBehavior.Default) { DefaultValue = DefaultValue.Mock }; _ModeSParity = TestUtilities.CreateMockImplementation<IModeSParity>(); _ModeSMessage = new ModeSMessage(); _AdsbMessage = new AdsbMessage(_ModeSMessage); _Port30003Message = new BaseStationMessage(); _Port30003Translator.Setup(r => r.Translate(It.IsAny<string>())).Returns(_Port30003Message); _AdsbTranslator.Setup(r => r.Translate(It.IsAny<ModeSMessage>())).Returns(_AdsbMessage); _ModeSTranslator.Setup(r => r.Translate(It.IsAny<byte[]>())).Returns(_ModeSMessage); _ModeSTranslator.Setup(r => r.Translate(It.IsAny<byte[]>(), It.IsAny<int>())).Returns(_ModeSMessage); _RawMessageTranslator.Setup(r => r.Translate(It.IsAny<DateTime>(), It.IsAny<ModeSMessage>(), It.IsAny<AdsbMessage>())).Returns(_Port30003Message); _Listener = Factory.Singleton.Resolve<IListener>(); _Provider = new MockListenerProvider(); _BytesExtractor = new MockMessageBytesExtractor(); _ExceptionCaughtEvent = new EventRecorder<EventArgs<Exception>>(); _ConnectionStateChangedEvent = new EventRecorder<EventArgs>(); _ModeSMessageReceivedEvent = new EventRecorder<ModeSMessageEventArgs>(); _Port30003MessageReceivedEvent = new EventRecorder<BaseStationMessageEventArgs>(); _SourceChangedEvent = new EventRecorder<EventArgs>(); _Listener.ConnectionStateChanged += _ConnectionStateChangedEvent.Handler; _Listener.ExceptionCaught += _ExceptionCaughtEvent.Handler; _Listener.ModeSMessageReceived += _ModeSMessageReceivedEvent.Handler; _Listener.Port30003MessageReceived += _Port30003MessageReceivedEvent.Handler; _Listener.SourceChanged += _SourceChangedEvent.Handler; _ExceptionCaughtEvent.EventRaised += DefaultExceptionCaughtHandler; }
void DoInstantiateCall (ListViewItemTemplate whichTemplate) { var events = new EventRecorder (); var lvp = new ListViewPoker (events); var container = new Control (); var template = new TestTemplate (); switch (whichTemplate) { case ListViewItemTemplate.EmptyData: lvp.DoInstantiateEmptyDataTemplate (null); lvp.EmptyDataTemplate = template; lvp.DoInstantiateEmptyDataTemplate (container); break; case ListViewItemTemplate.EmptyItem: lvp.DoInstantiateEmptyItemTemplate (null); lvp.EmptyItemTemplate = template; lvp.DoInstantiateEmptyItemTemplate (container); break; case ListViewItemTemplate.GroupSeparator: lvp.DoInstantiateGroupSeparatorTemplate (null); lvp.GroupSeparatorTemplate = template; lvp.DoInstantiateGroupSeparatorTemplate (container); break; case ListViewItemTemplate.Group: lvp.DoInstantiateGroupTemplate (null); lvp.GroupTemplate = template; lvp.DoInstantiateGroupTemplate (container); break; case ListViewItemTemplate.InsertItem: lvp.DoInstantiateInsertItemTemplate (null); lvp.InsertItemTemplate = template; lvp.DoInstantiateInsertItemTemplate (container); break; case ListViewItemTemplate.ItemSeparator: lvp.DoInstantiateItemSeparatorTemplate (null); lvp.ItemSeparatorTemplate = template; lvp.DoInstantiateItemSeparatorTemplate (container); break; case ListViewItemTemplate.Item: lvp.ItemTemplate = template; lvp.DoInstantiateItemTemplate (container, 0); break; case ListViewItemTemplate.EditItem: lvp.EditIndex = 0; lvp.ItemTemplate = template; lvp.EditItemTemplate = template; lvp.DoInstantiateItemTemplate (container, 0); break; case ListViewItemTemplate.AlternatingItem: lvp.ItemTemplate = template; lvp.AlternatingItemTemplate = template; lvp.DoInstantiateItemTemplate (container, 1); break; case ListViewItemTemplate.SelectedItem: lvp.ItemTemplate = template; lvp.SelectedIndex = 0; lvp.SelectedItemTemplate = template; lvp.DoInstantiateItemTemplate (container, 0); break; default: throw new NotSupportedException ("Unsupported ListView item type."); } Assert.AreEqual (0, events.Count, "#A1"); Assert.AreEqual (typeof (Control), container.Controls [0].GetType (), "#A2"); Assert.AreEqual ("TestTemplateControl", container.Controls [0].ID, "#A3"); }
public void Listener_Connect_Raises_ModeSBytesReceived_When_BytesExtractor_Extracts_ModeS_Message() { _Provider.ConfigureForConnect(); _Provider.ConfigureForReadStream("a"); var extractedBytes = _BytesExtractor.AddExtractedBytes(ExtractedBytesFormat.ModeS, new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 }, 1, 7, false, false); var eventRecorder = new EventRecorder<EventArgs<ExtractedBytes>>(); _Listener.ModeSBytesReceived += eventRecorder.Handler; ChangeSourceAndConnect(); Assert.AreEqual(1, eventRecorder.CallCount); Assert.AreSame(_Listener, eventRecorder.Sender); Assert.AreEqual(extractedBytes, eventRecorder.Args.Value); Assert.AreNotSame(extractedBytes, eventRecorder.Args.Value); // must be a clone, not the original - the original can be reused }
public void ListView_EnsureLayoutTemplate () { var events = new EventRecorder (); var lvp = new ListViewPoker (events); lvp.DoEnsureLayoutTemplate (); Assert.AreEqual (2, events.Count, "#A1"); Assert.AreEqual ("OnLayoutCreated:Enter", events [0], "#A2"); Assert.AreEqual ("OnLayoutCreated:Leave", events [1], "#A3"); Assert.AreEqual (0, lvp.Controls.Count, "#A4"); events.Clear (); lvp.LayoutTemplate = new TestTemplate (); lvp.DoEnsureLayoutTemplate (); Assert.AreEqual (2, events.Count, "#B1"); Assert.AreEqual ("OnLayoutCreated:Enter", events [0], "#B2"); Assert.AreEqual ("OnLayoutCreated:Leave", events [1], "#B3"); Assert.AreEqual (1, lvp.Controls.Count, "#B4"); Assert.AreEqual (typeof (Control), lvp.Controls [0].GetType (), "#B5"); Assert.AreEqual ("TestTemplateControl", lvp.Controls [0].Controls [0].ID, "#B6"); events.Clear (); lvp.DoEnsureLayoutTemplate (); Assert.AreEqual (0, events.Count, "#C1"); Assert.AreEqual (1, lvp.Controls.Count, "#C2"); Assert.AreEqual (typeof (Control), lvp.Controls [0].GetType (), "#C3"); Assert.AreEqual ("TestTemplateControl", lvp.Controls [0].Controls [0].ID, "#C4"); }
internal void SetEventRecorder (EventRecorder recorder) { this.recorder = recorder; }
public void ListView_CreateItem () { var events = new EventRecorder (); var lvp = new ListViewPoker (events); ListViewItem item; item = lvp.DoCreateItem (ListViewItemType.DataItem); Assert.IsFalse (item == null, "#A1"); Assert.AreEqual (ListViewItemType.DataItem, item.ItemType, "#A2"); Assert.AreEqual (typeof (ListViewItem), item.GetType (), "#A3"); Assert.AreEqual (0, events.Count, "#B1"); item = lvp.DoCreateItem (ListViewItemType.InsertItem); Assert.IsFalse (item == null, "#C1"); Assert.AreEqual (ListViewItemType.InsertItem, item.ItemType, "#C2"); Assert.AreEqual (typeof (ListViewItem), item.GetType (), "#C3"); item = lvp.DoCreateItem (ListViewItemType.EmptyItem); Assert.IsFalse (item == null, "#D1"); Assert.AreEqual (ListViewItemType.EmptyItem, item.ItemType, "#D2"); Assert.AreEqual (typeof (ListViewItem), item.GetType (), "#D3"); }
public ListViewPoker (EventRecorder recorder) { this.recorder = recorder; }
public void ListView_CreateInsertItem () { var events = new EventRecorder (); var lvp = new ListViewPoker (events); lvp.InsertItemTemplate = new TestTemplate (); ListViewItem item = lvp.DoCreateInsertItem (); Assert.AreEqual (0, lvp.Controls.Count, "#A1"); Assert.AreEqual (typeof (ListViewItem), item.GetType (), "#A2"); Assert.AreEqual (typeof (Control), item.Controls [0].GetType (), "#A3"); Assert.AreEqual (2, events.Count, "#A4"); Assert.AreEqual ("TestTemplateControl", item.Controls [0].ID, "#A5"); Assert.AreEqual ("OnItemCreated:Enter", events [0], "#A6"); Assert.AreEqual ("OnItemCreated:Leave", events [1], "#A7"); Assert.AreEqual (ListViewItemType.InsertItem, item.ItemType, "#A7"); Assert.IsTrue (item.Equals (lvp.InsertItem), "#A8"); }
public void ListView_CreateEmptyItem () { var events = new EventRecorder (); var lvp = new ListViewPoker (events); ListViewItem item = lvp.DoCreateEmptyItem (); Assert.AreEqual (0, events.Count, "#A1"); Assert.AreEqual (null, item, "#A2"); lvp.EmptyItemTemplate = new TestTemplate (); item = lvp.DoCreateEmptyItem (); Assert.AreEqual (0, lvp.Controls.Count, "#B1"); Assert.AreEqual (typeof (Control), item.Controls [0].GetType (), "#B2"); Assert.AreEqual ("TestTemplateControl", item.Controls [0].ID, "#B3"); Assert.AreEqual ("OnItemCreated:Enter", events [0], "#B4"); Assert.AreEqual ("OnItemCreated:Leave", events [1], "#B5"); }
public void ListView_SetPageProperties_Events () { var events = new EventRecorder (); var lvp = new ListViewPoker (events); // No events expected: databind is false events.Clear (); lvp.DoSetPageProperties (0, 1, false); // No events expected: startRowIndex and maximumRows don't change values events.Clear (); lvp.DoSetPageProperties (0, 1, true); Assert.AreEqual (0, events.Count, "#A1"); // No events expected: startRowIndex changes, but databind is false events.Clear(); lvp.DoSetPageProperties(1, 1, false); Assert.AreEqual (0, events.Count, "#A2"); // No events expected: maximumRows changes, but databind is false events.Clear(); lvp.DoSetPageProperties(1, 2, false); Assert.AreEqual (0, events.Count, "#A3"); // No events expected: maximumRows and startRowIndex change but databind is // false events.Clear(); lvp.DoSetPageProperties(3, 4, false); Assert.AreEqual (0, events.Count, "#A4"); // Events expected: maximumRows and startRowIndex change and databind is // true events.Clear(); lvp.DoSetPageProperties(5, 6, true); Assert.AreEqual (4, events.Count, "#A5"); Assert.AreEqual ("OnPagePropertiesChanging:Enter", events [0], "#A6"); Assert.AreEqual ("OnPagePropertiesChanging:Leave", events [1], "#A7"); Assert.AreEqual ("OnPagePropertiesChanged:Enter", events [2], "#A8"); Assert.AreEqual ("OnPagePropertiesChanged:Leave", events [3], "#A9"); // Events expected: maximumRows changes and databind is true events.Clear(); lvp.DoSetPageProperties(5, 7, true); Assert.AreEqual (4, events.Count, "#A10"); Assert.AreEqual ("OnPagePropertiesChanging:Enter", events [0], "#A11"); Assert.AreEqual ("OnPagePropertiesChanging:Leave", events [1], "#A12"); Assert.AreEqual ("OnPagePropertiesChanged:Enter", events [2], "#A13"); Assert.AreEqual ("OnPagePropertiesChanged:Leave", events [3], "#A14"); // Events expected: startRowIndex changes and databind is true events.Clear(); lvp.DoSetPageProperties(6, 7, true); Assert.AreEqual (4, events.Count, "#A15"); Assert.AreEqual ("OnPagePropertiesChanging:Enter", events [0], "#A16"); Assert.AreEqual ("OnPagePropertiesChanging:Leave", events [1], "#A17"); Assert.AreEqual ("OnPagePropertiesChanged:Enter", events [2], "#A18"); Assert.AreEqual ("OnPagePropertiesChanged:Leave", events [3], "#A19"); }
public void ListView_Edit () { WebTest t = new WebTest ("ListViewTest.aspx"); t.Invoker = PageInvoker.CreateOnInit (ListView_Edit_OnInit); t.Run (); FormRequest fr = new FormRequest(t.Response, "form1"); #if DOT_NET fr.Controls.Add ("ListView1$ctrl0$ctl03$EditButton"); fr.Controls.Add ("ListView1$ctrl6$ctrl7$CapitalTextBox"); fr.Controls.Add ("ListView1$ctrl6$ctrl7$IDTextBox"); fr.Controls.Add ("ListView1$ctrl6$ctrl7$NameTextBox"); fr.Controls.Add ("ListView1$ctrl6$ctrl7$PopulationTextBox"); fr.Controls ["ListView1$ctrl0$ctl03$EditButton"].Value = "Edit"; #else fr.Controls.Add ("ListView1$ctl13$EditButton"); fr.Controls.Add ("ListView1$ctl51$CapitalTextBox"); fr.Controls.Add ("ListView1$ctl51$IDTextBox"); fr.Controls.Add ("ListView1$ctl51$NameTextBox"); fr.Controls.Add ("ListView1$ctl51$PopulationTextBox"); fr.Controls ["ListView1$ctl13$EditButton"].Value = "Edit"; #endif t.Request = fr; EventRecorder events = new EventRecorder(); t.UserData = events; t.Run (); }
public void Listener_Connect_Does_Not_Raise_ModeSBytesReceived_When_BytesExtractor_Extracts_Port30003_Message() { _Provider.ConfigureForConnect(); _Provider.ConfigureForReadStream("a"); var extractedBytes = _BytesExtractor.AddExtractedBytes(ExtractedBytesFormat.Port30003, new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 }, 1, 7, false, false); var eventRecorder = new EventRecorder<EventArgs<ExtractedBytes>>(); _Listener.ModeSBytesReceived += eventRecorder.Handler; ChangeSourceAndConnect(); Assert.AreEqual(0, eventRecorder.CallCount); }