Esempio n. 1
0
        public void Setup()
        {
            httpClient       = Substitute.For <IHTTPClient>();
            newSessions      = new List <SessionWrapper>();
            openSessions     = new List <SessionWrapper>();
            finishedSessions = new List <SessionWrapper>();

            // provider
            timingProvider     = Substitute.For <ITimingProvider>();
            httpClientProvider = Substitute.For <IHTTPClientProvider>();
            httpClientProvider.CreateClient(Arg.Any <HTTPClientConfiguration>()).Returns(x => httpClient);

            // context
            context = Substitute.For <IBeaconSendingContext>();
            context.GetHTTPClient().Returns(httpClient);
            context.HTTPClientProvider.Returns(httpClientProvider);

            // beacon sender
            var logger = Substitute.For <ILogger>();

            beaconSender = new BeaconSender(logger, context);

            // sessions
            context.NewSessions.Returns(newSessions);
            context.OpenAndConfiguredSessions.Returns(openSessions);
            context.FinishedAndConfiguredSessions.Returns(finishedSessions);
        }
Esempio n. 2
0
        public void Setup()
        {
            currentTime      = 1;
            newSessions      = new List <SessionWrapper>();
            openSessions     = new List <SessionWrapper>();
            finishedSessions = new List <SessionWrapper>();

            // http client
            httpClient = Substitute.For <IHTTPClient>();

            // provider
            timingProvider = Substitute.For <ITimingProvider>();
            timingProvider.ProvideTimestampInMilliseconds().Returns(x => { return(++currentTime); }); // every access is a tick
            httpClientProvider = Substitute.For <IHTTPClientProvider>();
            httpClientProvider.CreateClient(Arg.Any <HTTPClientConfiguration>()).Returns(x => httpClient);

            // context
            context = Substitute.For <IBeaconSendingContext>();
            context.HTTPClientProvider.Returns(x => httpClientProvider);
            context.GetHTTPClient().Returns(x => httpClient);
            context.IsCaptureOn.Returns(true);

            // beacon sender
            logger       = Substitute.For <ILogger>();
            beaconSender = new BeaconSender(logger, config, httpClientProvider, timingProvider);

            // current time getter
            context.CurrentTimestamp.Returns(x => timingProvider.ProvideTimestampInMilliseconds());

            // sessions
            context.NewSessions.Returns(newSessions);
            context.OpenAndConfiguredSessions.Returns(openSessions);
            context.FinishedAndConfiguredSessions.Returns(finishedSessions);
        }
Esempio n. 3
0
        public void SetUp()
        {
            var logger = Substitute.For <ILogger>();

            logger.IsDebugEnabled.Returns(true);

            var beaconSendingContext = Substitute.For <IBeaconSendingContext>();
            var beaconSender         = new BeaconSender(logger, beaconSendingContext);

            var configuration = new TestConfiguration();
            var beacon        = new Beacon(logger,
                                           new Caching.BeaconCache(logger), configuration, "127.0.0.1", Substitute.For <IThreadIDProvider>(), Substitute.For <ITimingProvider>());

            wrappedSession = new Session(logger, beaconSender, beacon);
        }
Esempio n. 4
0
        public void Setup()
        {
            currentTime      = 1;
            lastTimeSyncTime = 1;
            newSessions      = new List <SessionWrapper>();
            openSessions     = new List <SessionWrapper>();
            finishedSessions = new List <SessionWrapper>();

            // http client
            httpClient = Substitute.For <IHTTPClient>();

            // provider
            timingProvider = Substitute.For <ITimingProvider>();
            timingProvider.ProvideTimestampInMilliseconds().Returns(x => { return(++currentTime); }); // every access is a tick
            httpClientProvider = Substitute.For <IHTTPClientProvider>();
            httpClientProvider.CreateClient(Arg.Any <HTTPClientConfiguration>()).Returns(x => httpClient);

            // context
            context = Substitute.For <IBeaconSendingContext>();
            context.HTTPClientProvider.Returns(x => httpClientProvider);
            context.GetHTTPClient().Returns(x => httpClient);
            context.LastTimeSyncTime.Returns(x => currentTime); // always return the current time to prevent re-sync
            context.IsCaptureOn.Returns(true);

            // beacon sender
            var logger = Substitute.For <ILogger>();

            beaconSender = new BeaconSender(logger, config, httpClientProvider, timingProvider);

            // return true by default
            context.IsTimeSyncSupported.Returns(true);

            // current time getter
            context.CurrentTimestamp.Returns(x => timingProvider.ProvideTimestampInMilliseconds());

            // last time sycn getter + setter
            context.LastTimeSyncTime = Arg.Do <long>(x => lastTimeSyncTime = x);
            context.LastTimeSyncTime = lastTimeSyncTime;

            // sessions
            context.NewSessions.Returns(newSessions);
            context.OpenAndConfiguredSessions.Returns(openSessions);
            context.FinishedAndConfiguredSessions.Returns(finishedSessions);
        }
        public void Setup()
        {
            httpClient       = Substitute.For <IHTTPClient>();
            finishedSessions = new Queue <Session>();
            openSessions     = new List <Session>();

            // provider
            timingProvider     = Substitute.For <ITimingProvider>();
            httpClientProvider = Substitute.For <IHTTPClientProvider>();
            httpClientProvider.CreateClient(Arg.Any <HTTPClientConfiguration>()).Returns(x => httpClient);

            // context
            context = Substitute.For <IBeaconSendingContext>();
            context.GetHTTPClient().Returns(httpClient);
            context.HTTPClientProvider.Returns(httpClientProvider);

            // beacon sender
            beaconSender = new BeaconSender(context);

            // sessions
            context.GetAllOpenSessions().Returns(openSessions);
            context.GetNextFinishedSession().Returns(x => (finishedSessions.Count == 0) ? null : finishedSessions.Dequeue());
        }