Esempio n. 1
0
        public void TestDeletePerson()
        {
            var personId = _db.Persons.FirstOrDefault().Id;
            var result   = _controller.DeletePerson(personId);

            ProcessResult(result);
        }
        public async void DeletePerson()
        {
            using (var context = new PersonContext(options)) {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
                var articles = new List <Person> {
                    new Person {
                        Id = 5, Name = "toDelete", DateAdded = DateTime.MinValue
                    },
                    new Person {
                        Id = 10, Name = "testName2", DateAdded = DateTime.MaxValue
                    }
                };
                context.People.AddRange(articles);
                context.SaveChanges();

                PersonController pc = new PersonController(context);
                await pc.DeletePerson(5);

                var people = await pc.GetPeople();

                var peopleArray = people.Value.ToArray();
                Assert.Single(peopleArray);
                Assert.Equal("testName2", peopleArray[0].Name);
                Assert.Equal(10, peopleArray[0].Id);
            }
        }
Esempio n. 3
0
        public void DeleteOk()
        {
            // Arrange
            PersonController controller = new PersonController();

            // Act
            var result = controller.DeletePerson(100);

            // Assert
            Assert.IsInstanceOfType(result, typeof(OkResult));
        }
Esempio n. 4
0
        public void DeletePersonTest()
        {
            var idToDelete         = SetupDbContext("DeleteTest").Id;
            var countAfterDeletion = Context.People.CountAsync().Result - 1;
            var personController   = new PersonController(Context);
            var result             = personController.DeletePerson(idToDelete);
            var okResult           = result.Result as OkObjectResult;

            Assert.IsNotNull(okResult, "Nothing was returned in the result");
            Assert.AreEqual(okResult.StatusCode, 200, "The Delete Failed");
            Assert.AreEqual(Context.People.CountAsync().Result, countAfterDeletion);
        }
Esempio n. 5
0
        public async Task DeleteShouldCallDeletePersonInBlOnce()
        {
            //Arrange
            var mock       = new Mock <IPersonWebService>();
            var controller = new PersonController(mock.Object);

            mock.Setup(x => x.Delete(1));

            //Act
            await controller.DeletePerson(1);

            //Assert
            mock.Verify(x => x.Delete(1), Times.Once);
        }
        public async Task WhenPersonAddedPersonIsReturned()
        {
            Person personToAdd = new Person
            {
                FirstName = "John",
                LastName  = "Doe"
            };
            long personCountBefore = await _personRepository.GetPersonCount();

            Person addedPerson      = GetValueFromOkObjectResult <Person>(await _personController.AddPerson(personToAdd) as OkObjectResult);
            long   personCountAfter = await _personRepository.GetPersonCount();

            Assert.IsTrue(--personCountAfter == personCountBefore);
            Assert.AreEqual(personToAdd.FirstName, addedPerson.FirstName);
            Assert.AreEqual(personToAdd.LastName, addedPerson.LastName);

            await _personController.DeletePerson(personToAdd.Id);
        }