예제 #1
0
        public async Task UploadAsync_AddAsyncToAudioLocalRepositoryIsCalled_True()
        {
            var audioLocalRepoMock = Substitute.For <IAudioLocalRepository>();
            var sut = new AudioServiceBuilder()
                      .WithLocalRepo(audioLocalRepoMock)
                      .Build();

            var audio = new AudioUploadDtoBuilder().Build();

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

            await audioLocalRepoMock.Received().AddAsync(Arg.Any <AudioUploadDto>(), CancellationToken.None);
        }
예제 #2
0
        public async Task UploadAsync_SaveAsyncToAudioEntriesRepositoryIsCalled_True()
        {
            var audioRepoMock = Substitute.For <IAudioEntriesRepository>();

            var sut = new AudioServiceBuilder()
                      .WithAudioEntriesRepo(audioRepoMock)
                      .Build();

            var audio = new AudioUploadDtoBuilder().Build();

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

            await audioRepoMock.Received().SaveAsync(CancellationToken.None);
        }
        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);
        }
        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);
        }
        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");
        }