Ejemplo n.º 1
0
        public async Task TestDeleteCharacter()
        {
            Mock <IRepository <Character> > mockRepository = new Mock <IRepository <Character> >();

            mockRepository.Setup(r => r.Delete(1)).ReturnsAsync(TestData.GetCharacters()[0]);
            mockRepository.Setup(r => r.Delete(5)).ReturnsAsync((Character)null);

            CharactersController        controller      = new CharactersController(mockRepository.Object);
            ActionResult <CharacterDTO> responseDeleted = await controller.DeleteCharacter(1);

            CharacterDTO character = responseDeleted.Value;
            ActionResult <CharacterDTO> responseNotFound = await controller.DeleteCharacter(5);

            Assert.IsTrue(TestData.GetCharacters()[0].IsDataEqual(new Character(character)));
            Assert.AreEqual(((StatusCodeResult)responseNotFound.Result).StatusCode, 404);
        }
Ejemplo n.º 2
0
        public void GivenAValidCharacter_RemovesCharacter()
        {
            // Arrange
            var character = new Character()
            {
                PlayerId = DefaultPlayer.Id
            };

            Context.Characters.Add(character);
            Context.SaveChanges();

            // Act
            var result = _controller.DeleteCharacter(character.Id);

            var foundCharacter = Context.Characters.Find(result.Value);

            // Assert
            foundCharacter.Should().BeNull();
        }
        public async Task DeleteCharacterTest()
        {
            // Arrange
            var repo       = new FakeCharacterRepository(TestData.Characters());
            var controller = new CharactersController(repo, null);
            var charId     = 1;

            // Act
            var result = await controller.DeleteCharacter(charId);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(charId, result.Value.Id);
        }
        public async Task DeleteCharacterNotFoundTest()
        {
            // Arrange
            var repo       = new FakeCharacterRepository(TestData.Characters());
            var controller = new CharactersController(repo, null);
            var charId     = 100;

            // Act
            var result = await controller.DeleteCharacter(charId);

            // Assert
            Assert.IsNotNull(result);
            var objResult = result.Result as NotFoundResult;

            Assert.IsNotNull(objResult);
        }
        public async Task TestDeleteSuccessfully()
        {
            using (var context = new PogGamesContext())
            {
                CharactersController charactersController = new CharactersController(context);

                ActionResult <IEnumerable <Character> > result1 = await charactersController.GetCharacter();

                ActionResult <Character> delete = await charactersController.DeleteCharacter("01");

                ActionResult <IEnumerable <Character> > result2 = await charactersController.GetCharacter();

                // Make sure that the characters list changed after delete
                Assert.AreNotEqual(result1, result2);
            }
        }