示例#1
0
        public async Task StorePhotoStoresNewPhotoTest()
        {
            var photo    = Model.Ignoring <Photo>(x => x.Data).Create <Photo>().Set(x => x.ContentType = ".jpg");
            var expected = Model.Create <byte[]>();

            var sut = new PhotoStore(Config.Storage);

            using (var inputStream = new MemoryStream(expected))
            {
                photo.Data = inputStream;

                var photoDetails = await sut.StorePhoto(photo, CancellationToken.None).ConfigureAwait(false);

                photoDetails.Should().BeEquivalentTo(photo, opt => opt.ExcludingMissingMembers().Excluding(x => x.Hash));
                photoDetails.Hash.Should().NotBeNullOrWhiteSpace();
                var retrievedPhoto = await sut.GetPhoto(photo.ProfileId, photo.Id, CancellationToken.None)
                                     .ConfigureAwait(false);

                retrievedPhoto.Should().BeEquivalentTo(photoDetails, opt => opt.ExcludingMissingMembers());

                using (var outputStream = retrievedPhoto.Data)
                {
                    outputStream.Position.Should().Be(0);
                    outputStream.Length.Should().Be(expected.Length);

                    var actual = new byte[expected.Length];

                    var length = outputStream.Read(actual, 0, expected.Length);

                    length.Should().Be(expected.Length);
                    expected.SequenceEqual(actual).Should().BeTrue();
                }
            }
        }
示例#2
0
        public void GetPhotoThrowsExceptionWithEmptyProfileIdTest()
        {
            var sut = new PhotoStore(Config.Storage);

            Func <Task> action = async() =>
                                 await sut.GetPhoto(Guid.Empty, Guid.NewGuid(), CancellationToken.None).ConfigureAwait(false);

            action.Should().Throw <ArgumentException>();
        }
示例#3
0
        private void Load()
        {
            List <string> choseLocationNames = new List <string>();

            var hitemVM = _mainViewModel.CurrentHighliteItemViewModel;

            LoadFromHighliteTarget(hitemVM.Target, hitemVM.TargetId);

            SelectedSection = Sections.First();

            var photo = _photoStore.GetPhoto(SelectedSection.Items.First().PhotoId);

            DebugInfo.Load(photo);

            OnPropertyChanged(nameof(DisplayName));
            OnPropertyChanged(nameof(SelectedSection));
            OnPropertyChanged(nameof(DebugInfo));

            ShowInfo = false;
        }
示例#4
0
        public async Task StorePhotoCreatesContainerWhenNotFoundTest()
        {
            // Retrieve storage account from connection-string
            var storageAccount = CloudStorageAccount.Parse(Config.Storage.ConnectionString);

            // Create the client
            var client = storageAccount.CreateCloudBlobClient();

            var container = client.GetContainerReference("photos");

            await container.DeleteIfExistsAsync().ConfigureAwait(false);

            var photo    = Model.Ignoring <Photo>(x => x.Data).Create <Photo>().Set(x => x.ContentType = ".jpg");
            var expected = Model.Create <byte[]>();

            var sut = new PhotoStore(Config.Storage);

            using (var inputStream = new MemoryStream(expected))
            {
                photo.Data = inputStream;

                var photoDetails = await sut.StorePhoto(photo, CancellationToken.None).ConfigureAwait(false);

                photoDetails.Should().BeEquivalentTo(photo, opt => opt.ExcludingMissingMembers().Excluding(x => x.Hash));
                photoDetails.Hash.Should().NotBeNullOrWhiteSpace();

                var retrievedPhoto = await sut.GetPhoto(photo.ProfileId, photo.Id, CancellationToken.None)
                                     .ConfigureAwait(false);

                retrievedPhoto.Should().BeEquivalentTo(photoDetails, opt => opt.ExcludingMissingMembers());

                using (var outputStream = retrievedPhoto.Data)
                {
                    outputStream.Position.Should().Be(0);
                    outputStream.Length.Should().Be(expected.Length);

                    var actual = new byte[expected.Length];

                    var length = outputStream.Read(actual, 0, expected.Length);

                    length.Should().Be(expected.Length);
                    expected.SequenceEqual(actual).Should().BeTrue();
                }
            }
        }
示例#5
0
        public async Task GetPhotoReturnsNullWhenContainerNotFoundTest()
        {
            // Retrieve storage account from connection-string
            var storageAccount = CloudStorageAccount.Parse(Config.Storage.ConnectionString);

            // Create the client
            var client = storageAccount.CreateCloudBlobClient();

            var container = client.GetContainerReference("photos");

            await container.DeleteIfExistsAsync().ConfigureAwait(false);

            var sut = new PhotoStore(Config.Storage);

            var actual = await sut.GetPhoto(Guid.NewGuid(), Guid.NewGuid(), CancellationToken.None)
                         .ConfigureAwait(false);

            actual.Should().BeNull();
        }
示例#6
0
        public async Task DeletePhotoRemovesPhotoBlobTest()
        {
            var photo    = Model.Ignoring <Photo>(x => x.Data).Create <Photo>().Set(x => x.ContentType = ".jpg");
            var expected = Model.Create <byte[]>();

            var sut = new PhotoStore(Config.Storage);

            using (var inputStream = new MemoryStream(expected))
            {
                photo.Data = inputStream;

                await sut.StorePhoto(photo, CancellationToken.None).ConfigureAwait(false);
            }

            await sut.DeletePhoto(photo.ProfileId, photo.Id, CancellationToken.None).ConfigureAwait(false);

            var actual = await sut.GetPhoto(photo.ProfileId, photo.Id, CancellationToken.None)
                         .ConfigureAwait(false);

            actual.Should().BeNull();
        }