Exemplo n.º 1
0
        public async Task GetExportProfileReturnsProfileAndPhotoDataTest()
        {
            var profileId = Guid.NewGuid();
            var profile   = ModelBuilder.Model.Create <Profile>();
            var photos    = ModelBuilder.Model.Ignoring <Photo>(x => x.Data).Create <List <Photo> >();
            var photoData = ModelBuilder.Model.Create <byte[]>();

            var profileQuery = Substitute.For <IProfileQuery>();
            var photoQuery   = Substitute.For <IPhotoQuery>();

            using (var inputStream = new MemoryStream(photoData))
            {
                photos.SetEach(x => x.Data = inputStream);

                using (var tokenSource = new CancellationTokenSource())
                {
                    profileQuery.GetProfile(profileId, tokenSource.Token).Returns(profile);
                    photoQuery.GetPhotos(profileId, tokenSource.Token).Returns(photos);

                    var sut = new ExportQuery(profileQuery, photoQuery);

                    var actual = await sut.GetExportProfile(profileId, tokenSource.Token).ConfigureAwait(false);

                    actual.Should().BeEquivalentTo(profile, opt => opt.ExcludingMissingMembers());
                    actual.Photos.Should().BeEquivalentTo(photos, opt => opt.Excluding(x => x.Data));
                    actual.Photos.All(x => x.Data.SequenceEqual(photoData)).Should().BeTrue();
                }
            }
        }
Exemplo n.º 2
0
        public void GetExportProfileThrowsExceptionWithEmptyProfileIdTest()
        {
            var profileQuery = Substitute.For <IProfileQuery>();
            var photoQuery   = Substitute.For <IPhotoQuery>();

            var sut = new ExportQuery(profileQuery, photoQuery);

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

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