예제 #1
0
        public async Task ReturnTrue_IfUser_ChosenSuccessfully()
        {
            var options = Utils.GetOptions(nameof(ReturnTrue_IfUser_ChosenSuccessfully));

            var categoryService = new Mock <ICategoryService>().Object;
            var userService     = new Mock <IUserService>();

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

            using (var arrContext = new PhotoContestContext(options))
            {
                await arrContext.Users.AddRangeAsync(Utils.SeedUsers());

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

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

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

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

                await arrContext.UserContests.AddRangeAsync(Utils.SeedUserContests());

                await arrContext.Ranks.AddRangeAsync(Utils.SeedRanks());

                await arrContext.SaveChangesAsync();

                var userToChoose = arrContext.Users.Skip(8).First();
                userService.Setup(u => u.GetUserByUsernameAsync(It.IsAny <string>())).Returns(Task.FromResult(userToChoose));
            }
            using (var actContext = new PhotoContestContext(options))
            {
                var userToChoose = actContext.Users.Skip(8).First().UserName;
                var sut          = new ContestService(actContext, contextAccessor, userService.Object, categoryService, userManager, signManager);
                var result       = await sut.ChooseJuryAsync(actContext.Contests.First().Name, userToChoose);

                Assert.IsTrue(result);
            }
        }