Update() private method

private Update ( ) : void
return void
コード例 #1
0
        public void UpdateModelTrueJsonResult()
        {
            // Arrange
            var  mockRepository = new Mock <IGenericRepository <Item> >();
            Item OldItem        = new Item()
            {
                Category = "test",
                Code     = "11-1111-QQ66",
                Name     = "TestName",
                Price    = 9,
                Id       = Guid.NewGuid()
            };
            Item NewItem = new Item()
            {
                Category = "testNew",
                Code     = "22-2222-QQ66",
                Name     = "TestNameNew",
                Price    = 2,
                Id       = OldItem.Id
            };

            mockRepository.Setup(a => a.GetByID(OldItem.Id)).Returns(OldItem);
            var mock = new Mock <IUnitOfWork>();

            mock.Setup(a => a.GetItems).Returns(mockRepository.Object);
            mock.Setup(a => a.Save());
            ItemController controller = new ItemController(mock.Object);

            string expected = Json.Encode(new
            {
                Data    = NewItem,
                success = true
            }
                                          );
            // Act
            JsonResult result     = controller.Update(NewItem);
            var        serializer = new JavaScriptSerializer();


            string serialize = serializer.Serialize(result.Data);
            string actual    = new JavaScriptSerializer().Serialize(result.Data);


            // Assert
            Assert.AreEqual(expected, actual);
        }
コード例 #2
0
        public void UpdateModelSaveException()
        {
            // Arrange
            Exception ex = new Exception("Test Message");

            var  mockRepository = new Mock <IGenericRepository <Item> >();
            Item OldItem        = new Item()
            {
                Category = "test",
                Code     = "11-1111-QQ66",
                Name     = "TestName",
                Price    = 9,
                Id       = Guid.NewGuid()
            };
            Item NewItem = new Item()
            {
                Category = "testNew",
                Code     = "22-2222-QQ66",
                Name     = "TestNameNew",
                Price    = 2,
                Id       = OldItem.Id
            };

            mockRepository.Setup(a => a.GetByID(OldItem.Id)).Returns(OldItem);
            var mock = new Mock <IUnitOfWork>();

            mock.Setup(a => a.GetItems).Returns(mockRepository.Object);
            mock.Setup(a => a.Save()).Throws(ex);
            ItemController controller = new ItemController(mock.Object);

            string expected = "{\"Msg\":\"" + ex.Message + "\",\"success\":false}";
            // Act
            JsonResult result     = controller.Update(NewItem);
            var        serializer = new JavaScriptSerializer();


            string serialize = serializer.Serialize(result.Data);
            string actual    = new JavaScriptSerializer().Serialize(result.Data);


            // Assert
            Assert.AreEqual(expected, actual);
        }
コード例 #3
0
ファイル: LevelScreen.cs プロジェクト: CodeEdelmann/HideOut
        public override void Update(GameTime gameTime)
        {
            bool hasMusicChanged = false;

            /*
             * musicLoopCounter = musicLoopCounter - gameTime.ElapsedGameTime.Milliseconds;
             * if (musicLoopCounter < 0)
             * {
             *  mainMusic.Resume();
             * }
             */

            /*
             * if (musicLoopCounter < 0)
             * {
             *  gameSound.Dispose();
             *  gameSound.Play();
             *  musicLoopCounter = 2000;// gameSound.Duration.Milliseconds;
             * }
             * else
             * {
             *  musicLoopCounter = musicLoopCounter - gameTime.ElapsedGameTime.Milliseconds;
             * }
             */
            if (HideOutGame.LEVEL_DESIGN_MODE)
            {
                playerController.Update(gameTime, mobile);
                entityGenerationController.Update(gameTime);
                xmlController.Update();
                return;
            }
            pauseState = Keyboard.GetState();
            if (isPaused)
            {
                if (((pauseState.IsKeyDown(Keys.Left) && !oldState.IsKeyDown(Keys.Left)) ||
                     (pauseState.IsKeyDown(Keys.Right) && !oldState.IsKeyDown(Keys.Right)) ||
                     (pauseState.IsKeyDown(Keys.Up) && !oldState.IsKeyDown(Keys.Up)) ||
                     (pauseState.IsKeyDown(Keys.Down) && !oldState.IsKeyDown(Keys.Down))) && !displayController.hasLost && !displayController.hasWon)
                {
                    isPaused = false;
                    displayController.displayLevel = false;
                }
                else if (pauseState.IsKeyDown(Keys.Enter))
                {
                    if (displayController.hasLost == true)
                    {
                        isPaused = false;
                        displayController.displayLevel = false;
                        displayController.hasLost      = false;
                        displayController.hasWon       = false;
                        HideOutGame.LEVEL_INITIALIZED  = false;
                        Type = "TitleScreen";

                        //gameSoundOn = true;
                        //gameSound.Dispose();
                        //gameSound.Play();

                        return;
                    }
                    else if (displayController.hasWon == true)
                    {
                        isPaused = false;
                        displayController.displayLevel = false;
                        displayController.hasLost      = false;
                        displayController.hasWon       = false;
                        HideOutGame.LEVEL_INITIALIZED  = false;
                        EndScreen.oldState             = pauseState;
                        Type = "EndScreen";
                    }
                }
                else
                {
                    oldState = pauseState;
                    return;
                }
            }
            oldState = pauseState;


            //musicLoopCounter -= gameTime.ElapsedGameTime.Milliseconds;
            //musicLoopCounter = musicLoopCounter - gameTime.ElapsedGameTime.Milliseconds;
            if (gameSoundOn && ((musicLoopCounter == 0) || (gameSound.IsDisposed)))
            {
                gameSound.Dispose();
                //gameSound.Play();
                musicLoopCounter = 2000;    // +gameSound.Duration.Milliseconds;
            }
            //Console.WriteLine("Time: " + gameTime.ElapsedGameTime.TotalMilliseconds);

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                // TODO: quit game
            }

            // TODO: Add your update logic here
            if (npcController.Update(playerController.thePlayer, obstacleController.obstacles, gameTime) && !CHEAT_MODE)
            {
                isPaused = true;
                //TODO: show losing screen
                Console.WriteLine("You lose!  Good day!");
                // gameSound.Dispose
                //failureSound.Player();
                //gameSoundOn = false;
                //gameSound.Dispose();
                //failureSound.Play();
                //musicLoopCounter = failureSound.Duration.Milliseconds;
                //Console.WriteLine("Duration: " + failureSound.Duration.Milliseconds

                musicSelection  = 1;
                hasMusicChanged = true;
                //mainMusic.Pause();
                //failureSound.Play();
                //musicLoopCounter = failureSound.Duration.Milliseconds;

                //failureSound.Duration
                displayController.hasLost = true;//Exit();
            }

            displayController.level = levelController.currentLevel;
            switch (levelController.Update())
            {
            case 0:
                //isPaused = true;
                displayController.displayLevel = true;

                /*
                 * if (pauseState.IsKeyDown(Keys.Enter))
                 * {
                 *  isPaused = false;
                 * }
                 * else
                 * {
                 *  isPaused = true;
                 * } */
                break;

            case 1:
                isPaused = true;
                displayController.displayLevel = true;
                displayController.level        = levelController.currentLevel;
                break;

            case 2:
                isPaused = true;
                //TODO: show winning screen
                gameSoundOn = false;
                Console.WriteLine("You win!  Good day!");
                //mainMusic.Pause();
                //victorySound.Play();
                musicSelection = 2;
                //musicLoopCounter = victorySound.Duration.Milliseconds;
                //musicLoopCounter = victorySound.Duration.Milliseconds;


                try
                {
                    File.Delete("Content\\Levels\\savestate.txt");
                }
                catch { }
                displayController.hasWon = true;    // GetHashCode//Exit();
                break;
            }

            if (playerController.Update(gameTime, mobile))
            {
                isPaused    = true;
                gameSoundOn = false;
                Console.WriteLine("You lose!  Good day!");
                //gameSound.Dispose();
                //failureSound.Play();
                musicSelection  = 1;
                hasMusicChanged = true;
                //mainMusic.Pause();
                //failureSound.Play();
                //musicLoopCounter = failureSound.Duration.Milliseconds;


                displayController.hasLost = true;
            }

            if (!hasMusicChanged)
            {
                musicSelection = 0;
            }

            itemController.Update(gameTime);
            obstacleController.Update(gameTime);
            displayController.Update(gameTime);
            xmlController.Update();
        }