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 GetNextStop_ServerInNonCentralTimeZone_Ok() { // Arrange var stack = new Stack { ScheduleId = Guid.NewGuid() }; var schedule = new Schedule { Id = stack.ScheduleId, StopCron = "* 18 * * 1-5" }; ScheduleRepositoryMock.Setup(x => x.Find(schedule.Id)).Returns(schedule); var oneOClockEastern = new DateTime(2015, 10, 1, 13, 0, 0); var easternTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); oneOClockEastern = TimeZoneInfo.ConvertTime(oneOClockEastern, easternTimeZone); ClockMock.Setup(x => x.Now).Returns(oneOClockEastern); // == 2 PM central var expected = new TimeSpan(4, 0, 0); // Act var result = Calculator.GetNextStop(stack); // Assert result.Should().Be(expected); }
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 TestInitialise() { _OriginalFactory = Factory.TakeSnapshot(); _Clock = new ClockMock(); Factory.Singleton.RegisterInstance <IClock>(_Clock.Object); _HeartbeatService = TestUtilities.CreateMockSingleton <IHeartbeatService>(); _List = new ExpiringList <string>(200, 100); _CountChangedCallCount = 0; _List.CountChangedDelegate = CountChangedHandler; }
public void TestInitialise() { _Snapshot = Factory.TakeSnapshot(); _RuntimeEnvironment = TestUtilities.CreateMockSingleton <IRuntimeEnvironment>(); _RuntimeEnvironment.Setup(r => r.IsTest).Returns(true); _Clock = new ClockMock(); Factory.Singleton.RegisterInstance <IClock>(_Clock.Object); _Heartbeat = TestUtilities.CreateMockSingleton <IHeartbeatService>(); _SharedConfiguration = TestUtilities.CreateMockSingleton <ISharedConfiguration>(); _Configuration = new Configuration(); _Configuration.BaseStationSettings.LookupAircraftDetailsOnline = true; _SharedConfiguration.Setup(r => r.Get()).Returns(_Configuration); _Provider = TestUtilities.CreateMockImplementation <IAircraftOnlineLookupProvider>(); _Provider.SetupGet(r => r.MaxBatchSize).Returns(10); _Provider.SetupGet(r => r.MinSecondsBetweenRequests).Returns(1); _Provider.SetupGet(r => r.MaxSecondsAfterFailedRequest).Returns(5); _DoLookupResult = true; _ReportMissingIcaos = new List <string>(); _RequestedIcaos = null; _ProviderCallback = null; _Provider.Setup(r => r.DoLookup(It.IsAny <string[]>(), It.IsAny <IList <AircraftOnlineLookupDetail> >(), It.IsAny <IList <string> >())) .Returns((string[] icaos, IList <AircraftOnlineLookupDetail> fetched, IList <string> missing) => { _RequestedIcaos = icaos; if (icaos != null && fetched != null && missing != null) { foreach (var icao in icaos) { if (_ReportMissingIcaos.Contains(icao)) { missing.Add(icao); } else { fetched.Add(new AircraftOnlineLookupDetail() { Icao = icao }); } } } if (_ProviderCallback != null) { _ProviderCallback(); } return(_DoLookupResult); }); _FetchedRecorder = new EventRecorder <AircraftOnlineLookupEventArgs>(); _Lookup = Factory.Singleton.ResolveNewInstance <IAircraftOnlineLookup>(); }
public void TestInitialise() { _OriginalFactory = Factory.TakeSnapshot(); _Clock = new ClockMock(); _Timer = TestUtilities.CreateMockImplementation <ITimer>(); _Compressor = TestUtilities.CreateMockImplementation <IBaseStationMessageCompressor>(); _Server = Factory.Resolve <IRebroadcastServer>(); _Feed = TestUtilities.CreateMockInstance <IFeed>(); _Listener = TestUtilities.CreateMockInstance <IListener>(); _Feed.SetupGet(r => r.Listener).Returns(_Listener.Object); _Connector = new MockConnector <INetworkConnector, INetworkConnection>(); _AircraftListJsonBuilder = TestUtilities.CreateMockImplementation <IAircraftListJsonBuilder>(); _AircraftListJson = new AircraftListJson(); _AircraftListJsonBuilderArgs = null; _IgnoreInvisibleFeeds = null; _FallbackToDefault = null; _AircraftListJsonBuilder.Setup(r => r.Build(It.IsAny <AircraftListJsonBuilderArgs>(), It.IsAny <bool>(), It.IsAny <bool>())).Callback((AircraftListJsonBuilderArgs args, bool ignoreInvisibleFeeds, bool fallbackToDefault) => { _AircraftListJsonBuilderArgs = args; _IgnoreInvisibleFeeds = ignoreInvisibleFeeds; _FallbackToDefault = fallbackToDefault; }).Returns(_AircraftListJson); _AircraftList = TestUtilities.CreateMockImplementation <IBaseStationAircraftList>(); _Feed.SetupGet(r => r.AircraftList).Returns(_AircraftList.Object); _SnapshotAircraft = new List <IAircraft>(); long of1, of2; _AircraftList.Setup(m => m.TakeSnapshot(out of1, out of2)).Returns(_SnapshotAircraft); _Server.UniqueId = 1; _Server.Name = "It's the code word"; _Server.Format = RebroadcastFormat.Port30003; _Server.Feed = _Feed.Object; _Server.Connector = _Connector.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() { _OriginalFactory = Factory.TakeSnapshot(); _Clock = new ClockMock(); Factory.RegisterInstance <IClock>(_Clock.Object); _Fetcher = Factory.ResolveNewInstance <ICallsignRouteFetcher>(); _FetchedHandler = new EventRecorder <EventArgs <CallsignRouteDetail> >(); _Fetcher.Fetched += _FetchedHandler.Handler; _Aircraft = TestUtilities.CreateMockInstance <IAircraft>(); _AircraftCallsign = _RouteCallsign = "BAW1"; _AircraftOperatorCode = null; _Aircraft.Setup(r => r.Icao24).Returns("ABC123"); _Aircraft.Setup(r => r.Callsign).Returns(() => _AircraftCallsign); _Aircraft.Setup(r => r.OperatorIcao).Returns(() => _AircraftOperatorCode); _CallsignParser = TestUtilities.CreateMockImplementation <ICallsignParser>(); _CallsignParser.Setup(r => r.GetAllRouteCallsigns(It.IsAny <string>(), It.IsAny <string>())).Returns((string callsign, string operatorCode) => { List <string> result; if (callsign == null || !_RouteCallsigns.TryGetValue(callsign, out result)) { result = new List <string>(); } return(result); }); _RouteCallsigns = new Dictionary <string, List <string> >() { { "BAW1", new List <string>() { "BAW1" } } }; // The fetcher uses a private heartbeat service to avoid slowing the GUI down. Unfortunately // the TestUtilities don't support creating non-singleton instances of ISingletons, do we // have to do it manually. _Heartbeat = TestUtilities.CreateMockInstance <IHeartbeatService>(); Factory.RegisterInstance <IHeartbeatService>(_Heartbeat.Object); _StandingDataManager = TestUtilities.CreateMockSingleton <IStandingDataManager>(); _Route = null; _StandingDataManager.Setup(r => r.FindRoute(It.IsAny <string>())).Returns((string callsign) => { return(callsign == _RouteCallsign ? _Route : null); }); _LookupAirlines = new List <Airline>(); _StandingDataManager.Setup(r => r.FindAirlinesForCode(It.IsAny <string>())).Returns((string code) => { return(_LookupAirlines); }); }
public void TestInitialise() { _Snapshot = Factory.TakeSnapshot(); _FetchedRecorder = new EventRecorder <AircraftOnlineLookupEventArgs>(); _Clock = new ClockMock(); Factory.Singleton.RegisterInstance <IClock>(_Clock.Object); _Lookup = TestUtilities.CreateMockSingleton <IAircraftOnlineLookup>(); _LookupUsed = new List <string>(); _LookupIcaos = new List <string>(); _LookupResponds = true; _Lookup.Setup(r => r.Lookup(It.IsAny <string>())).Callback((string icao) => { _LookupUsed.Add(icao); if (_LookupResponds) { var args = BuildAircraftOnlineLookupEventArgs(new string[] { icao }, _LookupIcaos); _Lookup.Raise(r => r.AircraftFetched += null, args); } }); _Lookup.Setup(r => r.LookupMany(It.IsAny <IEnumerable <string> >())).Callback((IEnumerable <string> icaos) => { _LookupUsed.AddRange(icaos); if (_LookupResponds) { var args = BuildAircraftOnlineLookupEventArgs(icaos, _LookupIcaos); _Lookup.Raise(r => r.AircraftFetched += null, args); } }); _Cache1 = TestUtilities.CreateMockInstance <IAircraftOnlineLookupCache>(); _Cache2 = TestUtilities.CreateMockInstance <IAircraftOnlineLookupCache>(); _Cache1Icaos = new List <string>(); _Cache2Icaos = new List <string>(); _SavedDetails = new List <AircraftOnlineLookupDetail>(); _RecordedMissingIcaos = new List <string>(); _LookupCacheUsed = new List <int>(); _SaveCacheUsed = new List <int>(); _SaveCallback = null; _CreateCacheRecordCallback = null; SetupCache(1, _Cache1, _Cache1Icaos); SetupCache(2, _Cache2, _Cache2Icaos); _Manager = Factory.Singleton.Resolve <IAircraftOnlineLookupManager>(); _Manager.RegisterCache(_Cache1.Object, 1, false); _Manager.RegisterCache(_Cache2.Object, 2, false); // <-- this has a higher priority and should take precedence }
public void TestInitialise() { _ClassFactorySnapshot = Factory.TakeSnapshot(); _Statistics = StatisticsHelper.CreateLockableStatistics(); _HeartbeatService = TestUtilities.CreateMockSingleton <IHeartbeatService>(); _Clock = new ClockMock(); Factory.Singleton.RegisterInstance <IClock>(_Clock.Object); _Presenter = Factory.Singleton.Resolve <IStatisticsPresenter>(); _View = TestUtilities.CreateMockInstance <IStatisticsView>(); _View.Setup(r => r.Statistics).Returns(_Statistics.Object); _View.Setup(r => r.AdsbMessageTypeCount).Returns(new long[256]); _View.Setup(r => r.ModeSDFStatistics).Returns(new ModeSDFStatistics[32]); _View.Setup(r => r.AdsbMessageFormatCount).Returns(new long[Enum.GetValues(typeof(MessageFormat)).OfType <MessageFormat>().Select(r => (int)r).Max() + 1]); }
public void LoadsCsv() { // Arrange Guid profileId = Guid.NewGuid(); var profile = new AwsProfile { Id = profileId, DetailedBillingS3Bucket = "my-bucket", IsBillingHistoryLoaded = true, Account = "12345", }; AwsProfileRepositoryMock.Setup(x => x.Find(profileId)).Returns(profile); AwsClientFactoryMock.Setup(x => x.GetClient(profile)).Returns(AwsClientMock.Object); var storage = new TestStorageService(); AwsClientMock.Setup(x => x.StorageService).Returns(storage); storage.Contents = new MemoryStream(Resources.LineItemsZip); var now = new DateTime(2014, 6, 14, 16, 15, 14, DateTimeKind.Utc); ClockMock.Setup(x => x.UtcNow).Returns(now); var command = new UpdateBillingData(AwsClientFactory, AwsProfileRepository, BillingManager, Clock, new S3PathParser()); string loadedPeriod = null; LineItem lineItem = null; BillingManagerMock.Setup(x => x.LoadLineItems(It.IsAny <IEnumerable <LineItem> >(), It.IsAny <string>())) .Callback((IEnumerable <LineItem> lineItems, string period) => { lineItem = lineItems.FirstOrDefault(); loadedPeriod = period; }); // Act command.LoadDeltas(profileId); // Assert loadedPeriod.Should().Be("2014-06"); lineItem.RecordId.Should().Be("31861622192480759163092020", "should match first line item from line-items.csv embedded resource"); }
public void TestInitialise() { _OriginalFactory = Factory.TakeSnapshot(); _SharedConfiguration = TestUtilities.CreateMockSingleton <ISharedConfiguration>(); _Configuration = new Configuration(); _SharedConfiguration.Setup(cs => cs.Get()).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>(); _UserManager = TestUtilities.CreateMockSingleton <IUserManager>(); _Feeds = new List <Mock <IFeed> >(); _Listeners = new List <Mock <IListener> >(); var useVisibleFeeds = false; _FeedManager = FeedHelper.CreateMockFeedManager(_Feeds, _Listeners, useVisibleFeeds, 1, 2); _Clock = new ClockMock(); Factory.Singleton.RegisterInstance <IClock>(_Clock.Object); _Presenter = Factory.Singleton.Resolve <IMainPresenter>(); _View = new Mock <IMainView>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); }
public void GetNextStop_Ok() { // Arrange var stack = new Stack { ScheduleId = Guid.NewGuid() }; var schedule = new Schedule { Id = stack.ScheduleId, StopCron = "* 18 * * 1-5" }; ScheduleRepositoryMock.Setup(x => x.Find(schedule.Id)).Returns(schedule); ClockMock.Setup(x => x.Now).Returns(new DateTime(2015, 10, 1, 17, 0, 0)); var expected = new TimeSpan(1, 0, 0); // Act var result = Calculator.GetNextStop(stack); // Assert result.Should().Be(expected); }
public void TestInitialise() { _ClassFactorySnapshot = Factory.TakeSnapshot(); _Clock = new ClockMock(); Factory.Singleton.RegisterInstance <IClock>(_Clock.Object); _LogClients = new List <LogClient>(); _LogSessions = new Dictionary <long, IList <LogSession> >(); _LogDatabase = TestUtilities.CreateMockSingleton <ILogDatabase>(); _LogDatabase.Setup(d => d.FetchAll(It.IsAny <IList <LogClient> >(), It.IsAny <IDictionary <long, IList <LogSession> > >())).Callback((IList <LogClient> clients, IDictionary <long, IList <LogSession> > sessions) => { foreach (var client in _LogClients) { clients.Add(client); } foreach (var kvpSession in _LogSessions) { sessions.Add(kvpSession.Key, kvpSession.Value); } }); _Log = TestUtilities.CreateMockSingleton <ILog>(); _Presenter = Factory.Singleton.Resolve <IConnectionClientLogPresenter>(); _Provider = new Mock <IConnectionClientLogPresenterProvider>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Provider.Setup(p => p.InvokeOnBackgroundThread(It.IsAny <Action <IList <LogClient> > >(), It.IsAny <IList <LogClient> >())).Callback((Action <IList <LogClient> > callback, IList <LogClient> clients) => { callback(clients); }); _Presenter.Provider = _Provider.Object; _View = new Mock <IConnectionClientLogView>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); }
public void TestInitialise() { _OriginalClassFactory = Factory.TakeSnapshot(); _Clock = new ClockMock(); Factory.Singleton.RegisterInstance <IClock>(_Clock.Object); _AircraftList = Factory.Singleton.Resolve <ISimpleAircraftList>(); _Aircraft = new Mock <IAircraft>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Aircraft.Setup(m => m.Clone()).Returns(() => { var result = new Mock <IAircraft>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); result.Object.UniqueId = _Aircraft.Object.UniqueId; return(result.Object); }); }
public void QueriesCorrectS3Object() { // Arrange Guid profileId = Guid.NewGuid(); var lastModified = new DateTime(2014, 6, 14, 13, 12, 11, DateTimeKind.Utc); var profile = new AwsProfile { Id = profileId, DetailedBillingS3Bucket = "my-bucket", Account = "12345", IsBillingHistoryLoaded = true, BillingMetadata = { { "2014-06", new BillingMetadata { LastModified = lastModified } } } }; AwsProfileRepositoryMock.Setup(x => x.Find(profileId)).Returns(profile); AwsClientFactoryMock.Setup(x => x.GetClient(profile)).Returns(AwsClientMock.Object); var storage = new TestStorageService(); AwsClientMock.Setup(x => x.StorageService).Returns(storage); var now = new DateTime(2014, 6, 14, 16, 15, 14, DateTimeKind.Utc); ClockMock.Setup(x => x.UtcNow).Returns(now); var command = new UpdateBillingData(AwsClientFactory, AwsProfileRepository, BillingManager, Clock, new S3PathParser()); // Act command.LoadDeltas(profileId); // Assert string expectedUrl = UpdateBillingData.MonthlyCsvUrl.Create("my-bucket", "12345", "2014-06"); storage.S3Url.Should().Be(expectedUrl); storage.LastModified.Should().Be(lastModified); storage.CallCount.Should().Be(1); }
public void TestInitialise() { _ClassFactorySnapshot = Factory.TakeSnapshot(); _Clock = new ClockMock(); Factory.RegisterInstance <IClock>(_Clock.Object); _WebServer = TestUtilities.CreateMockImplementation <IWebServer>(); _WebServerProvider = TestUtilities.CreateMockImplementation <IWebServerProvider>(); _WebServer.Setup(r => r.Provider).Returns(_WebServerProvider.Object); _RuntimeEnvironment = TestUtilities.CreateMockSingleton <IRuntimeEnvironment>(); _ExternalIPAddressService = TestUtilities.CreateMockSingleton <IExternalIPAddressService>(); _HeartbeatService = TestUtilities.CreateMockSingleton <IHeartbeatService>(); _Log = TestUtilities.CreateMockSingleton <ILog>(); _Configuration = new Configuration(); _ConfigurationStorage = TestUtilities.CreateMockSingleton <IConfigurationStorage>(); _ConfigurationStorage.Setup(s => s.Load()).Returns(_Configuration); _InstallerSettingsStorage = TestUtilities.CreateMockImplementation <IInstallerSettingsStorage>(); _InstallerSettings = new InstallerSettings(); _InstallerSettingsStorage.Setup(s => s.Load()).Returns(_InstallerSettings); _AutoConfigWebServer = Factory.ResolveNewInstance <IAutoConfigWebServer>(); }
public void SetsLastModified() { // Arrange Guid profileId = Guid.NewGuid(); var profile = new AwsProfile { Id = profileId, DetailedBillingS3Bucket = "my-bucket", IsBillingHistoryLoaded = true, Account = "12345", }; AwsProfileRepositoryMock.Setup(x => x.Find(profileId)).Returns(profile); AwsClientFactoryMock.Setup(x => x.GetClient(profile)).Returns(AwsClientMock.Object); var now = new DateTime(2014, 6, 14, 16, 15, 14, DateTimeKind.Utc); ClockMock.Setup(x => x.UtcNow).Returns(now); var storage = new TestStorageService(); AwsClientMock.Setup(x => x.StorageService).Returns(storage); storage.NewLastModified = new DateTime(2020, 1, 1, 1, 1, 1, DateTimeKind.Utc); storage.Contents = new MemoryStream(Resources.LineItemsZip); var command = new UpdateBillingData(AwsClientFactory, AwsProfileRepository, BillingManager, Clock, new S3PathParser()); // Act command.LoadDeltas(profileId); // Assert AwsProfileRepositoryMock.Verify( x => x.Update(It.Is((AwsProfile p) => p.Id == profileId && p.BillingMetadata["2014-06"].LastModified == storage.NewLastModified) )); }
public void TestInitialise() { _ClassFactorySnapshot = Factory.TakeSnapshot(); _ConfigurationStorage = TestUtilities.CreateMockSingleton <IConfigurationStorage>(); _ConfigurationStorage.Object.Folder = @"ztt:\ump"; _FullPath = Path.Combine(_ConfigurationStorage.Object.Folder, _FileName); _Clock = new ClockMock() { UtcNowValue = new DateTime(2001, 2, 3, 4, 5, 6, 789) }; Factory.RegisterInstance <IClock>(_Clock.Object); _Provider = new Mock <ILogProvider>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Provider.Setup(p => p.FileExists(It.IsAny <string>())).Returns(true); _Provider.Setup(p => p.FolderExists(It.IsAny <string>())).Returns(true); _Log = Factory.ResolveNewInstance <ILog>(); _Log.Provider = _Provider.Object; }
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); _NestedTransactionCount = 0; _LogDatabase.Setup(r => r.PerformInTransaction(It.IsAny <Func <bool> >())).Callback((Func <bool> r) => { if (++_NestedTransactionCount > 1) { throw new InvalidOperationException("Nested transactions are not allowed"); } r(); --_NestedTransactionCount; }); _ConnectionLogger = Factory.Singleton.ResolveNewInstance <IConnectionLogger>(); _ConnectionLogger.WebServer = _WebServer.Object; _ConnectionLogger.LogDatabase = _LogDatabase.Object; }
public void TestInitialise() { _ClassFactorySnapshot = Factory.TakeSnapshot(); _Clock = new ClockMock() { UtcNowValue = _StandardDate }; Factory.RegisterInstance <IClock>(_Clock.Object); 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>(); _LastModifiedUtc = new DateTime(2009, 8, 7, 6, 5, 4, 321); _Files = new Dictionary <string, List <TestFileInfo> >(); _Folders = new List <string>(); _Provider = new Mock <IDirectoryCacheProvider>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties(); _Provider.Setup(p => p.FolderExists(It.IsAny <string>())).Returns((string folder) => { if (folder != null && folder.EndsWith(@"\")) { folder = folder.Substring(0, folder.Length - 1); } return(_Folders.Contains(folder.ToLower())); }); _Provider.Setup(p => p.GetSubFoldersInFolder(It.IsAny <string>())).Returns((string folder) => { if (folder != null && !folder.EndsWith(@"\")) { folder += '\\'; } var subFolders = _Folders.Where(r => r.StartsWith(folder, StringComparison.OrdinalIgnoreCase) && r.IndexOf('\\', folder.Length) == -1) .Select(r => Path.GetFileName(r)) .ToList(); return(subFolders); }); _Provider.Setup(p => p.GetFilesInFolder(It.IsAny <string>())).Returns((string folder) => { List <TestFileInfo> files; if (folder != null && folder.EndsWith(@"\")) { folder = folder.Substring(0, folder.Length - 1); } _Files.TryGetValue(folder.ToLower(), out files); return((IEnumerable <TestFileInfo>)files ?? new TestFileInfo[0]); }); _Provider.Setup(p => p.GetFileInfo(It.IsAny <string>())).Returns((string fullPath) => { TestFileInfo result = null; var folder = (Path.GetDirectoryName(fullPath) ?? "").ToLower(); var fileName = Path.GetFileName(fullPath); List <TestFileInfo> files; if (_Files.TryGetValue(folder, out files)) { result = files.FirstOrDefault(r => r.Name.Equals(fileName, StringComparison.OrdinalIgnoreCase)); } return(result); }); _DirectoryCache = Factory.Resolve <IDirectoryCache>(); _DirectoryCache.Provider = _Provider.Object; }
public void TestInitialise() { _OriginalFactory = Factory.TakeSnapshot(); _RuntimeEnvironment = TestUtilities.CreateMockSingleton <IRuntimeEnvironment>(); _RuntimeEnvironment.Setup(r => r.IsTest).Returns(true); _Clock = new ClockMock(); Factory.RegisterInstance <IClock>(_Clock.Object); _Fetcher = Factory.ResolveNewInstance <IAircraftDetailFetcher>(); _FetchedHandler = new EventRecorder <EventArgs <AircraftDetail> >(); _Fetcher.Fetched += _FetchedHandler.Handler; _Aircraft = TestUtilities.CreateMockInstance <IAircraft>(); _Aircraft.Setup(r => r.Icao24).Returns("ABC123"); // The fetcher uses a private heartbeat service to avoid slowing the GUI down. Unfortunately // the TestUtilities don't support creating non-singleton instances of ISingletons, do we // have to do it manually. _Heartbeat = TestUtilities.CreateMockInstance <IHeartbeatService>(); Factory.RegisterInstance <IHeartbeatService>(_Heartbeat.Object); _AutoConfigDatabase = TestUtilities.CreateMockSingleton <IAutoConfigBaseStationDatabase>(); _Database = TestUtilities.CreateMockInstance <IBaseStationDatabase>(); _AutoConfigDatabase.Setup(r => r.Database).Returns(_Database.Object); _DatabaseAircraftAndFlights = null; _GetManyAircraftAndFlightsByCodes = new List <string>(); _GetManyAircraftByCodes = new List <string>(); _Database.Setup(r => r.GetManyAircraftByCode(It.IsAny <IEnumerable <string> >())).Returns((IEnumerable <string> icaos) => { var result = new Dictionary <string, BaseStationAircraft>(); if (icaos != null && icaos.Count() == 1 && icaos.First() == "ABC123" && _DatabaseAircraft != null) { result.Add("ABC123", _DatabaseAircraft); } if (icaos != null) { _GetManyAircraftByCodes.AddRange(icaos); } return(result); }); _Database.Setup(r => r.GetManyAircraftAndFlightsCountByCode(It.IsAny <IEnumerable <string> >())).Returns((IEnumerable <string> icaos) => { var result = new Dictionary <string, BaseStationAircraftAndFlightsCount>(); if (icaos != null && icaos.Count() == 1 && icaos.First() == "ABC123" && _DatabaseAircraftAndFlights != null) { result.Add("ABC123", _DatabaseAircraftAndFlights); } if (icaos != null) { _GetManyAircraftAndFlightsByCodes.AddRange(icaos); } return(result); }); _AutoConfigPictureFolderCache = TestUtilities.CreateMockSingleton <IAutoConfigPictureFolderCache>(); _PictureFolderCache = TestUtilities.CreateMockInstance <IDirectoryCache>(); _AutoConfigPictureFolderCache.Setup(r => r.DirectoryCache).Returns(() => _PictureFolderCache.Object); _AircraftPictureManager = TestUtilities.CreateMockSingleton <IAircraftPictureManager>(); _PictureManagerCache = _PictureFolderCache.Object; _PictureManagerIcao24 = "INVALID"; _PictureManagerReg = null; _PictureManagerThrowException = false; _PictureDetail = new PictureDetail(); _AircraftPictureManager.Setup(r => r.FindPicture(It.IsAny <IDirectoryCache>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <PictureDetail>())).Returns((IDirectoryCache cache, string icao24, string reg, PictureDetail existingPictureDetail) => { if (_PictureManagerThrowException) { throw new InvalidOperationException(); } return(cache == _PictureManagerCache && icao24 == _PictureManagerIcao24 && reg == _PictureManagerReg ? _PictureDetail : null); }); _StandingDataManager = TestUtilities.CreateMockSingleton <IStandingDataManager>(); _AircraftType = new AircraftType(); _StandingDataManager.Setup(r => r.FindAircraftType(It.IsAny <string>())).Returns((string type) => { return(type == _FindAircraftType ? _AircraftType : null); }); _Log = TestUtilities.CreateMockSingleton <ILog>(); _Log.Setup(r => r.WriteLine(It.IsAny <string>())).Callback((string x) => { throw new InvalidOperationException(x); }); _Log.Setup(r => r.WriteLine(It.IsAny <string>(), It.IsAny <object[]>())).Callback((string x, object[] args) => { throw new InvalidOperationException(String.Format(x, args)); }); _AircraftOnlineLookupManager = TestUtilities.CreateMockSingleton <IAircraftOnlineLookupManager>(); }