Ejemplo n.º 1
0
        public async Task CreateShouldAddNewTournament()
        {
            const string       databaseName = "TournamentCreate";
            ITournamentService service      = await GetTournamentService(databaseName);

            //Act
            TournamentFormModel expectedModel = new TournamentFormModel()
            {
                Id              = 5,
                Name            = "SandanskiOpen",
                StartDate       = new DateTime(),
                Place           = "Sandanski",
                NumberOfPlayers = 16,
                Type            = Domain.Enums.Tournament.TournamentType.Charity
            };

            await service.Create(expectedModel, new Guid().ToString());

            var db          = new FakeSportDbContext(databaseName);
            var actualModel = db.Data.Tournaments.FirstOrDefault(t => t.Id == 5);

            //Assert
            Assert.True(expectedModel.Id == actualModel.Id);
            Assert.True(expectedModel.Name.Equals(actualModel.Name));
            Assert.True(expectedModel.StartDate == actualModel.StartDate);
            Assert.True(expectedModel.NumberOfPlayers == actualModel.NumberOfPlayers);
            Assert.True(expectedModel.Place.Equals(actualModel.Place));
        }
Ejemplo n.º 2
0
        public async Task SignoutShouldSignOutCurrentUser()
        {
            //Arrange
            const string databaseName = "TournamentSignOutUser";
            var          db           = new FakeSportDbContext(databaseName);

            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new DomainProfile());
            });
            var mapper = config.CreateMapper();

            await AddTournaments(db);

            var mockUserStore = new Mock <IUserStore <User> >();
            UserManager <User> userManager = GetUserManager(mockUserStore);

            ITournamentService service = new TournamentService(mapper, db.Data, userManager);

            //Act
            var userId       = "1";
            var tournamentId = 2;
            await service.Signout(tournamentId, userId);

            var actualResult = db.Data.UserTournament.Any(u => u.UserId == userId);

            //Assert
            Assert.False(actualResult);
        }
Ejemplo n.º 3
0
        public async Task StartShouldCreateMatchesAndSetIsStartedTrue()
        {
            const string       databaseName = "TournamentStart";
            ITournamentService service      = await GetTournamentService(databaseName);

            //Act
            var tournamentId       = 4;
            var expectedTournament = service.ById(tournamentId);

            service.Start(tournamentId);

            var db = new FakeSportDbContext(databaseName);
            var actualTournament = db.Data.Tournaments
                                   .FirstOrDefault(t => t.Id == tournamentId);

            //Assert
            Assert.True(actualTournament.IsStarted);
        }
Ejemplo n.º 4
0
        private static async Task <ITournamentService> GetTournamentService(string databaseName)
        {
            var db = new FakeSportDbContext(databaseName);

            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new DomainProfile());
            });
            var mapper = config.CreateMapper();

            if (databaseName.Equals("TournamentCreate") ||
                databaseName.Equals("TournamentGetTournamentPlayers"))
            {
                await AddUsers(db);
            }
            else
            {
                await AddTournaments(db);
            }

            var user = new User()
            {
                Id = new Guid().ToString()
            };


            var mockUserStore = new Mock <IUserStore <User> >();
            var userManager   = GetUserManager(mockUserStore);

            mockUserStore.Setup(x => x.FindByIdAsync(user.Id, CancellationToken.None))
            .ReturnsAsync(new User()
            {
                Id = user.Id
            });
            ITournamentService service = new TournamentService(mapper, db.Data, userManager);

            return(service);
        }
Ejemplo n.º 5
0
        public async Task SigninShouldSignInCurrentUser()
        {
            //Arrange
            const string databaseName = "TournamentSigninUser";
            var          db           = new FakeSportDbContext(databaseName);

            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new DomainProfile());
            });
            var mapper = config.CreateMapper();

            await AddTournaments(db);

            var mockUserStore = new Mock <IUserStore <User> >();
            UserManager <User> userManager = GetUserManager(mockUserStore);

            ITournamentService service = new TournamentService(mapper, db.Data, userManager);
            //Act
            var user = new User()
            {
                Id = new Guid().ToString()
            };

            mockUserStore.Setup(x => x.FindByIdAsync(user.Id, CancellationToken.None))
            .ReturnsAsync(new User()
            {
                Id = user.Id
            });

            service.Signin(1, user);
            var actualResult = db.Data.UserTournament.Any(u => u.UserId == user.Id);

            //Assert
            Assert.True(actualResult);
        }
Ejemplo n.º 6
0
 private static Task AddUsers(FakeSportDbContext db)
 {
     return(db.Add(
                new User()
     {
         Id = "1",
         Email = "*****@*****.**"
     },
                new User()
     {
         Id = "2",
         Tournaments = new List <UserTournament>()
         {
             new UserTournament()
             {
                 TournamentId = 3,
                 UserId = "2"
             }
         }
     },
                new User()
     {
         Id = "3",
         Tournaments = new List <UserTournament>()
         {
             new UserTournament()
             {
                 TournamentId = 3,
                 UserId = "3"
             }
         }
     },
                new User()
     {
         Id = "4",
         Tournaments = new List <UserTournament>()
         {
             new UserTournament()
             {
                 TournamentId = 3,
                 UserId = "4"
             }
         }
     },
                new User()
     {
         Id = "5",
         Tournaments = new List <UserTournament>()
         {
             new UserTournament()
             {
                 TournamentId = 3,
                 UserId = "5"
             }
         }
     },
                new User()
     {
         Id = "6",
         Tournaments = new List <UserTournament>()
         {
             new UserTournament()
             {
                 TournamentId = 3,
                 UserId = "6"
             }
         }
     },
                new User()
     {
         Id = "7",
         Tournaments = new List <UserTournament>()
         {
             new UserTournament()
             {
                 TournamentId = 3,
                 UserId = "7"
             }
         }
     },
                new User()
     {
         Id = "8",
         Tournaments = new List <UserTournament>()
         {
             new UserTournament()
             {
                 TournamentId = 3,
                 UserId = "8"
             }
         }
     },
                new User()
     {
         Id = "9",
         Tournaments = new List <UserTournament>()
         {
             new UserTournament()
             {
                 TournamentId = 3,
                 UserId = "9"
             }
         }
     }));
 }
Ejemplo n.º 7
0
 private static Task AddTournaments(FakeSportDbContext db)
 {
     return(db.Add(
                new Tournament()
     {
         Id = 1,
         Name = "SofiaOpen",
         Place = "Sofia",
         NumberOfPlayers = 8
     },
                new Tournament()
     {
         Id = 2,
         Name = "BurgasOpen",
         Place = "Burgas",
         NumberOfPlayers = 8,
         Players = new List <UserTournament>()
         {
             new UserTournament()
             {
                 UserId = "1",
                 TournamentId = 2
             }
         }
     },
                new Tournament()
     {
         Id = 3,
         Name = "VarnaOpen",
         Place = "Varna",
         NumberOfPlayers = 8,
         Matches = new List <Domain.Match>()
         {
             new Domain.Match()
             {
                 Id = 1
             },
             new Domain.Match()
             {
                 Id = 2
             },
             new Domain.Match()
             {
                 Id = 3
             },
             new Domain.Match()
             {
                 Id = 4
             }
         },
         Players = new List <UserTournament>()
         {
             new UserTournament()
             {
                 UserId = "2",
                 TournamentId = 3
             },
             new UserTournament()
             {
                 UserId = "3",
                 TournamentId = 3
             },
             new UserTournament()
             {
                 UserId = "4",
                 TournamentId = 3
             },
             new UserTournament()
             {
                 UserId = "5",
                 TournamentId = 3
             },
             new UserTournament()
             {
                 UserId = "6",
                 TournamentId = 3
             },
             new UserTournament()
             {
                 UserId = "7",
                 TournamentId = 3
             },
             new UserTournament()
             {
                 UserId = "8",
                 TournamentId = 3
             },
             new UserTournament()
             {
                 UserId = "9",
                 TournamentId = 3
             }
         }
     }
                ,
                new Tournament()
     {
         Id = 4,
         Name = "SlivenOpen",
         Place = "Sliven",
         NumberOfPlayers = 8,
         Players = new List <UserTournament>()
         {
             new UserTournament()
             {
                 User = CreateUser(),
                 UserId = "2",
                 TournamentId = 4
             },
             new UserTournament()
             {
                 User = CreateUser(),
                 UserId = "3",
                 TournamentId = 4
             },
             new UserTournament()
             {
                 User = CreateUser(),
                 UserId = "4",
                 TournamentId = 4
             },
             new UserTournament()
             {
                 User = CreateUser(),
                 UserId = "5",
                 TournamentId = 4
             },
             new UserTournament()
             {
                 User = CreateUser(),
                 UserId = "6",
                 TournamentId = 4
             },
             new UserTournament()
             {
                 User = CreateUser(),
                 UserId = "7",
                 TournamentId = 4
             },
             new UserTournament()
             {
                 User = CreateUser(),
                 UserId = "8",
                 TournamentId = 4
             },
             new UserTournament()
             {
                 User = CreateUser(),
                 UserId = "9",
                 TournamentId = 4
             }
         }
     }));
 }