コード例 #1
0
        public void Delete_FileDeleteIsCalledIfFileExists_True()
        {
            var fileWrapperMock = Substitute.For <IFileWrapper>();

            fileWrapperMock.Exists(Arg.Any <string>()).Returns(true);
            var sut = new AudioLocalRepositoryBuilder()
                      .WithFileWrapper(fileWrapperMock)
                      .Build();

            sut.Delete("testFolder");
            fileWrapperMock.Received().Delete("testFolder");
        }
コード例 #2
0
        public async Task AddAsync_StreamCreateCalledWithCorrectParameters_True()
        {
            var stream = Substitute.For <IFileStreamFactory>();

            stream.Create(Arg.Any <string>(), Arg.Any <FileMode>(), Arg.Any <FileAccess>()).Returns(new MemoryStream());
            var sut = new AudioLocalRepositoryBuilder()
                      .WithFileStreamFactory(stream)
                      .Build();

            var audio = new AudioUploadDtoBuilder()
                        .WithPath("test")
                        .Build();

            await sut.AddAsync(audio, CancellationToken.None);

            stream.Received().Create("test", FileMode.Create, FileAccess.Write);
        }
コード例 #3
0
        public async Task AddAsync_FileCopyToAsyncShouldBeCalled_True()
        {
            var stream = Substitute.For <IFileStreamFactory>();

            stream.Create(Arg.Any <string>(), Arg.Any <FileMode>(), Arg.Any <FileAccess>()).Returns(new MemoryStream());
            var sut = new AudioLocalRepositoryBuilder()
                      .WithFileStreamFactory(stream)
                      .Build();

            var fileMock = Substitute.For <IFormFile>();

            var audio = new AudioUploadDtoBuilder()
                        .WithFile(fileMock)
                        .WithPath("test")
                        .Build();

            await sut.AddAsync(audio, CancellationToken.None);

            await fileMock.Received().CopyToAsync(Arg.Any <MemoryStream>(), CancellationToken.None);
        }
コード例 #4
0
        public async Task AddAsync_GetDirectoryShouldBeCalled_True()
        {
            var pathMock = Substitute.For <IPathWrapper>();

            pathMock.GetDirectoryName("test").Returns("test");
            var stream = Substitute.For <IFileStreamFactory>();

            stream.Create(Arg.Any <string>(), Arg.Any <FileMode>(), Arg.Any <FileAccess>()).Returns(new MemoryStream());
            var sut = new AudioLocalRepositoryBuilder()
                      .WithPathWrapper(pathMock)
                      .WithFileStreamFactory(stream)
                      .Build();

            var audio = new AudioUploadDtoBuilder()
                        .WithPath("test")
                        .Build();

            await sut.AddAsync(audio, CancellationToken.None);

            pathMock.Received().GetDirectoryName("test");
        }