Пример #1
0
        public async Task Run_RawOccurrancesProcessedOnceForNonUniqueResponseScheduleUntilHoursBackToRetrieve()
        {
            #region arrange
            IDateTimeOffsetProvider dateTimeOffsetProvider = Substitute.For <IDateTimeOffsetProvider>();
            DateTimeOffset          now = DateTimeOffset.MaxValue.Subtract(TimeSpan.FromSeconds(86399));
            dateTimeOffsetProvider.UtcNow.Returns(now);

            IRadiocomClient     client     = Substitute.For <IRadiocomClient>();
            IRadiocomRepository repository = Substitute.For <IRadiocomRepository>();
            IOptions <RadiocomDataCollectorEngineOptions> optionsSnapshot = Substitute.For <IOptions <RadiocomDataCollectorEngineOptions> >();
            RadiocomDataCollectorEngineOptions            options         = new RadiocomDataCollectorEngineOptions()
            {
                HoursBackToRetrive = 5
            };
            optionsSnapshot.Value.Returns(options);


            Task <StationRecentlyPlayedResponse> response = Task.FromResult(GetStationRecentlyPlayedResponse());
            client
            .StationRecentlyPlayed(Arg.Any <int>(), Arg.Any <int>(), Arg.Any <ApiWrapper.Radiocom.DayOfWeek>())
            .Returns(response);

            repository.ProcessRawOccurrances(Arg.Any <IEnumerable <RawArtistWorkStationOccurrence> >())
            .Returns(response.Result.Schedule.Count, 0);
            RadiocomDataCollectorEngine engine = new RadiocomDataCollectorEngine(client, repository, optionsSnapshot, dateTimeOffsetProvider, log);

            #endregion arrange
            #region act
            await engine.Run();

            #endregion act
            #region assert
            List <ICall> clientCalls = client.ReceivedCalls().AsList();


            await repository.Received(1).ProcessRawOccurrances(Arg.Any <IEnumerable <RawArtistWorkStationOccurrence> >());

            Assert.AreEqual(902, (int)clientCalls[0].GetArguments()[0]);
            Assert.AreEqual(902, (int)clientCalls[1].GetArguments()[0]);
            Assert.AreEqual(902, (int)clientCalls[2].GetArguments()[0]);
            Assert.AreEqual(902, (int)clientCalls[3].GetArguments()[0]);
            Assert.AreEqual(902, (int)clientCalls[4].GetArguments()[0]);

            Assert.AreEqual(now.Hour, (int)clientCalls[0].GetArguments()[1]);
            Assert.AreEqual(now.AddHours(-1).Hour, (int)clientCalls[1].GetArguments()[1]);
            Assert.AreEqual(now.AddHours(-2).Hour, (int)clientCalls[2].GetArguments()[1]);
            Assert.AreEqual(now.AddHours(-3).Hour, (int)clientCalls[3].GetArguments()[1]);
            Assert.AreEqual(now.AddHours(-4).Hour, (int)clientCalls[4].GetArguments()[1]);

            now = ConvertTime(now);
            Assert.AreEqual(now.DayOfWeek.ToRadiocomDayOfWeek().ToString(), clientCalls[0].GetArguments()[2].ToString());


            Assert.AreEqual(now.DayOfWeek.ToString(), clientCalls[1].GetArguments()[2].ToString());
            Assert.AreEqual(now.DayOfWeek.ToString(), clientCalls[2].GetArguments()[2].ToString());
            Assert.AreEqual(now.DayOfWeek.ToString(), clientCalls[3].GetArguments()[2].ToString());
            Assert.AreEqual(now.DayOfWeek.ToString(), clientCalls[4].GetArguments()[2].ToString());

            #endregion assert
        }
Пример #2
0
 public RadiocomEngineRunner(RadiocomDataCollectorEngine radiocomDataCollectorEngine)
 {
     _radiocomDataCollectorEngine = radiocomDataCollectorEngine;
 }
Пример #3
0
 public Function1(RadiocomDataCollectorEngine radiocomDataCollectorEngine)
 {
     _radiocomDataCollectorEngine = radiocomDataCollectorEngine;
 }