コード例 #1
0
        public void execute_passes_the_audio_name_onto_the_audio_service(string audioName)
        {
            var audioService = new AudioServiceMock(MockBehavior.Loose);
            var sut = new AudioActionBuilder()
                .WithAudioService(audioService)
                .WithAudioName(audioName)
                .Build();

            sut.Execute(new ExecutionContext()).Subscribe();

            audioService
                .Verify(x => x.Play(audioName))
                .WasCalledExactlyOnce();
        }
コード例 #2
0
        public void execute_pauses_if_context_is_paused()
        {
            var audioService = new AudioServiceMock(MockBehavior.Loose);
            var sut = new AudioActionBuilder()
                .WithAudioService(audioService)
                .Build();

            using (var context = new ExecutionContext())
            {
                context.IsPaused = true;

                sut.Execute(context).Subscribe();

                audioService
                    .Verify(x => x.Play(It.IsAny<string>()))
                    .WasNotCalled();
            }
        }
コード例 #3
0
        public void execute_composes_the_appropriate_actions()
        {
            var audioService = new AudioServiceMock();
            var delayService = new DelayServiceMock();
            var actionsPerformed = new List<string>();

            audioService
                .When(x => x.Play(It.IsAny<string>()))
                .Do<string>((resource) => actionsPerformed.Add("Played audio resource " + resource))
                .Return(Observable.Return(Unit.Default));

            delayService
                .When(x => x.Delay(It.IsAny<TimeSpan>()))
                .Do<TimeSpan>(period => actionsPerformed.Add("Delayed for " + period))
                .Return(Observable.Return(Unit.Default));

            var sut = new MetronomeActionBuilder()
                .WithAudioService(audioService)
                .WithDelayService(delayService)
                .WithMetronomeTick(new MetronomeTick(TimeSpan.Zero, MetronomeTickType.Bell))
                .WithMetronomeTick(new MetronomeTick(TimeSpan.FromMilliseconds(10)))
                .WithMetronomeTick(new MetronomeTick(TimeSpan.FromMilliseconds(20)))
                .WithMetronomeTick(new MetronomeTick(TimeSpan.FromMilliseconds(50), MetronomeTickType.Bell))
                .WithMetronomeTick(new MetronomeTick(TimeSpan.FromMilliseconds(30), MetronomeTickType.None))
                .Build();

            sut
                .Execute(new ExecutionContext())
                .Subscribe();

            Assert.Equal(8, actionsPerformed.Count);
            Assert.Equal("Played audio resource MetronomeBell", actionsPerformed[0]);
            Assert.Equal("Delayed for 00:00:00.0100000", actionsPerformed[1]);
            Assert.Equal("Played audio resource MetronomeClick", actionsPerformed[2]);
            Assert.Equal("Delayed for 00:00:00.0200000", actionsPerformed[3]);
            Assert.Equal("Played audio resource MetronomeClick", actionsPerformed[4]);
            Assert.Equal("Delayed for 00:00:00.0500000", actionsPerformed[5]);
            Assert.Equal("Played audio resource MetronomeBell", actionsPerformed[6]);
            Assert.Equal("Delayed for 00:00:00.0300000", actionsPerformed[7]);
        }