public void Constructor_should_load_given_entity_data()
        {
            Dinner dinner = new Dinner
            {
                Id = 1,
                Address = "testaddress",
                ContactPhone = "testphone",
                Country = "testcountry",
                Description = "testdescription",
                EventDate = DateTime.Today.AddDays(-10),
                HostedBy = "someone",
                Latitude = 42,
                Longitude = 42,
                Title = "testtitle"
            };

            DinnerViewModel model = new DinnerViewModel(dinner);

            Assert.AreEqual(dinner.Id, model.Id);
            Assert.AreEqual(dinner.Title, model.Title);
            Assert.AreEqual(dinner.Address, model.Address);
            Assert.AreEqual(dinner.ContactPhone, model.ContactPhone);
            Assert.AreEqual(dinner.Country, model.Country);
            Assert.AreEqual(dinner.Description, model.Description);
            Assert.AreEqual(dinner.EventDate, model.EventDate);
            Assert.AreEqual(dinner.HostedBy, model.HostedBy);
            Assert.AreEqual(dinner.Latitude, model.Latitude);
            Assert.AreEqual(dinner.Longitude, model.Longitude);
        }
Пример #2
0
        public ActionResult View(int id)
        {
            var dinner = _context.Dinners.Find(id);
            var vm     = new DinnerViewModel
            {
                Data = Mapper.Map <DinnerEditModel>(dinner),
                //We can use the service directly in our controlller code to check that a user will be able to perform actions that we want to link to on the view page
                //We can actually pass in the id of the current dinner via the lambda expression. This will be passed into the constructor of the "EditDinner" class so that the id is then available to the authorizer
                CanEdit   = _service.Authorize <DinnerController>(c => c.Edit(dinner.Id), User),
                CanDelete = _service.Authorize <DinnerController>(c => c.Delete(dinner.Id), User)
            };

            return(View(vm));
        }
        public void Constructor_should_initialize_all_properties()
        {
            DinnerViewModel model = new DinnerViewModel(null);

            Assert.IsEmpty(model.Title);
            Assert.IsEmpty(model.Description);
            Assert.AreEqual(DateTime.Today, model.EventDate);
            Assert.IsEmpty(model.HostedBy);
            Assert.IsEmpty(model.ContactPhone);
            Assert.IsEmpty(model.Address);
            Assert.IsEmpty(model.Country);
            Assert.AreEqual(0, model.Longitude);
            Assert.AreEqual(0, model.Latitude);
        }