Example #1
0
        public async Task <List <string> > UploadImageAsync(int id, FileModel fileModel)
        {
            List <string> urls     = null;
            var           lodgment = await repository.GetLodgmentByIdAsync(id);

            if (lodgment == null)
            {
                throw new KeyNotFoundException();
            }

            urls = await storageService.AddLodgmentImageAsync(id, fileModel);

            await repository.AddLodgmentImageAsync(id, urls);

            return(urls);
        }
        public async Task AddLodgmentImageAsync_LodgmentFolderExists_ReturnsUrl()
        {
            // Arrange
            foreach (var file in fileModel.Files)
            {
                var fileName = fileModel.Name + (expectedUrls.Count + 1);
                expectedUrl = string.Format("{0}/{1}/{2}/{3}/{4}", expectedBaseUrlFolder, expectedLodgmentsFolder, lodgmentId, "images", fileName);
                expectedUrls.Add(expectedUrl);
            }

            moqConfigManager.Setup(x => x.LodgmentsFolder).Returns(expectedLodgmentsFolder);
            moqConfigManager.Setup(x => x.ResourcesFolder).Returns(expectedResourcesFolder);
            moqConfigManager.Setup(x => x.BaseUrl).Returns(expectedBaseUrlFolder);

            // Act
            var actualUrls = await storageService.AddLodgmentImageAsync(lodgmentId, fileModel);

            // Assert
            moqConfigManager.VerifyAll();
            CollectionAssert.AreEqual(expectedUrls, actualUrls);
        }