public void Start_WhenFileNotificationIsYield_ShouldCallSynchronize( [Frozen]TestScheduler scheduler, [Frozen(As = typeof(IObservable<MusicMirrorConfiguration>))]TestObservableWrapper<MusicMirrorConfiguration> configurationObservable, [Frozen]Mock<IFileObserverFactory> fileObserverFactory, [Frozen]Mock<IFileSynchronizerVisitorFactory> fileSynchronizerFactory, SynchronizeFilesWhenFileChanged sut, MusicMirrorConfiguration configuration, IFileNotification[][] fileNotification, Mock<IFileSynchronizerVisitor> fileSynchronizerVisitor) { //arrange configurationObservable.SetObservable(scheduler.CreateHotObservable(OnNext(Subscribed + 1, configuration))); const long NotificationsStart = Subscribed + 2; var fileObserver = scheduler.CreateHotObservable( fileNotification.Select((f, i) => OnNext(NotificationsStart + i, f)).ToArray()); fileObserverFactory.Setup(f => f.GetFileObserver(configuration.SourcePath)).Returns(fileObserver); fileSynchronizerFactory.Setup(f => f.CreateVisitor(configuration)).Returns(fileSynchronizerVisitor.Object); //act sut.Start(); scheduler.Start(); //assert foreach (var m in fileNotification.SelectMany(f => f).Select(f => Mock.Get(f))) { m.Verify(ff => ff.Accept(It.IsAny<CancellationToken>(), fileSynchronizerVisitor.Object)); } }
public void SynchronizedFileCount_WhenTranscodingIsRunning_AndTranscodingResultsArePushedWithFailures_ShouldReturnCorrectValue( [Frozen]TestSchedulers schedulers, [Frozen]Mock<ITranscodingNotifications> notifications, IFileNotification[] fileNotifications, IFileNotification[] failuresNotifications, Fixture fixture) { //arrange var notificationsObservable = schedulers.CreateHotObservable( OnNext(201, true)); var transcodingResultsObservable = schedulers.CreateHotObservable( fileNotifications.Select((f, i) => OnNext(203 + i, FileTranscodingResultNotification.CreateSuccess(f))) .Concat(failuresNotifications.Select((f, i) => OnNext(203 + fileNotifications.Length + i, FileTranscodingResultNotification.CreateFailure(f, new Exception())))) .ToArray()); notifications.Setup(n => n.ObserveIsTranscodingRunning()).Returns(notificationsObservable); notifications.Setup(n => n.ObserveTranscodingResult()).Returns(transcodingResultsObservable); var sut = fixture.Create<ConfigurationPageViewModel>(); //act var actual = schedulers.Start(() => sut.SynchronizedFileCount); //assert var expected = new[] { OnNext(Subscribed, SynchronizedFilesCountViewModel.Empty), } .Concat(fileNotifications.Select((f, i) => OnNext(203 + i, new SynchronizedFilesCountViewModel(i + 1, 0))).ToArray()); actual.Messages.ShouldAllBeEquivalentTo(expected); }
public void SynchronizedFileCount_WhenTranscodingIsRunningChangesSeveralTimes_AndTranscodingResultsArePushed_ShouldReturnCorrectValue( [Frozen]TestSchedulers schedulers, [Frozen]Mock<ITranscodingNotifications> notifications, IFileNotification[] fileNotifications, Fixture fixture) { //arrange var notificationsObservable = schedulers.CreateHotObservable( OnNext(Subscribed + 1, false), OnNext(Subscribed + 100, true), OnNext(Subscribed + 199, false), OnNext(Subscribed + 200, true), OnNext(Subscribed + 299, false), OnNext(Subscribed + 300, true), OnNext(Subscribed + 399, false)); Func<long, IEnumerable<Recorded<Notification<IFileTranscodingResultNotification>>>> createFileNotifications = offset => fileNotifications.Select((f, i) => OnNext(offset + i, FileTranscodingResultNotification.CreateSuccess(f))); var transcodingResultsObservable = schedulers.CreateHotObservable( createFileNotifications(Subscribed + 101) .Concat(createFileNotifications(Subscribed + 201)) .Concat(createFileNotifications(Subscribed + 301)) .ToArray() ); notifications.Setup(n => n.ObserveIsTranscodingRunning()).Returns(notificationsObservable); notifications.Setup(n => n.ObserveTranscodingResult()).Returns(transcodingResultsObservable); var sut = fixture.Create<ConfigurationPageViewModel>(); //act var actual = schedulers.Start(() => sut.SynchronizedFileCount.Do(_ => { })); //assert Func<long, IEnumerable<Recorded<Notification<SynchronizedFilesCountViewModel>>>> createExpectedFileNotifications = offset => fileNotifications.Select((f, i) => OnNext(offset + i, new SynchronizedFilesCountViewModel(i + 1, 0))); var expected = new[] { OnNext(Subscribed, SynchronizedFilesCountViewModel.Empty), } .Concat(createExpectedFileNotifications(Subscribed + 101)) .Concat(createExpectedFileNotifications(Subscribed + 201)) .Concat(createExpectedFileNotifications(Subscribed + 301)) .ToArray(); actual.Messages.ShouldAllBeEquivalentTo(expected); }
public void SynchronizedFileCount_WhenTranscodingIsRunningChangesSeveralTimes_AndFileNotificationsArePushedSeveralTimes_ShouldReturnCorrectValue( [Frozen]TestSchedulers schedulers, [Frozen]Mock<ITranscodingNotifications> notifications, IFileNotification[][] fileNotifications, Fixture fixture) { //arrange const int TranscodingStoppedRelativeTime = 50; var fileNotificationsObservable = schedulers.CreateHotObservable( fileNotifications.Select((f, i) => OnNext(Subscribed + i + 101, f)) .Concat(fileNotifications.Select((f, i) => OnNext(Subscribed + i + 201, f))) .Concat(fileNotifications.Select((f, i) => OnNext(Subscribed + i + 301, f))) .ToArray() ); var notificationsObservable = schedulers.CreateHotObservable( OnNext(Subscribed + 1, false), OnNext(Subscribed + 100, true), OnNext(Subscribed + 100 + TranscodingStoppedRelativeTime, false), OnNext(Subscribed + 200, true), OnNext(Subscribed + 200 + TranscodingStoppedRelativeTime, false), OnNext(Subscribed + 300, true), OnNext(Subscribed + 300 + TranscodingStoppedRelativeTime, false)); notifications.Setup(n => n.ObserveIsTranscodingRunning()).Returns(notificationsObservable); notifications.Setup(n => n.ObserveNotifications()).Returns(fileNotificationsObservable); var sut = fixture.Create<ConfigurationPageViewModel>(); //act var actual = schedulers.Start(() => sut.SynchronizedFileCount); //assert var expected = OnNext(Subscribed, SynchronizedFilesCountViewModel.Empty).Yield() .Concat(CreateExpectedFileNotifications(fileNotifications, 101)) .Concat(CreateExpectedFileNotifications(fileNotifications, 201)) .Concat(CreateExpectedFileNotifications(fileNotifications, 301)) .ToArray(); actual.Messages.ShouldAllBeEquivalentTo(expected); }
public void ObserveTranscodingResult_WhenFileNotificationIsYield_ShouldReturnCorrectValue( [Frozen]TestScheduler scheduler, [Frozen(As = typeof(IObservable<MusicMirrorConfiguration>))]TestObservableWrapper<MusicMirrorConfiguration> configurationObservable, [Frozen]Mock<IFileObserverFactory> fileObserverFactory, [Frozen]Mock<IFileSynchronizerVisitorFactory> fileSynchronizerFactory, SynchronizeFilesWhenFileChanged sut, MusicMirrorConfiguration configuration, IFileNotification[][] fileNotification, Mock<IFileSynchronizerVisitor> fileSynchronizerVisitor) { //arrange sut.SynchronizationScheduler = ImmediateScheduler.Instance; configurationObservable.SetObservable(scheduler.CreateHotObservable(OnNext(Subscribed + 1, configuration))); const long NotificationsStart = Subscribed + 2; var fileObserver = scheduler.CreateHotObservable( fileNotification.Select((f, i) => OnNext(NotificationsStart + i, f)).ToArray()); fileObserverFactory.Setup(f => f.GetFileObserver(configuration.SourcePath)).Returns(fileObserver); fileSynchronizerFactory.Setup(f => f.CreateVisitor(configuration)).Returns(fileSynchronizerVisitor.Object); scheduler.Schedule(200.Ticks(), () => sut.Start()); //act var actual = scheduler.Start(() => sut.ObserveTranscodingResult()); //assert var expected = fileNotification.SelectMany( (notifications, i) => notifications.Select( f => new FileTranscodingResultNotification.SuccessTranscodingResultNotification(f)) ).ToArray(); actual.Values().ShouldAllBeEquivalentTo(expected, o => o.RespectingRuntimeTypes()); }
public void ObserveFileNotifications_Start_WhenFileNotificationIsYield_ShouldCallSynchronize( [Frozen]TestScheduler scheduler, [Frozen(As = typeof(IObservable<MusicMirrorConfiguration>))]TestObservableWrapper<MusicMirrorConfiguration> configurationObservable, [Frozen]Mock<IFileObserverFactory> fileObserverFactory, SynchronizeFilesWhenFileChanged sut, MusicMirrorConfiguration configuration, IFileNotification[][] fileNotification) { //arrange configurationObservable.SetObservable(scheduler.CreateHotObservable(OnNext(Subscribed + 1, configuration))); var expectedNotifications = fileNotification.Select((f, i) => OnNext(Subscribed + i + 2, f)).ToArray(); var fileObserver = scheduler.CreateHotObservable(expectedNotifications); fileObserverFactory.Setup(f => f.GetFileObserver(configuration.SourcePath)).Returns(fileObserver); scheduler.Schedule(200.Ticks(), () => sut.Start()); //act var actual = scheduler.Start(() => sut.ObserveNotifications()); //assert var expected = expectedNotifications.Select(n => n.Value.Value); actual.Values().ShouldAllBeEquivalentTo(expected); }