コード例 #1
0
        public void Delete(int id)
        {
            //Arrange
            var result = Builder <Person>
                         .CreateNew()
                         .Build();

            var personDTO = Builder <PersonDTO>
                            .CreateNew()
                            .Build();

            _personService
            .Setup(o => o.GetFirstAsync(It.IsAny <int>()))
            .ReturnsAsync(result);
            _personService
            .Setup(o => o.DeleteAsync(It.IsAny <Person>()))
            .ReturnsAsync(result);

            _mapper
            .Setup(o => o.Map <PersonDTO>(It.IsAny <Person>()))
            .Returns(personDTO);

            //Act
            var response  = _controller.Delete(id).Result;
            var resultDto = (response.Result as AcceptedAtActionResult).Value as PersonDTO;

            //Assert
            Assert.NotNull(resultDto);
            Assert.IsType <PersonDTO>(resultDto);
        }
コード例 #2
0
        public void Delete_WhenCalled_GeneratesNotFoundResponse()
        {
            //Arrange
            int          Id     = 2;
            ActionResult result = _testPersonController.Delete(Id);

            Assert.IsType <NotFoundResult>(result);
        }
コード例 #3
0
        public void Delete_NotFound()
        {
            service.Setup(x => x.Delete(It.IsAny <int>())).Returns(false);

            var response = controller.Delete(1);

            Assert.IsInstanceOf(typeof(NotFoundResult), response);
        }
コード例 #4
0
        public void Delete_Ok()
        {
            var result = _controller.Delete(1);

            Assert.IsInstanceOf <OkObjectResult>(result.Result);

            var value = (result.Result as OkObjectResult).Value as Person;

            Assert.AreEqual(1, value.Id);
            Assert.AreEqual("Gandelf", value.Name);
            Assert.AreEqual("Hogwarts", value.Nationality);
        }
コード例 #5
0
        public void InsertUpdateDelete()
        {
            PersonController personController = new PersonController();

            //create new entity
            Person person = new Person();

            person.personId       = Guid.NewGuid();
            person.name           = "Test Name";
            person.dateOfBirth    = DateTime.Now;
            person.entryDate      = DateTime.Now;
            person.appUserId      = Guid.NewGuid();
            person.modifiedDate   = DateTime.Now;
            person.remark         = "Test Remark";
            person.homeCityId     = null;
            person.nativeCityId   = null;
            person.homeTownshipId = null;

            //insert
            var result1 = personController.Post(person);
            //update
            var result2 = personController.Post(person);
            //delete
            var result3 = personController.Delete(person.personId);

            //assert
            Assert.IsNotNull(result1);
            Assert.IsNotNull(result2);
            Assert.IsNotNull(result3);
            Assert.IsTrue(result1 is OkResult);
            Assert.IsTrue(result2 is OkResult);
            Assert.IsTrue(result3 is OkResult);
        }
コード例 #6
0
        public void DeletePerson()
        {
            // ARRANGE
            ApplicationConfiguration appApplicationConfiguration = new ApplicationConfiguration();
            PersonRepository         personRepository            = new PersonRepository(_session);
            DeviceRepository         deviceRepository            = new DeviceRepository(_session);
            SessionRepository        sessionRepository           = new SessionRepository(_session);
            ScheduledEmailRepository scheduledEmailRepository    = new ScheduledEmailRepository(_session);
            EmailNotificationService emailNotificationService    = new EmailNotificationService(appApplicationConfiguration);
            ScheduledEmailService    scheduledEmailService       = new ScheduledEmailService(scheduledEmailRepository, emailNotificationService, personRepository);
            PersonService            personService = new PersonService(personRepository, deviceRepository, sessionRepository, emailNotificationService, scheduledEmailService, appApplicationConfiguration, scheduledEmailRepository);

            SessionService   apiSessionService = new SessionService(sessionRepository);
            PersonController personController  = new PersonController(apiSessionService, personService)
            {
                Configuration = new HttpConfiguration(),
                Request       = new HttpRequestMessage()
            };

            personController.Request.Headers.Add("XClientId", Guid.NewGuid().ToString());
            personController.Request.RequestUri = new Uri("http://localhost?xerxes=1");             // Authentication shortcut

            // ACT
            personController.Delete(20000);

            // ASSERT
            var personModel = personController.GetPersonById(20000);

            Assert.IsNull(personModel);
        }
コード例 #7
0
        public void GetPerson_ShouldNotFindPerson()
        {
            var controller = new PersonController();

            var result = controller.Delete(999);

            Assert.IsInstanceOfType(result, typeof(NotFoundObjectResult));
        }
コード例 #8
0
        public void Remove_IdIsNull_ReturnsBadRequest()
        {
            // Act
            var okResponse = _controller.Delete(null);

            // Assert
            Assert.IsType <BadRequestObjectResult>(okResponse);
        }
コード例 #9
0
        public void TestDelete()
        {
            _controller.Delete(1);

            var result = _controller.Get("John").Result;
            var value  = (result as OkObjectResult).Value as IEnumerable <Person>;

            Assert.AreEqual(value.Count(), 0);
        }
コード例 #10
0
        public void DeleteShouldReturnJsonResult()
        {
            var controller = new PersonController(_context.Object, _badgeRepo.Object,
                                                  _personRepo.Object, _recognitionRepo.Object);

            _personRepo.Setup(x => x.Delete(2)).Returns(true);
            var result = controller.Delete(2);

            Assert.IsInstanceOfType(result, typeof(JsonResult));
        }
コード例 #11
0
        public void DeletePostAction_DeleteModel()
        {
            var person     = new PersonDTO();
            var mock       = new Mock <IService>();
            var controller = new PersonController(mock.Object);

            var result = controller.Delete(person.Id) as RedirectToRouteResult;

            mock.Verify(a => a.DeletePerson(person.Id));
        }
コード例 #12
0
        public void Delete()
        {
            // Arrange
            PersonController controller = new PersonController();

            controller.Delete(18);
            Person per = controller.Get(18);

            Assert.AreEqual(null, per);
        }
コード例 #13
0
        public void ShouldDeletePerson()
        {
            // arrange
            int PersonId = 1;

            //act
            var result = PersonController.Delete(PersonId);

            // assert
            Assert.IsNotNull(result);
        }
コード例 #14
0
        internal static IHttpActionResult Delete()
        {
            CustomerImplementaion.Delete();
            UserImplementaion.Delete();

            var _persons  = GetAll() as OkNegotiatedContentResult <IEnumerable <Person> >;
            var personIDs = _persons.Content.Select(t => t.ID).ToList();
            var response  = baseController.Delete(personIDs);

            return(response);
        }
コード例 #15
0
        public void PersonController_Delete()
        {
            // Arrange
            PersonController controller = new PersonController();

            // Act
            // this person does not exist - will redirect to error page
            var result = (RedirectToRouteResult)controller.Delete(0);

            // Assert
            Assert.IsTrue(result.RouteValues["action"].ToString() == "FatalError");
        }
コード例 #16
0
        public async Task DeleteShouldReturnViewResult()
        {
            // Arrange
            int id         = 1;
            var mock       = new Mock <IPersonWebService>();
            var controller = new PersonController(mock.Object);

            // Act
            var result = await controller.Delete(id);

            // Assert
            Assert.That(result, Is.TypeOf <ViewResult>());
        }
コード例 #17
0
        public void TestDeletePersonNotFound()
        {
            var logger     = Mock.Of <ILogger <PersonController> >();
            var dbContext  = DbContextMocker.GetPersonContext(nameof(TestDeletePersonNotFound));
            var controller = new PersonController(dbContext, logger);

            var response = controller.Delete(10);
            var value    = response.StatusCode;

            dbContext.Dispose();

            Assert.True(value == StatusCodes.Status404NotFound);
        }
コード例 #18
0
        public void DeletePersonTest()
        {
            DirectoryContext _directoryContext = new DirectoryContext();
            ProducerConfig   _config           = new ProducerConfig();
            PersonController personController  = new PersonController(_config, _directoryContext);
            PersonDeleteVM   model             = new PersonDeleteVM();

            var data = personController.Delete(model);


            Assert.IsNotNull(model);
            Assert.IsNotNull(data);
        }
コード例 #19
0
        public async Task Delete_ValidIdNoMatchingPerson_ReturnsNotFound()
        {
            Mock <IPersonRepository> repository = new Mock <IPersonRepository>();

            repository.Setup(r => r.GetAsync(It.IsAny <int>())).Returns(Task.FromResult((Person)null));

            PersonController controller = new PersonController(repository.Object);

            //Act
            IActionResult result = await controller.Delete(0);

            //Assert
            Assert.IsType <NotFoundResult>(result);
        }
コード例 #20
0
        public async Task delete_post_returns_JSON()
        {
            //Arrange

            //Act
            var result = await _controller.Delete(_testid, "UnitTest") as JsonResult;

            //Assert
            Assert.IsNotNull(result);
            IDictionary <string, object> data = new RouteValueDictionary(result.Value);

            Assert.AreEqual("OK", data["status"]);
            Assert.AreEqual(4242, data["deletedID"]);
        }
コード例 #21
0
        public void TestDeleteHttpMoq()
        {
            Person person = new Person();

            person.imie     = "Basia";
            person.nazwisko = "Kowalska";
            Mock <IPersonSharingContext> context = new Mock <IPersonSharingContext>();

            context.Setup(x => x.FindPersonById(2)).Returns(person);
            var controller = new PersonController(context.Object);

            var result = controller.Delete(25);

            Assert.AreEqual(typeof(HttpNotFoundResult), result.GetType());
        }
コード例 #22
0
        public void TestDeletePersonIsNotNullMoq()
        {
            Person person = new Person();

            person.imie     = "Basia";
            person.nazwisko = "Kowalska";
            Mock <IPersonSharingContext> context = new Mock <IPersonSharingContext>();

            context.Setup(x => x.FindPersonById(2)).Returns(person);
            var controller = new PersonController(context.Object);

            var result = controller.Delete(2) as ViewResult;

            Assert.IsNotNull(result);
        }
コード例 #23
0
        public void DeleteReturnsOk()
        {
            // Arrange
            var mockRepository = new Mock <IPersonRepository>();
            var controller     = new PersonController(mockRepository.Object);

            mockRepository.Setup(x => x.Exists(It.IsAny <int>()))
            .Returns(true);

            // Act
            IHttpActionResult actionResult = controller.Delete(10);

            // Assert
            Assert.IsInstanceOfType(actionResult, typeof(OkResult));
        }
コード例 #24
0
        public void DeleteCasetExist()
        {
            int id   = 1;
            var mock = new Mock <IPersonService>(MockBehavior.Strict);

            mock.Setup(service => service.Remove(id));
            var controller = new PersonController(mock.Object);

            var result     = controller.Delete(id);
            var okResult   = result as ObjectResult;
            var statusCode = okResult.StatusCode;

            mock.VerifyAll();
            Assert.AreEqual(statusCode, 200);
        }
コード例 #25
0
        public async Task Delete_ValidIdMatchingPersonInRepository_ReturnsOk()
        {
            Person person = PersonGenerator.Generate();

            Mock <IPersonRepository> repository = new Mock <IPersonRepository>();

            repository.Setup(r => r.RemoveAsync(It.IsAny <int>())).Returns(Task.FromResult(person));

            PersonController controller = new PersonController(repository.Object);

            //Act
            IActionResult result = await controller.Delete(0);

            //Assert
            Assert.IsType <OkResult>(result);
        }
コード例 #26
0
        public void TestDeleteViewMoq()
        {
            Person person = new Person();

            person.imie     = "Basia";
            person.nazwisko = "Kowalska";
            Mock <IPersonSharingContext> context = new Mock <IPersonSharingContext>();

            context.Setup(x => x.FindPersonById(2)).Returns(person);
            var controller = new PersonController(context.Object);

            var result       = controller.Delete(2) as ViewResult;
            var resultPerson = (Person)result.Model;

            Assert.AreEqual("Basia", resultPerson.imie);
        }
コード例 #27
0
        public void DeleteCaseNotExist()
        {
            int id   = 2;
            var mock = new Mock <IPersonService>(MockBehavior.Strict);

            mock.Setup(service => service.Remove(id)).Throws(new KeyNotFoundException());
            var controller = new PersonController(mock.Object);

            var result     = controller.Delete(id);
            var okResult   = result as ObjectResult;
            var statusCode = okResult.StatusCode;
            var value      = okResult.Value;

            mock.VerifyAll();
            Assert.AreEqual(statusCode, 404);
        }
コード例 #28
0
        public async void DeleteTest()
        {
            var optionsBuilder = new DbContextOptionsBuilder <HallOfFameContext>()
                                 .UseInMemoryDatabase("userdbstore");

            using (var context = new HallOfFameContext(optionsBuilder.Options))
            {
                PersonController controller = new PersonController(context);
                int contextCount            = await context.Person.CountAsync();

                int id = 1;
                controller.Delete(id);
                var result = controller.Get(id);

                Assert.IsType <NotFoundResult>(result);
            }
        }
コード例 #29
0
        public void DeleteInvalidItemFromControllerReturnsNotFound()
        {
            // Arrange
            var mockRepository = new Mock <IPersonRepository>();

            mockRepository.Setup(x => x.Exists(2))
            .Returns(false);
            var controller = new PersonController(mockRepository.Object);

            // Act
            var actionResult   = controller.Delete(2);
            var negativeResult = actionResult as NegotiatedContentResult <string>;

            // Assert
            Assert.IsNotNull(negativeResult);
            Assert.AreEqual("Person 2 not found.", negativeResult.Content);
            Assert.AreEqual(HttpStatusCode.NotFound, negativeResult.StatusCode);
        }
コード例 #30
0
        public async Task DeleteShouldDeleteTest()
        {
            var service = new Mock <IPersonService>();
            var newId   = Guid.NewGuid();

            service
            .Setup(x => x.Delete(newId))
            .Returns(Task.CompletedTask);
            var controller    = new PersonController(service.Object);
            var resultRequest = await controller.Delete(newId);

            var data          = Assert.IsType <OkObjectResult>(resultRequest.Result);
            var crudOperation = Assert.IsType <CrudOperationDto>(data.Value);

            Assert.Equal(newId, crudOperation.Id);
            Assert.True(crudOperation.Success);
            service.Verify(x => x.Delete(newId), Times.Once);
        }