Пример #1
0
        public async Task UploadModelAsync_ShouldSucceed()
        {
            //Arrange
            var runId = Guid.NewGuid();

            //Act
            await sut.UploadModelAsync(runId, @"Data/model.txt");

            //Assert
            using var memoryStream = new MemoryStream();
            await sut.DownloadModelAsync(runId, memoryStream);

            memoryStream.Should().NotBeNull();
            memoryStream.Length.Should().BeGreaterThan(0);
        }
        public async Task UploadModelAsync_ShouldSaveFileInS3Bucket()
        {
            // Arrange
            mockAmzonClient.Setup(a => a.ListBucketsAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(new ListBucketsResponse
            {
                Buckets = new List <S3Bucket>()
                {
                    new S3Bucket
                    {
                        BucketName = "model-repository"
                    }
                }
            });

            // Act
            await sut.UploadModelAsync(new Guid(), "model.zip");

            // Assert
            mockAmzonClient.Verify(a => a.PutObjectAsync(It.Is <PutObjectRequest>(o => o.BucketName == "model-repository"), It.IsAny <CancellationToken>()), Times.Once);
        }
        public async Task UploadModelAsync_ShouldCreateS3BucketIfNotExists()
        {
            // Arrange
            var mockAmzonClient = new Mock <IAmazonS3>();

            mockAmzonClient.Setup(a => a.ListBucketsAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(new ListBucketsResponse
            {
                Buckets = new List <S3Bucket>()
            });

            var sut = new S3BucketModelRepository(mockAmzonClient.Object, "model-repository");

            // Act
            await sut.UploadModelAsync(new Guid(), "model.zip");

            // Assert
            mockAmzonClient.Verify(a => a.PutBucketAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()), Times.Once);
        }