Esempio n. 1
0
        public void DeleteReturnsPhone()
        {
            //Arrange
            moq.Setup(m => m.Delete(It.IsAny <object[]>())).Returns(Task.FromResult(new Phone()));

            //Act
            var result = (controller.Delete(0).Result as OkObjectResult)?.Value;

            //Assert
            Assert.IsInstanceOfType(result, typeof(Phone));
        }
Esempio n. 2
0
        public async Task TestDelete()
        {
            var options = new DbContextOptionsBuilder <MobileContext>()
                          .UseInMemoryDatabase(databaseName: "phonesdb")
                          .Options;

            using (var context = new MobileContext(options))
            {
                int beforeCount = context.Phones.Count();
                var phones      = new Phone
                {
                    Name    = "IPhone 14",
                    Company = "Apple",
                    Price   = 20
                };
                _phonesController = new PhonesController(context, _ihost);
                var result = await _phonesController.Delete(phones);

                var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);
                Assert.Equal("Index", redirectToActionResult.ActionName);
                Assert.Equal(beforeCount - 1, context.Phones.Count());
            }
        }