Пример #1
0
        public async Task ChangeStatusTo_Finished()
        {
            var options = Utils.GetOptions(nameof(ChangeStatusTo_Finished));

            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.Contests.AddRangeAsync(Utils.SeedContests());

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

                await arrContext.SaveChangesAsync();
            }
            using (var actContext = new PhotoContestContext(options))
            {
                var sut     = new ContestService(actContext, contextAccessor, userService.Object, categoryService, userManager, signManager);
                var contest = actContext.Contests.Include(c => c.Status).First();
                contest.Phase1   = DateTime.UtcNow.AddDays(-5);
                contest.Phase2   = DateTime.UtcNow.AddHours(-5);
                contest.Finished = DateTime.UtcNow;
                await sut.ChangeStatus();

                Assert.AreEqual(contest.Status.Name, "Finished");
            }
        }