コード例 #1
0
        public async Task GetAllPhotoDTOs()
        {
            var options = Utils.GetOptions(nameof(GetAllPhotoDTOs));

            var userStore   = new Mock <IUserStore <User> >();
            var userManager = new Mock <UserManager <User> >(userStore.Object, null, null, null,
                                                             null, null, null, null, null);
            var contextAccessor      = new Mock <IHttpContextAccessor>();
            var userPrincipalFactory = new Mock <IUserClaimsPrincipalFactory <User> >().Object;
            var signManager          = new Mock <SignInManager <User> >(userManager.Object, contextAccessor.Object, userPrincipalFactory, null, null, null, null).Object;
            var context = new Mock <HttpContext>();

            contextAccessor.Setup(x => x.HttpContext).Returns(context.Object);
            var contestService = new Mock <IContestService>();
            var userService    = new Mock <IUserService>();

            var userContestService = new Mock <IUserContestService>();

            using (var arrContext = new PhotoContestContext(options))
            {
                await arrContext.Ranks.AddRangeAsync(Utils.SeedRanks());

                await arrContext.Contests.AddRangeAsync(Utils.SeedContests());

                await arrContext.Categories.AddRangeAsync(Utils.SeedCategories());

                await arrContext.Photos.AddRangeAsync(Utils.SeedPhotos());

                await arrContext.Statuses.AddRangeAsync(Utils.SeedStatuses());

                await arrContext.Users.AddRangeAsync(Utils.SeedUsers());

                await arrContext.SaveChangesAsync();
            };
            using (var actContext = new PhotoContestContext(options))
            {
                var sut    = new PhotoService(actContext, contextAccessor.Object, contestService.Object, userService.Object, userManager.Object, signManager, userContestService.Object);
                var result = await sut.GetAllAsync();

                var photoDTOs = await actContext.Photos.Where(p => p.IsDeleted == false).Select(p => new PhotoDTO(p)).ToListAsync();

                Assert.AreEqual(photoDTOs.Count(), result.Count());
                Assert.IsInstanceOfType(result, typeof(IEnumerable <PhotoDTO>));
            }
        }