Пример #1
0
        public void GetByIds_ArrayOfIdis_ReturnsArrayOfThumbnailOption()
        {
            var optionEntites = ThumbnailOptionEntitesDataSource.ToArray();

            var ids   = optionEntites.Select(t => t.Id).ToArray();
            var tasks = optionEntites.Select(t => t.ToModel(new ThumbnailOption())).ToArray();

            var mock = new Mock <IThumbnailRepository>();

            mock.Setup(r => r.GetThumbnailOptionsByIdsAsync(It.IsIn <string[]>(ids)))
            .ReturnsAsync(optionEntites.Where(o => ids.Contains(o.Id)).ToArray());

            var sut    = new ThumbnailOptionService(() => mock.Object);
            var result = sut.GetByIdsAsync(ids);

            Assert.Equal(result.Result.Length, tasks.Length);
        }
        public async Task SaveChanges_ArrayOfThumbnailOptions_ThumbnailOptionsUpdatedAsync()
        {
            var optionEntities = ThumbnailOptionEntitesDataSource.ToArray();
            var options        = ThumbnailOptionDataSource.ToArray();

            var mock = new Mock <IThumbnailRepository>();

            mock.SetupGet(x => x.UnitOfWork).Returns(new Mock <IUnitOfWork>().Object);
            mock.Setup(r => r.GetThumbnailOptionsByIdsAsync(It.IsAny <string[]>()).Result)
            .Returns((string[] ids) =>
            {
                var result = optionEntities.Where(t => ids.Contains(t.Id)).ToArray();
                return(result);
            });

            var sut = new ThumbnailOptionService(() => mock.Object);
            await sut.SaveOrUpdateAsync(options);

            Assert.Contains(optionEntities, o => o.Name == "New Name");
        }