public async Task AddNewShouldThrowArgumentNullExceptionIfNotGivenAddInput()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase("test");
            var db = new ApplicationDbContext(options.Options);

            var service = new NewsService(db);

            await Assert.ThrowsAsync <ArgumentNullException>(() => service.AddNew(null, "userId"));
        }
        public async Task AddNewShouldThrowArgumentNullExceptionIfGivenInvalidUserId()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase("test");
            var db = new ApplicationDbContext(options.Options);

            var service = new NewsService(db);

            var testNewTitle   = "Test";
            var testNewContent = "TestContentTestContentTestContent";
            var testNewImage   = "https://p.bigstockphoto.com/GeFvQkBbSLaMdpKXF1Zv_bigstock-Aerial-View-Of-Blue-Lakes-And--227291596.jpg";

            var addNewInput = new NewAddInputModel()
            {
                Title   = testNewTitle,
                Content = testNewContent,
                Image   = testNewImage,
            };

            await Assert.ThrowsAsync <ArgumentNullException>(() => service.AddNew(addNewInput, "fake_user_id"));
        }
        public async Task AddNewShouldAddNewWithGivenValidNewAddInputModelAndUserId()
        {
            var user = new ApplicationUser()
            {
                Email        = "*****@*****.**",
                PasswordHash = "4297F44B13955235245B2497399D7A93",
            };

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase("testadd");
            var db = new ApplicationDbContext(options.Options);

            await db.Users.AddAsync(user);

            await db.SaveChangesAsync();

            var service = new NewsService(db);

            var testNewTitle   = "Test";
            var testNewContent = "TestContentTestContentTestContent";
            var testNewImage   = "https://p.bigstockphoto.com/GeFvQkBbSLaMdpKXF1Zv_bigstock-Aerial-View-Of-Blue-Lakes-And--227291596.jpg";

            var addNewInput = new NewAddInputModel()
            {
                Title   = testNewTitle,
                Content = testNewContent,
                Image   = testNewImage,
            };

            int newsCountBeforeAdd = db.News.Count();

            await service.AddNew(addNewInput, user.Id);

            var addedNew = db.News.First();

            Assert.Equal(newsCountBeforeAdd + 1, db.News.Count());
            Assert.Equal(addNewInput.Title, addedNew.Title);
            Assert.Equal(addNewInput.Content, addedNew.Content);
            Assert.Equal(addNewInput.Image, addedNew.Image);
        }
Beispiel #4
0
 public static News AddNew(News news)
 {
     return(NewsService.AddNew(news));
 }