Ejemplo n.º 1
0
        protected override void Save()
        {
            try
            {
                Game newGame = new Game(Name.Trim(), ExecutablePath.Trim());

                if (_existingGame == null)
                {
                    _gameService.Add(newGame);
                }
                else
                {
                    EditGame(newGame);
                }
            }
            catch (DuplicateEntityException)
            {
                _dialogService.ShowErrorDialog("无法保存此游戏,因为已经存在此名称或目录的游戏。");
            }
            catch (Exception exception)
            {
                _dialogService.ShowErrorDialog("保存游戏时出错。" + Environment.NewLine + exception.Message);
            }
            finally
            {
                Close();
            }
        }
        public void GameOutcome()
        {
            //Arrange
            var id       = new ObjectId();
            var uniqueId = new BsonObjectId(id);

            var playerOne = new Player()
            {
                Id     = uniqueId,
                Name   = "Falsum Hominem",
                Losses = 1,
                Wins   = 2,
            };

            var mockRepo = new Mock <IRepository <IPlayer> >();

            mockRepo.Setup(x => x.FindByUsername("Falsum Hominem")).Returns(playerOne);

            var gameService = new GameService(mockRepo.Object);
            var winner      = "Falsum Hominem";
            var loser       = "Falsum Hominem";

            //Act
            var game = gameService.Add(winner, loser);

            //Assert
            game.Winner.Should().Be(playerOne.Id);
            game.Loser.Should().Be(playerOne.Id);
        }
Ejemplo n.º 3
0
        protected override void Save()
        {
            try
            {
                Game newGame = new Game(Name.Trim(), ExecutablePath.Trim());

                if (_existingGame == null)
                {
                    _gameService.Add(newGame);
                }
                else
                {
                    EditGame(newGame);
                }
            }
            catch (DuplicateEntityException)
            {
                _dialogService.ShowErrorDialog("Can't save this game because a game already exists with this name or directory.");
            }
            catch (Exception exception)
            {
                _dialogService.ShowErrorDialog("Error saving game." + Environment.NewLine + exception.Message);
            }
            finally
            {
                Close();
            }
        }
Ejemplo n.º 4
0
        public ActionResult AddGame(Game game, HttpPostedFileBase GamePhoto, int SizeVersion)
        {
            try
            {
                CategoryService catservice = new CategoryService(db);
                var             categories = catservice.GetAll();

                ViewBag.Categories = categories;
                if (ModelState.IsValid)
                {
                    if (GamePhoto != null)
                    {
                        if (GamePhoto.ContentLength > 1048576)
                        {
                            ModelState.AddModelError("PhotoLenght", "Please add correct Photo.");
                            return(View(game));
                        }
                        if (GamePhoto.ContentType != "image/jpeg" && GamePhoto.ContentType != "image/jpg" && GamePhoto.ContentType != "image/gif" && GamePhoto.ContentType != "image/png")
                        {
                            ModelState.AddModelError("PhotoLenght", "Please add correct Photo.");
                            return(View(game));
                        }
                    }



                    string date     = DateTime.Now.ToString("yyMMddHHmmss");
                    string fileName = date + GamePhoto.FileName;
                    string path     = Path.Combine(Server.MapPath("~/Uploads/GameImage"), fileName);
                    GamePhoto.SaveAs(path);
                    if (SizeVersion == 1)
                    {
                        float size = game.Size;
                        size      = size / 1024;
                        game.Size = size;
                    }
                    game.GamePhoto = fileName;
                    GameService service = new GameService(db);
                    game.Confirm    = Confirm.Incorrect.ToString();
                    game.CreateDate = DateTime.Now;
                    var user = Session["User"] as User;
                    game.UserId = user.Id;
                    service.Add(game);
                    db.SaveChanges();
                    Session["GameAddAdmin"] = true;
                    return(RedirectToAction("UserProfile", "Game"));
                }

                return(View(game));
            }
            catch (Exception)
            {
                ModelState.AddModelError("Size", "Please add correct Size.");
                CategoryService catservice = new CategoryService(db);
                var             categories = catservice.GetAll();

                ViewBag.Categories = categories;
                return(View(game));
            }
        }
Ejemplo n.º 5
0
        public int Add(PLGame item)
        {
            //I hate this point, but how can i simplify?

            if (PLValidation.IsItemNull(item))
            {
                Console.WriteLine($"Cant add null");
                return(0);
            }
            if ((!PLValidation.ValidateId(item.GenreId)) || (!PLValidation.ValidateId(item.PublisherID)) || (!PLValidation.ValidateYear(item.YearOfProduction)))
            {
                return(0);
            }
            int addResult = _curGameWorkerService.Add(new BLLGame {
                GameName = item.GameName, YearOfProduction = item.YearOfProduction, GenreId = item.GenreId, PublisherID = item.PublisherID
            });

            if (addResult > 0)
            {
                Console.WriteLine($"Item {item.GameName} was added");
            }
            else
            {
                Console.WriteLine($"Item add error");
            }
            return(addResult);
        }
Ejemplo n.º 6
0
        public void Add_IsCalled_CalledOneTime()
        {
            _gameRepository.Setup(p => p.Add(It.IsAny <Game>()));

            _sut.Add(new Game(), It.IsAny <string>());

            _gameRepository.Verify(p => p.Add(It.IsAny <Game>()), Times.Once);
        }
Ejemplo n.º 7
0
        public void GetGameFromMatchTest()
        {
            var service      = new GameService();
            var matchService = new MatchService();
            var match        = new Match(new ArenaName("test"), Guid.NewGuid(), Guid.NewGuid(), dummySeries.SeriesDummy);
            var game         = service.GetGameFromMatch(match);

            Assert.IsTrue(game == null);
            matchService.Add(match);
            service.Add(match.Id);
            game = service.GetGameFromMatch(match);
            Assert.IsTrue(game != null);
        }
Ejemplo n.º 8
0
        public async Task game_service_add_should_succeed()
        {
            var createGameViewModel = new GameCreateViewModel
            {
                UserId      = 1,
                ReleaseDate = DateTime.UtcNow,
                Name        = "test",
                Description = "test",
            };

            _gameService.Add(createGameViewModel);
            _autoMapperMock.Verify(x => x.Map <CreateGameCommand>(createGameViewModel), Times.Once);
            _mediatorBusMock.Verify(x => x.SendCommand(It.IsAny <CreateGameCommand>()), Times.Once);
        }
Ejemplo n.º 9
0
        public void Check_That_Game_Service_Adds_Game()
        {
            //Arrange
            var mock = new Mock <IUnitOfWork>();

            mock.Setup(m => m.GameRepository.Insert(It.IsAny <Game>()));

            var gameService = new GameService(mock.Object);

            //Act
            gameService.Add(new GameModel());

            //Assert
            mock.Verify(m => m.SaveChanges());
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            Console.WriteLine("///////////OYUNCU EKLEME///////////");
            DateTime tarih  = new DateTime(1988, 07, 05);
            Gamer    gamer1 = new Gamer
            {
                Id          = 1,
                NationalId  = 31187118752,
                FirstName   = "Saide Işılay".ToUpper(),
                LastName    = "Baykal".ToUpper(),
                DateOfBirth = tarih
            };
            GamerService gamerService = new GamerService(new GamerValidation());

            gamerService.Add(gamer1);

            Console.WriteLine("///////////OYUN EKLEME///////////");
            Game game1 = new Game
            {
                Id            = 1,
                GameName      = "The Talos Principle",
                GameCategory  = "Stategy",
                GameUnitPrice = 60
            };

            GameService gameService = new GameService();

            gameService.Add(game1);

            Console.WriteLine("///////////KAMPANYA EKLEME///////////");
            Campaign campaign = new Campaign
            {
                Id           = 1,
                CampaignName = "Arkadaş kampanyası",
                Description  = "1-7 Mart tarihlerde geçerli olan bu kampanyada kendine ve seçtiğin bir arkadaşına 'Jammer' ve 'Reflector' ENVANTERLERİNİ veriyoruz!!!"
            };
            CampaignService campaignService = new CampaignService();

            campaignService.Add(campaign);

            Console.WriteLine("///////////SATIŞ EKLEME///////////");
            SaleGameService saleGameService = new SaleGameService();

            saleGameService.SalesToGamer(game1, gamer1);
            Console.WriteLine("///////////KAMPANYALI SATIŞ EKLEME///////////");
            saleGameService.SalesToGamerViaCampaign(game1, gamer1, campaign);
        }
Ejemplo n.º 11
0
        public void Check_That_Game_Service_Adds_Game()
        {
            //Arrange
            Mapping.MapInit();
            Mapper.AssertConfigurationIsValid();

            var mock = new Mock <IUnitOfWork>();

            mock.Setup(m => m.GameRepository.Insert(It.IsAny <Game>()));

            var gameService = new GameService(mock.Object);

            //Act
            gameService.Add(new GameModel());

            //Assert
            mock.Verify(m => m.Save());
        }
Ejemplo n.º 12
0
        public void Check_That_Game_Service_Add_Game_Rethrows_An_Exception()
        {
            //Arrange
            var mock = new Mock <IUnitOfWork>();

            mock.Setup(m => m.GameRepository.Insert(It.IsAny <Game>()))
            .Callback(() => { throw new Exception(); });

            var gameService = new GameService(mock.Object);

            var gameModel = new GameModel
            {
                GameId = 5,
                Key    = "testKey"
            };

            //Act
            gameService.Add(gameModel);
        }
Ejemplo n.º 13
0
        public void AddListOfGames()
        {
            var series = new DummySeries();
            var game1  = new Game(series.SeriesDummy.Schedule.ElementAt(0));
            var game2  = new Game(series.SeriesDummy.Schedule.ElementAt(1));
            var game3  = new Game(series.SeriesDummy.Schedule.ElementAt(2));

            var games = new List <Game>
            {
                game1,
                game2
            };

            gameService.Add(games);
            var allGames = DomainService.GetAllGames();

            Assert.IsTrue(allGames.Contains(game1));
            Assert.IsTrue(allGames.Contains(game2));
            Assert.IsFalse(allGames.Contains(game3));
        }
        public ActionResult Create(GameViewModel gameViewModel, HttpPostedFileBase file)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (gameViewModel.CoverImageFile != null && gameViewModel.CoverImageFile.ContentLength > 0)
                    {
                        try
                        {
                            string FileName = Path.GetFileNameWithoutExtension(gameViewModel.CoverImageFile.FileName);

                            //To Get File Extension
                            string FileExtension = Path.GetExtension(gameViewModel.CoverImageFile.FileName);

                            //Add Current Date To Attached File Name
                            FileName = FileName.Trim() + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + FileExtension;

                            //Get Upload path from Web.Config file AppSettings.
                            //string UploadPath = ConfigurationManager.AppSettings["UserImagePath"].ToString();
                            string path = Path.Combine(Server.MapPath("~/Images/Game_Cover_Images/"),
                                                       Path.GetFileName(FileName));

                            //To copy and save file into server.
                            gameViewModel.CoverImagePath = FileName;
                            gameViewModel.CoverImageFile.SaveAs(path);
                        }
                        catch (Exception ex)
                        {
                            ViewBag.Message = "ERROR:" + ex.Message.ToString();
                            ModelState.AddModelError("CoverImageFile", "Could not save file!");
                            return(View(gameViewModel));
                        }
                    }
                    else
                    {
                        gameViewModel.CoverImagePath = "noimage.jpg";
                    }

                    var game = new Game()
                    {
                        Title          = gameViewModel.Title,
                        DeveloperId    = gameViewModel.DeveloperId,
                        GenreId        = gameViewModel.GenreId,
                        Description    = gameViewModel.Description,
                        ReleaseDate    = gameViewModel.ReleaseDate,
                        CoverImagePath = gameViewModel.CoverImagePath
                    };

                    gameService.Add(game);
                    gameService.Save();

                    TempData["Message"] = "Movie created successfuly!";
                    return(RedirectToAction("Index"));
                }
            }
            catch
            {
                ModelState.AddModelError("", "Database error!");
                return(View(gameViewModel));
            }

            return(View(gameViewModel));
        }
Ejemplo n.º 15
0
        public DummyGames(DummySeries dummySeries)
        {
            this.GameOne    = new Game(dummySeries.SeriesDummy.Schedule.ElementAt(0));
            this.GameTwo    = new Game(dummySeries.SeriesDummy.Schedule.ElementAt(1));
            this.GameThree  = new Game(dummySeries.SeriesDummy.Schedule.ElementAt(2));
            this.GameFour   = new Game(dummySeries.SeriesDummy.Schedule.ElementAt(3));
            this.GameFive   = new Game(dummySeries.SeriesDummy.Schedule.ElementAt(4));
            this.GameSix    = new Game(dummySeries.SeriesDummy.Schedule.ElementAt(5));
            this.GameSeven  = new Game(dummySeries.SeriesDummy.Schedule.ElementAt(6));
            this.GameEight  = new Game(dummySeries.SeriesDummy.Schedule.ElementAt(7));
            this.GameNine   = new Game(dummySeries.SeriesDummy.Schedule.ElementAt(8));
            this.GameTen    = new Game(dummySeries.SeriesDummy.Schedule.ElementAt(9));
            this.GameEleven = new Game(dummySeries.SeriesDummy.Schedule.ElementAt(10));
            this.GameTwelve = new Game(dummySeries.SeriesDummy.Schedule.ElementAt(11));

            this.GameOne.Protocol.Goals.Add(new Goal(new MatchMinute(28), this.GameOne.HomeTeamId,
                                                     DomainService.FindTeamById(this.GameOne.HomeTeamId).PlayerIds.ElementAt(0)));
            this.GameOne.Protocol.Goals.Add(new Goal(new MatchMinute(48), this.GameOne.HomeTeamId,
                                                     DomainService.FindTeamById(this.GameOne.HomeTeamId).PlayerIds.ElementAt(1)));
            this.GameOne.Protocol.Cards.Add(new Card(new MatchMinute(75), this.GameOne.HomeTeamId,
                                                     DomainService.FindTeamById(this.GameOne.AwayTeamId).PlayerIds.ElementAt(2), CardType.Red));

            this.GameThree.Protocol.Goals.Add(new Goal(new MatchMinute(30), this.GameThree.AwayTeamId,
                                                       DomainService.FindTeamById(this.GameThree.AwayTeamId).PlayerIds.ElementAt(1)));
            this.GameThree.Protocol.Goals.Add(new Goal(new MatchMinute(50), this.GameThree.HomeTeamId,
                                                       DomainService.FindTeamById(this.GameThree.HomeTeamId).PlayerIds.ElementAt(2)));
            this.GameThree.Protocol.Cards.Add(new Card(new MatchMinute(75), this.GameThree.HomeTeamId,
                                                       DomainService.FindTeamById(this.GameThree.AwayTeamId).PlayerIds.ElementAt(1), CardType.Yellow));

            this.GameFive.Protocol.Goals.Add(new Goal(new MatchMinute(20), this.GameFive.AwayTeamId,
                                                      DomainService.FindTeamById(this.GameFive.AwayTeamId).PlayerIds.ElementAt(1)));
            this.GameFive.Protocol.Goals.Add(new Goal(new MatchMinute(45), this.GameFive.HomeTeamId,
                                                      DomainService.FindTeamById(this.GameFive.HomeTeamId).PlayerIds.ElementAt(0)));
            this.GameFive.Protocol.Cards.Add(new Card(new MatchMinute(70), this.GameFive.HomeTeamId,
                                                      DomainService.FindTeamById(this.GameFive.AwayTeamId).PlayerIds.ElementAt(1), CardType.Red));
            this.GameFive.Protocol.Goals.Add(new Goal(new MatchMinute(74), this.GameFive.AwayTeamId,
                                                      DomainService.FindTeamById(this.GameOne.AwayTeamId).PlayerIds.ElementAt(1)));
            this.GameFive.Protocol.Goals.Add(new Goal(new MatchMinute(80), this.GameFive.HomeTeamId,
                                                      DomainService.FindTeamById(this.GameOne.HomeTeamId).PlayerIds.ElementAt(1)));
            this.GameFive.Protocol.Cards.Add(new Card(new MatchMinute(89), this.GameFive.HomeTeamId,
                                                      DomainService.FindTeamById(this.GameFive.HomeTeamId).PlayerIds.ElementAt(0), CardType.Yellow));

            this.GameSeven.Protocol.Goals.Add(new Goal(new MatchMinute(11),
                                                       this.GameSeven.HomeTeamId,
                                                       DomainService.FindTeamById(this.GameSeven.HomeTeamId).PlayerIds.ElementAt(0)));
            this.GameSeven.Protocol.Goals.Add(new Goal(new MatchMinute(35),
                                                       this.GameSeven.HomeTeamId,
                                                       DomainService.FindTeamById(this.GameSeven.HomeTeamId).PlayerIds.ElementAt(1)));
            this.GameSeven.Protocol.Assists.Add(new Assist(new MatchMinute(35), this.GameSeven.HomeTeamId,
                                                           DomainService.FindTeamById(this.GameSeven.HomeTeamId).PlayerIds.ElementAt(0)));
            this.GameSeven.Protocol.Cards.Add(new Card(new MatchMinute(75), this.GameSeven.HomeTeamId,
                                                       DomainService.FindTeamById(this.GameSeven.AwayTeamId).PlayerIds.ElementAt(0),
                                                       CardType.Red));

            this.GameNine.Protocol.Cards.Add(new Card(new MatchMinute(55), this.GameNine.HomeTeamId,
                                                      DomainService.FindTeamById(this.GameNine.HomeTeamId).PlayerIds.ElementAt(2),
                                                      CardType.Yellow));
            this.GameNine.Protocol.Cards.Add(new Card(new MatchMinute(67), this.GameNine.HomeTeamId,
                                                      DomainService.FindTeamById(this.GameNine.AwayTeamId).PlayerIds.ElementAt(1),
                                                      CardType.Yellow));
            this.GameNine.Protocol.Goals.Add(new Goal(new MatchMinute(87),
                                                      this.GameNine.Id,
                                                      DomainService.FindTeamById(this.GameNine.AwayTeamId).PlayerIds.ElementAt(2)));

            this.GameEleven.Protocol.Goals.Add(new Goal(new MatchMinute(35),
                                                        this.GameEleven.AwayTeamId,
                                                        DomainService.FindTeamById(this.GameEleven.AwayTeamId).PlayerIds.ElementAt(0)));
            this.GameEleven.Protocol.Goals.Add(new Goal(new MatchMinute(45),
                                                        this.GameEleven.AwayTeamId,
                                                        DomainService.FindTeamById(this.GameEleven.AwayTeamId).PlayerIds.ElementAt(0)));
            this.GameEleven.Protocol.Goals.Add(new Goal(new MatchMinute(55),
                                                        this.GameEleven.AwayTeamId,
                                                        DomainService.FindTeamById(this.GameEleven.AwayTeamId).PlayerIds.ElementAt(0)));
            this.GameEleven.Protocol.Goals.Add(new Goal(new MatchMinute(62),
                                                        this.GameEleven.HomeTeamId,
                                                        DomainService.FindTeamById(this.GameEleven.HomeTeamId).PlayerIds.ElementAt(0)));
            this.GameEleven.Protocol.Goals.Add(new Goal(new MatchMinute(88),
                                                        this.GameEleven.HomeTeamId,
                                                        DomainService.FindTeamById(this.GameEleven.HomeTeamId).PlayerIds.ElementAt(1)));

            var gameService = new GameService();

            gameService.Add(this.GameOne);
            gameService.Add(this.GameTwo);
            gameService.Add(this.GameThree);
            gameService.Add(this.GameFour);
            gameService.Add(this.GameFive);
            gameService.Add(this.GameSix);
            gameService.Add(this.GameSeven);
            gameService.Add(this.GameEight);
            gameService.Add(this.GameNine);
            gameService.Add(this.GameTen);
            gameService.Add(this.GameEleven);
            gameService.Add(this.GameTwelve);
        }
Ejemplo n.º 16
0
 private void 处理_S_返回服务数据(int p, byte[][] whisper)
 {
     _gameService.Add(p, whisper[2].ToObject <int[]>());
 }
 private void SaveGameProtocol(object obj)
 {
     gameService.Add(game);
     SaveOvertime();
     CloseDialog();
 }