Ejemplo n.º 1
0
        public async Task DeletePhotosRemovesPhotosFromStoreTest()
        {
            var profileId       = Guid.NewGuid();
            var photoReferences = Model.Create <List <Guid> >();

            var store   = Substitute.For <IPhotoStore>();
            var resizer = Substitute.For <IPhotoResizer>();
            var config  = Substitute.For <IPhotoConfig>();

            using (var tokenSource = new CancellationTokenSource())
            {
                store.GetPhotos(profileId, tokenSource.Token).Returns(photoReferences);

                var sut = new PhotoCommand(store, resizer, config);

                await sut.DeletePhotos(profileId, tokenSource.Token).ConfigureAwait(false);

                await store.Received(photoReferences.Count).DeletePhoto(profileId, Arg.Any <Guid>(), tokenSource.Token).ConfigureAwait(false);

                foreach (var photoReference in photoReferences)
                {
                    await store.Received().DeletePhoto(profileId, photoReference, tokenSource.Token).ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 2
0
        public async Task CreatePhotoStoresResizedPhotoTest()
        {
            var expected = Model.Ignoring <Photo>(x => x.Data).Create <Photo>();
            var details  = Model.Create <PhotoDetails>();

            var store        = Substitute.For <IPhotoStore>();
            var resizer      = Substitute.For <IPhotoResizer>();
            var config       = Substitute.For <IPhotoConfig>();
            var resizedPhoto = Substitute.For <Photo>();

            config.MaxHeight.Returns(Environment.TickCount);
            config.MaxWidth = config.MaxHeight + 1;

            var sut = new PhotoCommand(store, resizer, config);

            using (resizedPhoto)
            {
                resizer.Resize(expected, config.MaxHeight, config.MaxWidth).Returns(resizedPhoto);

                using (var tokenSource = new CancellationTokenSource())
                {
                    store.StorePhoto(resizedPhoto, tokenSource.Token).Returns(details);

                    var actual = await sut.CreatePhoto(expected, tokenSource.Token).ConfigureAwait(false);

                    actual.Should().BeEquivalentTo(details);

                    resizedPhoto.Received().Dispose();
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// コンストラクタで処理を購読
 /// </summary>
 public MainWindowViewModel()
 {
     StartCommand.Subscribe(async() => await StartPreview());
     StopCommand.Subscribe(_ => StopPreview());
     PhotoCommand = IsStop.ObserveHasErrors.CombineLatest(
         InputText.ObserveHasErrors, (x, y) => !x && !y).ToReactiveCommand();
     OptionCommand.Subscribe(_ => IsOption.Value = !IsOption.Value);
     PhotoCommand.Subscribe(_ => Photo());
     IsPhoto = InputText.Select(x => x.Length != 0).ToReactiveProperty();
 }
Ejemplo n.º 4
0
        public void DeletePhotosThrowsExceptionWithEmptyProfileIdTest()
        {
            var store   = Substitute.For <IPhotoStore>();
            var resizer = Substitute.For <IPhotoResizer>();
            var config  = Substitute.For <IPhotoConfig>();

            var sut = new PhotoCommand(store, resizer, config);

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

            action.Should().Throw <ArgumentException>();
        }
Ejemplo n.º 5
0
        public void CreatePhotoThrowsExceptionWithNullPhotoTest()
        {
            var store   = Substitute.For <IPhotoStore>();
            var resizer = Substitute.For <IPhotoResizer>();
            var config  = Substitute.For <IPhotoConfig>();

            var sut = new PhotoCommand(store, resizer, config);

            Func <Task> action = async() => await sut.CreatePhoto(null, CancellationToken.None).ConfigureAwait(false);

            action.Should().Throw <ArgumentNullException>();
        }