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 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 Sut_ShouldBeITranscodingNotifications(SynchronizeFilesWhenFileChanged sut) { sut.Should().BeAssignableTo<ITranscodingNotifications>(); }
public void Start_ShouldReturnDisposable(SynchronizeFilesWhenFileChanged sut) { sut.Start().Should().NotBeNull(); }
public void ObserveIsTranscodingRunning_WhenFilesAreTranscodingAndSubscribeOccursLaterOn_ShouldReturnCorrectValue( [Frozen]TestScheduler scheduler, [Frozen(As = typeof(IObservable<MusicMirrorConfiguration>))]TestObservableWrapper<MusicMirrorConfiguration> configurationObservable, [Frozen]Mock<IFileObserverFactory> fileObserverFactory, SynchronizeFilesWhenFileChanged sut, MusicMirrorConfiguration configuration, IFileNotification[] fileNotification ) { sut.SynchronizationScheduler = ImmediateScheduler.Instance; const long NotificationsStart = Subscribed + 1; const long Subscription = Subscribed + 3; configurationObservable.SetObservable(scheduler.CreateHotObservable(OnNext(NotificationsStart, configuration))); var fileObserver = scheduler.CreateHotObservable(OnNext(NotificationsStart, fileNotification)); fileObserverFactory.Setup(f => f.GetFileObserver(configuration.SourcePath)).Returns(fileObserver); SetupTranscodingWorkWithIncrementalDuration(scheduler, fileNotification); scheduler.Schedule(200.Ticks(), () => sut.Start()); //act var actual = scheduler.Start(() => sut.ObserveIsTranscodingRunning(), Created, Subscription, Disposed); //assert var expected = new[] { true, false }; //+1 because we expect that the tasks results of file.Accept will be scheduled on the TestScheduler actual.Values().ShouldAllBeEquivalentTo(expected); }
public void Sut_ShouldBeIStartSynchronizing(SynchronizeFilesWhenFileChanged sut) { sut.Should().BeAssignableTo<IStartSynchronizing>(); }
public void ObserveIsTranscodingRunning_WhenFilesAreTranscoding_ShouldReturnCorrectValue( [Frozen]TestScheduler scheduler, [Frozen(As = typeof(IObservable<MusicMirrorConfiguration>))]TestObservableWrapper<MusicMirrorConfiguration> configurationObservable, [Frozen]Mock<IFileObserverFactory> fileObserverFactory, SynchronizeFilesWhenFileChanged sut, MusicMirrorConfiguration configuration, IFileNotification[] fileNotification ) { //arrange sut.SynchronizationScheduler = ImmediateScheduler.Instance; configurationObservable.SetObservable(scheduler.CreateHotObservable(OnNext(Subscribed + 1, configuration))); const long NotificationsStart = Subscribed + 2; var fileObserver = scheduler.CreateHotObservable(OnNext(NotificationsStart, fileNotification)); fileObserverFactory.Setup(f => f.GetFileObserver(configuration.SourcePath)).Returns(fileObserver); SetupTranscodingWorkWithIncrementalDuration(scheduler, fileNotification); scheduler.Schedule(200.Ticks(), () => sut.Start()); //act var actual = scheduler.Start(() => sut.ObserveIsTranscodingRunning()); //assert var expected = new[] { false, true, false }; actual.Values().ShouldAllBeEquivalentTo(expected); }
public void ObserveIsTranscodingRunning_WhenNoFileIsTranscoding_ShouldReturnCorrectValue( [Frozen]TestScheduler scheduler, SynchronizeFilesWhenFileChanged sut ) { //act var actual = scheduler.Start(() => sut.ObserveIsTranscodingRunning()); //assert actual.Messages.ShouldAllBeEquivalentTo(OnNext(Subscribed, false).Yield()); }
public void ObserveNotifications_ShouldNoBeSubject(SynchronizeFilesWhenFileChanged sut) { (sut.ObserveNotifications() as ISubject<IFileNotification[]>).Should().BeNull("IObservable<T> is also a ISubject<T>, but it should not"); }
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); }
public void ObserveTranscodingResult_ShouldNoBeSubject(SynchronizeFilesWhenFileChanged sut) { (sut.ObserveTranscodingResult() as ISubject<IFileTranscodingResultNotification>).Should().BeNull("IObservable<T> is also a ISubject<T>, but it should not"); }