public void ActivateSeason_InvalidEndDate_ThrowsException() { var fakeContext = new Mock<IDatabaseContext>(); Person person = new Person { Id = 1, }; var accountGroupPeople = new List<AccountGroupPerson>() { new AccountGroupPerson { PermissionLevel = PermissionLevel.Admin, // this is imporant PersonId = 1, Person = person, } }; person.AccountGroupPeople = accountGroupPeople; Season season = new Season { Id = 1000, IsActive = false, //important EndDate = DateTime.Today.AddDays(1), AccountGroup = new AccountGroup() { AccountGroupPeople = accountGroupPeople }, }; fakeContext.Setup(x => x.List<Season>()).Returns(new[] { season }.AsQueryable()); fakeContext.Setup(x => x.List<Person>()).Returns(new[] { person }.AsQueryable()); var mng = new SeasonManagement(fakeContext.Object, 1); mng.ActivateSeason(season.Id); }
public void ActivateSeason_InvalidStartDate_ThrowsException() { var fakeContext = new Mock<IDatabaseContext>(); Person person = new Person() { Id = 100 }; AccountGroupPerson personJoin = new AccountGroupPerson() { Person = person, PersonId = person.Id, PermissionLevel = PermissionLevel.Admin }; AccountGroup accountGroup = new AccountGroup() { Id = 1000, AccountGroupPeople = new List<AccountGroupPerson>() { personJoin, } }; personJoin.AccountGroup = accountGroup; personJoin.AccountGroupId = accountGroup.Id; person.AccountGroupPeople = new[] { personJoin }; Season season = new Season { Id = 2, IsActive = false, AccountGroup = accountGroup, StartDate = null, EndDate = DateTime.Today, AccountGroupId = accountGroup.Id, }; fakeContext.Setup(x => x.List<Season>()).Returns(new[] { season }.AsQueryable()); fakeContext.Setup(x => x.List<Person>()).Returns(new[] { person }.AsQueryable()); SeasonManagement management = new SeasonManagement(fakeContext.Object, 100); management.ActivateSeason(2); }
public void GiveAchievement_BadAccountGroupDetails_Fails() { //give an achievement to the incorrect account group var fakeContext = new Mock<IDatabaseContext>(); var season = new Season { Id = 10000, }; Guid achievementKey = Guid.NewGuid(); var achievements = new[] { new Achievement { Key = achievementKey, Season = season, SeasonId = season.Id } }; fakeContext.Setup(x => x.List<Achievement>()) .Returns(achievements.AsQueryable()); //this is the only person in the database var person = new Person { Id = 100 }; var accountGroup = new AccountGroup() { }; person.AddToGroup(accountGroup, 12); var people = new[] { person }; fakeContext.Setup(x => x.List<Person>()) .Returns(people.AsQueryable()); season.AccountGroup = accountGroup; Season currentSeason = new Season { IsActive = true, StartDate = DateTime.Now.AddDays(-1), EndDate = DateTime.Now.AddDays(1), Achievements = new[] { new Achievement { Key = achievementKey, } } }; string customKey = person.Id.ToString(); Guid apiKey = Guid.NewGuid(); fakeContext.Setup(x => x.List<ApiKey>()).Returns(new[] { new ApiKey { Key = apiKey, IsActive = true, AccountGroup = new AccountGroup { Seasons = new [] { currentSeason }, Achievements = new List<Achievement>() { new Achievement { Key = achievementKey, } }, AccountGroupPeople = new [] { new AccountGroupPerson { CustomKey = customKey, Person = person } } } } }.AsQueryable()); AchievementManagement mng = new AchievementManagement(fakeContext.Object); var allocation = new AchievementAllocation(); allocation.CustomPersonKey = "no such key"; allocation.AchievementKey = achievementKey; allocation.ApiKey = apiKey; mng.GiveAchievement(allocation); }
public void GiveAchievement_NoActiveSeasons_Fails() { var key = Guid.NewGuid(); var fakeContext = new Mock<IDatabaseContext>(); var mng = new AchievementManagement(fakeContext.Object); var season1 = new Season { StartDate = DateTime.Now.AddDays(-100), EndDate = DateTime.Now.AddDays(-88), IsActive = true, Achievements = new [] { new Achievement { Key = key, IsApproved = true, } } }; var season2 = new Season { StartDate = DateTime.Now.AddDays(-87), EndDate = DateTime.Now.AddDays(-70), IsActive = true, Achievements = new [] { new Achievement { Key = key, IsApproved = true, } } }; fakeContext.Setup(x => x.List<Season>()).Returns( new[] { season1, season2 }.AsQueryable()); var allocation = new AchievementAllocation() { AchievementKey = key, }; mng.GiveAchievement(allocation); }