Ejemplo n.º 1
0
        public async Task ShouldCompleteSessionIfAllBlocksAreUploaded()
        {
            // Arrange
            var fixture = new TestFixture <CompleteUploadSessionCommandHandler>();
            var command = new CompleteUploadSessionCommand("123");

            var session = fixture.Build <UploadSession>()
                          .With(x => x.Parts, new[]
            {
                fixture.Build <UploadPart>().With(x => x.Id, "1").With(x => x.SizeInBytes, 10).Create(),
                fixture.Build <UploadPart>().With(x => x.Id, "2").With(x => x.SizeInBytes, 20).Create()
            })
                          .With(x => x.Id, "123")
                          .With(x => x.Extension, FileExtension.Txt.ToString())
                          .Create();

            fixture.Freeze <ISessionsRepository>().FindNotCompletedSessionAsync(command.UploadId, CancellationToken.None)
            .Returns(session);

            var blockList = new[]
            {
                new BlockInfo("1", 10),
                new BlockInfo("2", 20)
            };

            fixture.Freeze <IBlobStorage>().GetBlockListAsync("123", CancellationToken.None)
            .Returns(blockList);

            // Act
            var result = await fixture.Sut.Handle(command, CancellationToken.None);

            // Assert
            result.Should().NotBeNull();
            result.CorruptedParts.Should().BeEmpty();
        }
Ejemplo n.º 2
0
        public async Task ShouldGetCorruptedBlocksIfNoneOfThemWereNotUploaded()
        {
            // Arrange
            var fixture = new TestFixture <CompleteUploadSessionCommandHandler>();
            var command = new CompleteUploadSessionCommand("123");

            var session = fixture.Build <UploadSession>()
                          .With(x => x.Parts, new[]
            {
                fixture.Build <UploadPart>().With(x => x.Id, "1").With(x => x.SizeInBytes, 10).With(x => x.Offset, 0).Create()
            })
                          .With(x => x.Id, "123")
                          .With(x => x.Extension, FileExtension.Txt.ToString())
                          .Create();

            var expectedPart = new CorruptedPart
            {
                ActualSizeInBytes = 0, ExpectedSizeInBytes = 10, Offset = 0, Id = "1"
            };

            fixture.Freeze <ISessionsRepository>().FindNotCompletedSessionAsync(command.UploadId, CancellationToken.None)
            .Returns(session);

            // Act
            var result = await fixture.Sut.Handle(command, CancellationToken.None);

            // Assert
            result.Should().NotBeNull();
            result.CorruptedParts.Should().BeEquivalentTo(expectedPart);
        }
Ejemplo n.º 3
0
        public async Task ShouldReturnNullIfSessionIsNotFound()
        {
            // Arrange
            var fixture = new TestFixture <CompleteUploadSessionCommandHandler>();
            var command = new CompleteUploadSessionCommand("123");

            // Act
            var result = await fixture.Sut.Handle(command, CancellationToken.None);

            // Assert
            result.Should().BeNull();
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> CompleteUploadSession([FromRoute] string uploadId,
                                                                CancellationToken cancellationToken)
        {
            var command = new CompleteUploadSessionCommand(uploadId);
            var result  = await _mediator.Send(command, cancellationToken);

            if (result == null)
            {
                return(NotFound());
            }

            if (result.CorruptedParts.Any())
            {
                return(BadRequest(result));
            }

            return(Ok());
        }