コード例 #1
0
 public async Task<Season> CreateSeason()
 {
     if (IsAdministrator)
     {
         var newSeason = new Season();
         Context.Add(newSeason);
         await Context.SaveChangesAsync();
         return newSeason;
     }
     else
     {
         throw new UnauthorizedAccessException();
     }
 }
コード例 #2
0
        public async Task AddAchievementToSeason_ValidAchievement_AddsAndSaves()
        {
            Mock<IDbContext> fakeContext = new Mock<IDbContext>();
            fakeContext.SetAdmin(0);
            var season = new Season()
            {
                Id = 1,
                AchievementSeason = new List<SeasonalAchievement>(),
            };
            fakeContext.Setup(x => x.Get<Season>()).Returns(new Season[] { season }.AsQueryable());
            var seasonManager = new SeasonManager(fakeContext.Object, 0);

            await seasonManager.AddAchievementToSeason(1, 5, 0);

            fakeContext.Verify(x => x.SaveChangesAsync());
        }
コード例 #3
0
        public async Task AddAchievementToSeason_Repeat_ThrowsExceptions()
        {
            Mock<IDbContext> fakeContext = new Mock<IDbContext>();
            fakeContext.SetAdmin(0);
            var season = new Season()
            {
                Id = 1,
                AchievementSeason = new [] { new SeasonalAchievement
                {
                    SeasonId = 1,
                    AchievementId = 10,
                } },
            };
            fakeContext.Setup(x => x.Get<Season>()).Returns(new Season[] { season }.AsQueryable());
            var seasonManager = new SeasonManager(fakeContext.Object, 0);

            await seasonManager.AddAchievementToSeason(1, 10, 0);

            fakeContext.Verify(x => x.SaveChangesAsync(), Times.Never());
        }