public async Task AddStadiumCommand_Can_Add_Stadium() { using (var dbContext = GetDbContext("AddStadiumCommand_Can_Add_Stadium")) { var fakePlayerRepo = new PlayerRepository(dbContext); await fakePlayerRepo.AddAsync(new Domain.Entities.Player { Name = "FirstPlayer", Surname = "LastName", Height = 1.98, EmailAddress = "*****@*****.**" }); await fakePlayerRepo.AddAsync(new Domain.Entities.Player { Name = "SecondPlayer", Surname = "LastName", Height = 1.98, EmailAddress = "*****@*****.**" }); var fakeTeamRepo = new TeamRepository(dbContext); var players = fakePlayerRepo.GetAll(); await fakeTeamRepo.AddAsync(new Domain.Entities.Team { Name = "FirstTeam", Players = players.ToList() }); } using (var dbContext = GetDbContext("AddStadiumCommand_Can_Add_Stadium")) { var fakeStadiumRepo = new StadiumRepository(dbContext); var fakeTeamRepo = new TeamRepository(dbContext); var fakeLogger = new Mock <ILogger <AddStadiumCommandHandler> >(); var handler = new AddStadiumCommandHandler(fakeStadiumRepo, fakeTeamRepo, GetMapper(), fakeLogger.Object); var command = new AddStadiumCommand { Name = "TestStadiumName", TeamId = 1 }; var result = await handler.Handle(command, default); Assert.False(result.Notifications.HasErrors()); Assert.Equal(command.Name, result.StadiumLookupModel.Name); Assert.Equal(command.TeamId, result.StadiumLookupModel.Team.Id); } }
public async Task AddTeamCommand_Can_Add_Team() { using (var dbContext = GetDbContext("AddTeamCommand_Can_Add_Team")) { var fakeRepo = new PlayerRepository(dbContext); await fakeRepo.AddAsync(new Domain.Entities.Player { Name = "FirstPlayer", Surname = "LastName", Height = 1.98, EmailAddress = "*****@*****.**" }); await fakeRepo.AddAsync(new Domain.Entities.Player { Name = "SecondPlayer", Surname = "LastName", Height = 1.98, EmailAddress = "*****@*****.**" }); } using (var dbContext = GetDbContext("AddTeamCommand_Can_Add_Team")) { var fakeTeamRepo = new TeamRepository(dbContext); var fakePlayerRepo = new PlayerRepository(dbContext); var fakeLogger = new Mock <ILogger <AddTeamCommandHandler> >(); var handler = new AddTeamCommandHandler(fakeTeamRepo, fakePlayerRepo, GetMapper(), fakeLogger.Object); var command = new AddTeamCommand { Name = "TestTeamName", Longitude = 8.11, Latitude = 9.43, PlayerIds = new List <int> { 1, 2 } }; var result = await handler.Handle(command, default); Assert.False(result.Notifications.HasErrors()); Assert.Equal(command.Name, result.TeamLookupModel.Name); Assert.Equal(command.Latitude, result.TeamLookupModel.Latitude); Assert.Equal(command.Longitude, result.TeamLookupModel.Longitude); Assert.Equal(command.PlayerIds.ToList()[0], result.TeamLookupModel.Players.ToList()[0].Id); Assert.Equal(command.PlayerIds.ToList()[1], result.TeamLookupModel.Players.ToList()[1].Id); } }
public async Task GetPlayersQuery_Can_Return_Players() { var dbContext = GetDbContext("GetPlayersQuery_Can_Return_Players"); using (dbContext) { var fakeRepo = new PlayerRepository(dbContext); var fakeLogger = new Mock <ILogger <GetPlayersQueryHandler> >(); var handler = new GetPlayersQueryHandler(fakeRepo, GetMapper(), fakeLogger.Object); var playerToAdd = new Player { Name = "FirstName", Surname = "LastName", Height = 1.98, EmailAddress = "*****@*****.**" }; await fakeRepo.AddAsync(playerToAdd); var result = await handler.Handle(new GetPlayersQuery(), default); Assert.False(result.Notifications.HasErrors()); Assert.Equal(1, result.Players.Count); Assert.Equal(playerToAdd.Name, result.Players[0].Name); Assert.Equal(playerToAdd.Surname, result.Players[0].Surname); Assert.Equal(playerToAdd.Height, result.Players[0].Height); Assert.Equal(playerToAdd.EmailAddress, result.Players[0].EmailAddress); } }
public async Task DeletePlayerCommand_Can_Delete_Player() { using (var dbContext = GetDbContext("DeletePlayerCommand_Can_Delete_Player")) { var fakeRepo = new PlayerRepository(dbContext); await fakeRepo.AddAsync(new Domain.Entities.Player { Name = "FirstName", Surname = "LastName", Height = 1.98, EmailAddress = "*****@*****.**" }); } using (var dbContext = GetDbContext("DeletePlayerCommand_Can_Delete_Player")) { var fakeRepo = new PlayerRepository(dbContext); var fakeLogger = new Mock <ILogger <DeletePlayerCommandHandler> >(); var handler = new DeletePlayerCommandHandler(fakeRepo, GetMapper(), fakeLogger.Object); var command = new DeletePlayerCommand { Id = 1, }; var result = await handler.Handle(command, default); Assert.False(result.Notifications.HasErrors()); Assert.Equal(command.Id, result.PlayerDeleteModel.Id); Assert.Equal(Domain.Enumerations.EnumBag.DataState.Inactive, result.PlayerDeleteModel.DataState); } }
public async Task GetPlayerByIdQuery_Can_Return_Player() { var dbContext = GetDbContext("GetPlayerByIdQuery_Can_Return_Player"); using (dbContext) { var fakeRepo = new PlayerRepository(dbContext); var fakeLogger = new Mock <ILogger <GetPlayerByIdQueryHandler> >(); var handler = new GetPlayerByIdQueryHandler(fakeRepo, GetMapper(), fakeLogger.Object); var playersToAdd = new List <Player> { new Player { Name = "FirstName", Surname = "LastName", Height = 1.98, EmailAddress = "*****@*****.**" }, new Player { Name = "SecondName", Surname = "SecondLastName", Height = 1.98, EmailAddress = "*****@*****.**" }, new Player { Name = "ThirdName", Surname = "ThirdLastName", Height = 1.98, EmailAddress = "*****@*****.**" }, }; foreach (var playerToAdd in playersToAdd) { await fakeRepo.AddAsync(playerToAdd); } var result = await handler.Handle(new GetPlayerByIdQuery() { Id = 2 }, default); Assert.False(result.Notifications.HasErrors()); var secondPlayer = result.PlayerLookupModel; Assert.Equal(playersToAdd[1].Name, secondPlayer.Name); Assert.Equal(playersToAdd[1].Surname, secondPlayer.Surname); Assert.Equal(playersToAdd[1].Height, secondPlayer.Height); Assert.Equal(playersToAdd[1].EmailAddress, secondPlayer.EmailAddress); } }
public async Task UpdatePlayerCommand_Can_Update_Player() { using (var dbContext = GetDbContext("UpdatePlayerCommand_Can_Update_Player")) { var fakeRepo = new PlayerRepository(dbContext); await fakeRepo.AddAsync(new Domain.Entities.Player { Name = "FirstName", Surname = "LastName", Height = 1.98, EmailAddress = "*****@*****.**" }); } using (var dbContext = GetDbContext("UpdatePlayerCommand_Can_Update_Player")) { var fakeRepo = new PlayerRepository(dbContext); var fakeLogger = new Mock <ILogger <UpdatePlayerCommandHandler> >(); var handler = new UpdatePlayerCommandHandler(fakeRepo, GetMapper(), fakeLogger.Object); var command = new UpdatePlayerCommand { Id = 1, Name = "NewName", Surname = "NewLastName", Height = 1.55, EmailAddress = "*****@*****.**" }; var result = await handler.Handle(command, default); Assert.False(result.Notifications.HasErrors()); Assert.Equal(command.Name, result.PlayerLookupModel.Name); Assert.Equal(command.Surname, result.PlayerLookupModel.Surname); Assert.Equal(command.Height, result.PlayerLookupModel.Height); Assert.Equal(command.EmailAddress, result.PlayerLookupModel.EmailAddress); } }
public async Task GetStadiumByIdQuery_Can_Return_Stadium() { var dbContext = GetDbContext("GetStadiumByIdQuery_Can_Return_Stadium"); using (dbContext) { var fakeStadiumRepo = new StadiumRepository(dbContext); var fakeTeamRepo = new TeamRepository(dbContext); var fakeLogger = new Mock <ILogger <GetStadiumByIdQueryHandler> >(); var handler = new GetStadiumByIdQueryHandler(fakeStadiumRepo, GetMapper(), fakeLogger.Object); var fakePlayerRepo = new PlayerRepository(dbContext); await fakePlayerRepo.AddAsync(new Domain.Entities.Player { Name = "FirstPlayer", Surname = "LastName", Height = 1.98, EmailAddress = "*****@*****.**" }); await fakePlayerRepo.AddAsync(new Domain.Entities.Player { Name = "SecondPlayer", Surname = "LastName", Height = 1.98, EmailAddress = "*****@*****.**" }); await fakePlayerRepo.AddAsync(new Domain.Entities.Player { Name = "ThirdPlayer", Surname = "LastName", Height = 1.98, EmailAddress = "*****@*****.**" }); var TeamsToAdd = new List <Team> { new Team { Name = "TeamOne", Longitude = 1.11, Latitude = 1.43, Players = new List <Player> { await fakePlayerRepo.GetPlayerByIdAsync(1) } }, new Team { Name = "TeamTwo", Longitude = 2.11, Latitude = 2.43, Players = new List <Player> { await fakePlayerRepo.GetPlayerByIdAsync(2) } }, new Team { Name = "TeamThree", Longitude = 3.11, Latitude = 3.43, Players = new List <Player> { await fakePlayerRepo.GetPlayerByIdAsync(3) } }, }; foreach (var TeamToAdd in TeamsToAdd) { await fakeTeamRepo.AddAsync(TeamToAdd); } var StadiumsToAdd = new List <Stadium> { new Stadium { Name = "StadiumOne", TeamId = 1 }, new Stadium { Name = "StadiumTwo", TeamId = 2 }, new Stadium { Name = "StadiumThree", TeamId = 3 } }; foreach (var StadiumToAdd in StadiumsToAdd) { await fakeStadiumRepo.AddAsync(StadiumToAdd); } var result = await handler.Handle(new GetStadiumByIdQuery() { Id = 2 }, default); Assert.False(result.Notifications.HasErrors()); var secondStadium = result.StadiumLookupModel; Assert.Equal(StadiumsToAdd[1].Name, secondStadium.Name); Assert.Equal(StadiumsToAdd[1].Team.Id, secondStadium.Team.Id); } }
public async Task AddAsync(Player entity) { await _repository.AddAsync(entity); await _unitOfWork.SaveChangesAsync(); }
public async Task UpdateTeamPlayersCommand_Can_Add_Team() { using (var dbContext = GetDbContext("UpdateTeamPlayersCommand_Can_Add_Team")) { var fakePlayerRepo = new PlayerRepository(dbContext); await fakePlayerRepo.AddAsync(new Domain.Entities.Player { Name = "FirstPlayer", Surname = "LastName", Height = 1.98, EmailAddress = "*****@*****.**" }); await fakePlayerRepo.AddAsync(new Domain.Entities.Player { Name = "SecondPlayer", Surname = "LastName", Height = 1.98, EmailAddress = "*****@*****.**" }); var fakeTeamRepo = new TeamRepository(dbContext); await fakeTeamRepo.AddAsync(new Domain.Entities.Team { Name = "TeamName", Longitude = 1.11, Latitude = 1.43, }); var fakeTeam = fakeTeamRepo.GetTeamByIdAsync(1).Result; var fakePlayerOne = fakePlayerRepo.GetPlayerByIdAsync(1).Result; fakePlayerOne.Team = fakeTeam; fakeTeam.Players = new List <Player> { fakePlayerOne }; await fakePlayerRepo.UpdateAsync(fakePlayerOne); await fakeTeamRepo.UpdateAsync(fakeTeam); var fakeLogger = new Mock <ILogger <UpdateTeamPlayersCommandHandler> >(); var handler = new UpdateTeamPlayersCommandHandler(fakeTeamRepo, fakePlayerRepo, GetMapper(), fakeLogger.Object); var command = new UpdateTeamPlayersCommand { Id = 1, PlayerIds = new List <int> { 2 } }; var result = await handler.Handle(command, default); Assert.False(result.Notifications.HasErrors()); Assert.Equal(command.Id, result.TeamLookupModel.Id); Assert.Equal(1, result.TeamLookupModel.Players.ToList()[0].Id); Assert.Equal(command.PlayerIds.ToList()[0], result.TeamLookupModel.Players.ToList()[1].Id); } }
public async Task UpdateStadiumCommand_Can_Update_Stadium() { using (var dbContext = GetDbContext("UpdateStadiumCommand_Can_Update_Stadium")) { var fakeStadiumRepo = new StadiumRepository(dbContext); var fakeTeamRepo = new TeamRepository(dbContext); var fakePlayerRepo = new PlayerRepository(dbContext); await fakePlayerRepo.AddAsync(new Domain.Entities.Player { Name = "FirstPlayer", Surname = "LastName", Height = 1.98, EmailAddress = "*****@*****.**" }); await fakePlayerRepo.AddAsync(new Domain.Entities.Player { Name = "SecondPlayer", Surname = "LastName", Height = 1.98, EmailAddress = "*****@*****.**" }); await fakePlayerRepo.AddAsync(new Domain.Entities.Player { Name = "ThirdPlayer", Surname = "LastName", Height = 1.98, EmailAddress = "*****@*****.**" }); var TeamsToAdd = new List <Team> { new Team { Name = "TeamOne", Longitude = 1.11, Latitude = 1.43, Players = new List <Player> { await fakePlayerRepo.GetPlayerByIdAsync(1) } }, new Team { Name = "TeamTwo", Longitude = 2.11, Latitude = 2.43, Players = new List <Player> { await fakePlayerRepo.GetPlayerByIdAsync(2) } }, new Team { Name = "TeamThree", Longitude = 3.11, Latitude = 3.43, Players = new List <Player> { await fakePlayerRepo.GetPlayerByIdAsync(3) } }, }; foreach (var TeamToAdd in TeamsToAdd) { await fakeTeamRepo.AddAsync(TeamToAdd); } await fakeStadiumRepo.AddAsync(new Domain.Entities.Stadium { Name = "StadiumName", TeamId = 2 }); var fakeLogger = new Mock <ILogger <UpdateStadiumCommandHandler> >(); var handler = new UpdateStadiumCommandHandler(fakeStadiumRepo, GetMapper(), fakeLogger.Object); var command = new UpdateStadiumCommand { Id = 1, Name = "NewStadiumName", TeamId = 1 }; var result = await handler.Handle(command, default); Assert.False(result.Notifications.HasErrors()); Assert.Equal(command.Name, result.StadiumLookupModel.Name); Assert.Equal(command.TeamId, result.StadiumLookupModel.Team.Id); } }