Beispiel #1
0
        public async Task CreateAdTests()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Create_Ad")
                          .Options;

            IEnumerable <string> imgP = new List <string> {
                "aaaaa", "bbbbbb"
            };
            var user = new AgencyProfile {
                Id = "agencyId", Username = "******"
            };

            int count;

            using (var db = new ApplicationDbContext(options))
            {
                db.AgenciesProfiles.Add(user);
                db.SaveChanges();
                AdService service = new AdService(db);

                await service.CreateAd("Name", "Titleeeeeeeeeeeeee", "Description", imgP, "Residental",
                                       "65", "Location", "20", "A");

                count = db.Ads.Count();
            }

            Assert.Equal(1, count);
        }
Beispiel #2
0
        public async Task <ActionResult <CreateAdDTO> > PostAd(CreateAdDTO adDTO)
        {
            if (adDTO == null || adDTO.Body == null || adDTO.Email == null || adDTO.Subject == null)
            {
                throw new HttpResponseException {
                          Status = 400,
                          Value  = "Missing Body, Email or Subject in Ad"
                };
            }

            var ad = await adService.CreateAd(adDTO.Subject, adDTO.Body, adDTO.Email, adDTO.Price);

            return(CreatedAtAction(nameof(GetAd), new { id = ad.Id }, ad));
        }