Beispiel #1
0
        public static void SelfInitializingWithFileRecorder(
            string fileRecorderPath,
            ILibraryService realServiceWhileRecording,
            ILibraryService realServiceDuringPlayback,
            int countWhileRecording,
            int countDuringPlayback)
        {
            "Given a path that does not exist"
            .x(() => fileRecorderPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));

            "And a real service to wrap while recording"
            .x(() =>
            {
                realServiceWhileRecording = A.Fake <ILibraryService>();

                A.CallTo(() => realServiceWhileRecording.GetCount("8"))
                .Returns(0x8);
            });

            "And a real service to wrap while playing back"
            .x(() => realServiceDuringPlayback = A.Fake <ILibraryService>());

            "When I use a self-initialized fake recording to the path to get the count for book 8"
            .x(() =>
            {
                using (var recorder = Recorders.FileRecorder(fileRecorderPath))
                {
                    var fakeService = A.Fake <ILibraryService>(options => options
                                                               .Wrapping(realServiceWhileRecording).RecordedBy(recorder));
                    countWhileRecording = fakeService.GetCount("8");
                }
            })
            .Teardown(() => File.Delete(fileRecorderPath));

            "And I use a self-initialized fake playing back from the path to get the count for book 8"
            .x(() =>
            {
                using (var recorder = Recorders.FileRecorder(fileRecorderPath))
                {
                    var playbackFakeService = A.Fake <ILibraryService>(options => options
                                                                       .Wrapping(realServiceDuringPlayback).RecordedBy(recorder));

                    countDuringPlayback = playbackFakeService.GetCount("8");
                }
            });

            "Then the recording fake returns the wrapped service's result"
            .x(() => countWhileRecording.Should().Be(8));

            "And the playback fake returns the recorded result"
            .x(() => countDuringPlayback.Should().Be(8));
        }
Beispiel #2
0
        public static void SelfInitializingWithFileRecorder(
            string fileRecorderPath,
            ILibraryService realServiceWhileRecording,
            ILibraryService realServiceDuringPlayback,
            int countWhileRecording,
            int countDuringPlayback)
        {
            "establish"
            .x(() =>
            {
                fileRecorderPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

                realServiceWhileRecording = A.Fake <ILibraryService>();
                realServiceDuringPlayback = A.Fake <ILibraryService>();

                A.CallTo(() => realServiceWhileRecording.GetCount("9780345813923")).Returns(8);
            });

            "when self initializing a fake with a file recorder"
            .x(() =>
            {
                try
                {
                    using (var recorder = Recorders.FileRecorder(fileRecorderPath))
                    {
                        var fakeService = A.Fake <ILibraryService>(options => options
                                                                   .Wrapping(realServiceWhileRecording).RecordedBy(recorder));
                        countWhileRecording = fakeService.GetCount("9780345813923");
                    }

                    using (var recorder = Recorders.FileRecorder(fileRecorderPath))
                    {
                        var playbackFakeService = A.Fake <ILibraryService>(options => options
                                                                           .Wrapping(realServiceDuringPlayback).RecordedBy(recorder));

                        countDuringPlayback = playbackFakeService.GetCount("9780345813923");
                    }
                }
                finally
                {
                    File.Delete(fileRecorderPath);
                }
            })
            .Teardown(() => File.Delete(fileRecorderPath));

            "it should return the expected result while recording"
            .x(() => countWhileRecording.Should().Be(8));

            "it should return the recorded result during playback"
            .x(() => countDuringPlayback.Should().Be(8));
        }
        public void FileRecorder_tests()
        {
            using (var recorder = Recorders.FileRecorder(@"C:\Users\Patrik\Documents\recorded_calls.dat"))
            {
                var realReader = new WebReader();
                var fakeReader = A.Fake <WebReader>(x => x.Wrapping(realReader).RecordedBy(recorder));

                for (int i = 0; i < 30; i++)
                {
                    fakeReader.Download(new Uri("http://www.sembo.se/"));
                }

                Console.WriteLine(fakeReader.Download(new Uri("http://www.sembo.se/")));
            }
        }
Beispiel #4
0
        public void FileRecorder_should_return_recording_manager_with_file_storage()
        {
            // Arrange
            var storage = new FileStorage(string.Empty, A.Fake <IFileSystem>());

            this.StubResolve <FileStorage.Factory>(x => x == "c:\\file.dat" ? storage : null);

            var recordingManager = A.Fake <RecordingManager>();

            this.StubResolve <RecordingManager.Factory>(x => x.Equals(storage) ? recordingManager : null);

            // Act
            var recorder = Recorders.FileRecorder("c:\\file.dat");

            // Assert
            recorder.Should().BeSameAs(recordingManager);
        }