Esempio n. 1
0
        public async Task UpdateStandings_3WayTieBrokenWithWin_2TiedUsersHaveCorrectTieBreakScores()
        {
            var season  = CreateSeason((1, 5, 1000), (2, 5, 100), (3, 5, 10), (4, 2, 0));
            var player1 = season.Participants[0];
            var player2 = season.Participants[1];
            var player3 = season.Participants[2];
            var player4 = season.Participants[3];

            MockTieBreak(arg =>
            {
                arg.First(p => p.Key.ID == player1.ID).Key.TieBreakerPoints = 100;
                arg.First(p => p.Key.ID == player3.ID).Key.TieBreakerPoints = 10;
            });

            pointCalculator.CalculatePointDeltas(player2, player4).Returns((2, 1));

            var set = SetUtility.Create(dbContext, player2, player4, season.LeagueID);

            DbContextUtility.UpdateAndSave(dbContext, set, () =>
            {
                set.Player1Score = 1;
                set.Player2Score = 0;
            });

            await testObj.UpdateStandings(set.ID);

            Assert.Greater(player1.TieBreakerPoints, 0);
            Assert.Greater(player3.TieBreakerPoints, 0);

            Assert.AreEqual(0, player2.TieBreakerPoints);
        }
Esempio n. 2
0
        public void SetUp()
        {
            dbContext    = DbContextUtility.CreateMockDb();
            pointService = Substitute.For <IPointService>();

            testObj = new LeagueService(dbContext, pointService);
        }
Esempio n. 3
0
        public void SetUp()
        {
            dbContext     = DbContextUtility.CreateMockDb();
            seasonService = Substitute.For <ISeasonService>();

            testObj = new SetService(dbContext, seasonService);
        }
Esempio n. 4
0
        public void AddLeague_NotOwner_NotAuthorizedException()
        {
            var league       = CreateLeagueWithAdmin();
            var organization = DbContextUtility.AddNew <Organization>(dbContext);

            Assert.ThrowsAsync <NotAuthorizedException>(() => testObj.AddLeague(organization.ID, league.ID, userID));
        }
Esempio n. 5
0
        public void SetUp()
        {
            dbContext  = DbContextUtility.CreateMockDb();
            cdnService = Substitute.For <ICdnService>();

            testObj = new GameService(dbContext, cdnService);
        }
Esempio n. 6
0
        public void SetUp()
        {
            dbContext = DbContextUtility.CreateMockDb();

            testObj = new OrganizationService(dbContext);

            userID = DbContextUtility.AddNew <ApplicationUser>(dbContext).Id;
        }
Esempio n. 7
0
        public async Task Get_Valid_Ok()
        {
            var user = DbContextUtility.AddNew <ApplicationUser>(dbContext, u => u.Email = "*****@*****.**");

            var result = await testObj.Get(user.Id);

            ControllerUtility.AssertStatusCode(result, HttpStatusCode.OK);
        }
Esempio n. 8
0
 private void AddUser()
 {
     DbContextUtility.AddNew <ApplicationUser>(dbContext, u =>
     {
         u.Id    = ID;
         u.Email = Email;
     });
 }
Esempio n. 9
0
        public void SetUp()
        {
            dbContext = DbContextUtility.CreateMockDb();
            var logger     = Substitute.For <ILogger <GameApi> >();
            var cdnService = Substitute.For <ICdnService>();

            testObj = new GameApi(logger, dbContext, cdnService);
        }
Esempio n. 10
0
        public void SetUp()
        {
            var logger      = Substitute.For <ILogger <FakeBaseController> >();
            var userManager = Substitute.For <IUserManager>();
            var dbContext   = DbContextUtility.CreateMockDb();

            testObj = new FakeBaseController(logger, userManager, dbContext);
        }
Esempio n. 11
0
        public void SetUp()
        {
            setService = Substitute.For <ISetService>();
            dbContext  = DbContextUtility.CreateMockDb();
            var logger = Substitute.For <ILogger <SetApi> >();

            testObj = new SetApi(logger, dbContext, setService);
        }
Esempio n. 12
0
        public async Task ListForLeague_Valid_ReturnOk()
        {
            var league = DbContextUtility.AddNew <League>(dbContext, l => l.GameID = gameID);

            var result = await testObj.ListForLeague(league.ID);

            ControllerUtility.AssertStatusCode(result, HttpStatusCode.OK);
        }
Esempio n. 13
0
        public void SetUp()
        {
            dbContext = DbContextUtility.CreateMockDb();
            applicationUserService = Substitute.For <IApplicationUserService>();
            var logger     = Substitute.For <ILogger <UserApi> >();
            var cdnService = Substitute.For <ICdnService>();

            testObj = new UserApi(logger, dbContext, cdnService, applicationUserService);
        }
Esempio n. 14
0
        public async Task UploadImage_Valid_SetsUserProfilePicKey()
        {
            var user = DbContextUtility.AddNew <ApplicationUser>(dbContext);
            var file = PrepareCdnService();

            await testObj.UploadProfilePic(user.Id, file);

            Assert.AreEqual(ImageKey, user.ProfilePicKey);
        }
Esempio n. 15
0
        public async Task UploadImage_Valid_ReturnImageUrl()
        {
            var user = DbContextUtility.AddNew <ApplicationUser>(dbContext);
            var file = PrepareCdnService();

            var imageUrl = await testObj.UploadProfilePic(user.Id, file);

            Assert.AreEqual(ImageUrl, imageUrl);
        }
Esempio n. 16
0
        public async Task Create_Valid_ReturnOk()
        {
            var league  = DbContextUtility.AddNew <League>(dbContext, l => l.GameID = gameID);
            var request = new CreateRequest(league.ID, DateTime.Now.AddMinutes(1), DateTime.Now.AddMinutes(2));

            var result = await testObj.Create(request);

            ControllerUtility.AssertStatusCode(result, HttpStatusCode.Created);
        }
Esempio n. 17
0
        public void SetUp()
        {
            leagueService = Substitute.For <ILeagueService>();
            dbContext     = DbContextUtility.CreateMockDb();
            var logger        = Substitute.For <ILogger <LeagueApi> >();
            var configuration = Substitute.For <IConfiguration>();

            testObj = new LeagueApi(logger, dbContext, leagueService, configuration);
        }
Esempio n. 18
0
        public async Task Create_Valid_ReturnLeague()
        {
            var admin = DbContextUtility.AddNew <ApplicationUser>(dbContext);
            var game  = DbContextUtility.AddNew <Game>(dbContext);

            var league = await testObj.Create("", game.ID, admin.Id);

            Assert.IsNotNull(league);
        }
Esempio n. 19
0
        public async Task Create_Valid_AdminAdded()
        {
            var admin = DbContextUtility.AddNew <ApplicationUser>(dbContext);
            var game  = DbContextUtility.AddNew <Game>(dbContext);

            var league = await testObj.Create("", game.ID, admin.Id);

            Assert.AreEqual(admin.Id, league.Members[0].UserID);
        }
Esempio n. 20
0
        public void SetUp()
        {
            seasonService = Substitute.For <ISeasonService>();
            dbContext     = DbContextUtility.CreateMockDb();
            var logger      = Substitute.For <ILogger <SeasonController> >();
            var userManager = Substitute.For <IUserManager>();

            testObj = new SeasonController(seasonService, dbContext, logger, userManager);
        }
Esempio n. 21
0
        public async Task Join_NewUser_UpdateDisplayName()
        {
            var league = LeagueUtility.CreateLeague(dbContext);
            var user   = DbContextUtility.AddNew <ApplicationUser>(dbContext, u => u.UserName = "******");

            var leagueUser = await testObj.Join(league.ID, user.Id);

            Assert.AreEqual(user.UserName, leagueUser.DisplayName);
        }
Esempio n. 22
0
        public async Task UploadProfilePic_Valid_Created()
        {
            var user = DbContextUtility.AddNew <ApplicationUser>(dbContext);
            var file = Substitute.For <IFormFile>();

            var result = await testObj.UploadProfilePic(user.Id, file);

            ControllerUtility.AssertStatusCode(result, HttpStatusCode.Created);
        }
Esempio n. 23
0
        public async Task UpdateSettings_NoProfilePic_DontUpdatePicture()
        {
            var user = DbContextUtility.AddNew <ApplicationUser>(dbContext);

            await testObj.UpdateSettings(user.Id, "bob", "", null);

#pragma warning disable 4014
            cdnService.DidNotReceiveWithAnyArgs().UploadImageAsync(null, null);
#pragma warning restore 4014
        }
Esempio n. 24
0
        public async Task Get_Valid_ReturnUser()
        {
            var user = DbContextUtility.AddNew <ApplicationUser>(dbContext, u => u.Email = "*****@*****.**");

            var result = await testObj.Get(user.Id);

            var resultObj = result.GetObject <UserDto>();

            Assert.AreEqual(user.Email, resultObj.Email);
        }
Esempio n. 25
0
        public async Task ForgotPassword_SignedIn_RedirectToUserHome()
        {
            var user = DbContextUtility.AddNew <ApplicationUser>(dbContext);

            userManager.GetUserAsync(null).ReturnsForAnyArgs(user);

            var result = await testObj.ForgotPassword();

            Assert.IsInstanceOf <RedirectToActionResult>(result);
        }
Esempio n. 26
0
        public void Add <TEntity>(TEntity entity)
            where TEntity : class, IKeyIdentity <TKey>
        {
            ICollection <TEntity> entityCollection = (ICollection <TEntity>)GetCollection(typeof(TEntity));

            if (GenerateId)
            {
                entity.Id = DbContextUtility.GenerateNewKey();
            }
            entityCollection.Add(entity);
        }
Esempio n. 27
0
        public async Task UpdateSettings_ProfilePic_UpdatePicture()
        {
            var user = DbContextUtility.AddNew <ApplicationUser>(dbContext);
            var file = Substitute.For <IFormFile>();

            await testObj.UpdateSettings(user.Id, "bob", "", file);

#pragma warning disable 4014
            cdnService.Received(1).ReplaceImageAsync(Arg.Any <string>(), file, ClimbImageRules.ProfilePic);
#pragma warning restore 4014
        }
Esempio n. 28
0
        public async Task Join_Valid_Created()
        {
            var league = LeagueUtility.CreateLeague(dbContext);
            var user   = DbContextUtility.AddNew <ApplicationUser>(dbContext);

            var request = new JoinRequest(league.ID, user.Id);

            var result = await testObj.Join(request);

            ControllerUtility.AssertStatusCode(result, HttpStatusCode.Created);
        }
Esempio n. 29
0
        public async Task Join_OldUser_HasLeftFalse()
        {
            var        league        = LeagueUtility.CreateLeague(dbContext);
            var        user          = DbContextUtility.AddNew <ApplicationUser>(dbContext);
            LeagueUser oldLeagueUser = CreateOldLeagueUser(league, user);

            var leagueUser = await testObj.Join(league.ID, user.Id);

            Assert.IsFalse(leagueUser.HasLeft);
            Assert.AreEqual(oldLeagueUser.ID, leagueUser.ID);
        }
Esempio n. 30
0
        public void SetUp()
        {
            dbContext = DbContextUtility.CreateMockDb();
            var game = DbContextUtility.AddNew <Game>(dbContext);

            gameID = game.ID;

            seasonService = Substitute.For <ISeasonService>();
            var logger = Substitute.For <ILogger <SeasonApi> >();

            testObj = new SeasonApi(logger, dbContext, seasonService);
        }