Пример #1
0
        // GET: Advertisements/Details/5
        public IActionResult Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var advertisement = advertService.GetAdvertisement((int)id);

            if (advertisement == null)
            {
                return(NotFound());
            }

            return(View(advertisement));
        }
Пример #2
0
        public async Task <IActionResult> GetAdvertisementDetails([FromRoute] int id)
        {
            var advertisement = await AdvertisementService.GetAdvertisement(id);

            if (advertisement == null)
            {
                return(NotFound());
            }

            return(Ok(advertisement));
        }
        public void AdvertisementWithInvalidId_WhenRetrieved_ThrowsExeption()
        {
            context.Advertisements.Add(new Advertisement {
                Name = "Advertisement"
            });
            context.SaveChanges();
            var service = new AdvertisementService(context);

            var ex = Assert.Throws <ArgumentException>(() => service.GetAdvertisement(2));

            Assert.That(ex.Message, Is.EqualTo("Invalid advertisement id. (Parameter 'id')"));
        }
        public void Advertisement_CanBeRetrieved()
        {
            context.Advertisements.Add(new Advertisement {
                Name = "Advertisement1", Description = "An advertisement for a job.", Active = true, JobPositionId = this.jobPositionId
            });
            context.SaveChanges();
            var service = new AdvertisementService(context);

            var advertisement = service.GetAdvertisement(1);

            Assert.AreEqual(1, advertisement.Id);
            Assert.AreEqual("Advertisement1", advertisement.Name);
        }