예제 #1
0
        public void GetAll_ReturnsCorrectCollection()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            using (var dbContext = new ApplicationDbContext(options))
            {
                Phone phone1 = new Phone()
                {
                    PhoneNumber = "0897248721"
                };
                Phone phone2 = new Phone()
                {
                    PhoneNumber = "0897248722"
                };

                dbContext.Phones.Add(phone1);
                dbContext.Phones.Add(phone2);
                dbContext.SaveChanges();

                var phonesService = new PhonesService(dbContext);
                var phones        = phonesService.GetAll();

                Assert.Collection(phones, item => Assert.Contains("0897248721", phone1.PhoneNumber),
                                  item => Assert.Contains("0897248722", phone2.PhoneNumber));
            }
        }
예제 #2
0
        public ActionResult List()
        {
            PhonesService phonesService = new PhonesService();
            PhonesListVM  model         = new PhonesListVM();

            TryUpdateModel(model);

            if (!model.ContactID.HasValue || phonesService.GetContact(model.ContactID.Value) == null)
            {
                return(this.RedirectToAction <ContactsController>(c => c.List()));
            }

            model.Phones  = phonesService.GetAll().Where(p => p.ContactID == model.ContactID.Value).ToList();
            model.Contact = phonesService.GetContact(model.ContactID.Value);

            return(View(model));
        }