public void GetContact_ShouldReturnNotFound()
        {
            var context = new TestSampleAppContext();

            context.Contacts.Add(GetDemoContact());

            var controller = new ContactController(context);
            var result     = controller.GetContact(10);

            Assert.IsNotNull(result);
            Assert.IsInstanceOf(typeof(NotFoundResult), result);
        }
        public void GetContact_ShouldReturnContactWithSameID()
        {
            var context = new TestSampleAppContext();

            context.Contacts.Add(GetDemoContact());

            var controller = new ContactController(context);
            var result     = controller.GetContact(3) as OkNegotiatedContentResult <Contact>;

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Content.Id);
        }
        public void DeleteContact_ShouldReturnOK()
        {
            var context = new TestSampleAppContext();
            var item    = GetDemoContact();

            context.Contacts.Add(item);

            var controller = new ContactController(context);
            var result     = controller.DeleteContact(3) as OkNegotiatedContentResult <Contact>;

            Assert.IsNotNull(result);
            Assert.AreEqual(item.Id, result.Content.Id);
        }
Пример #4
0
        public void DeleteContact_ShouldReturnNotFound()
        {
            var context = new TestSampleAppContext();
            var item    = GetDemoContact();

            context.Contacts.Add(item);

            var controller = new ContactController(context);
            var result     = controller.DeleteContact(10);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }
        public void GetContacts_ShouldReturnAllContacts()
        {
            var context = new TestSampleAppContext();

            context.Contacts.Add(new Contact {
                Id = 1, FirstName = "Demo1", LastName = "Demo1", Email = "*****@*****.**", Mobile = "+972599142563", Age = 30
            });
            context.Contacts.Add(new Contact {
                Id = 2, FirstName = "Demo2", LastName = "Demo2", Email = "*****@*****.**", Mobile = "+972599142564", Age = 30
            });
            context.Contacts.Add(new Contact {
                Id = 3, FirstName = "Demo3", LastName = "Demo3", Email = "*****@*****.**", Mobile = "+972599142565", Age = 30
            });

            var controller = new ContactController(context);
            var result     = controller.GetContacts() as TestContactDbSet;

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Local.Count);
        }