Esempio n. 1
0
        public async Task OnPostAsync_ShouldAddPostToContext()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <WallContext>()
                          .UseInMemoryDatabase(databaseName: "IndexWallDataBase")
                          .Options;

            using (var context = new WallContext(options))
            {
                var post = new Post()
                {
                    Body = "Test post"
                };
                string personName = "Post Test Name";
                //Act
                HomeController homeController = new HomeController(context);

                /*indexModel.PersonName = personName;
                 * indexModel.Post = post;
                 * await indexModel.OnPostAsync();*/

                //Assert
                Assert.Equal(personName, context.People.Where(p => p.Name == personName).FirstOrDefault().Name);
                Assert.Equal(post, context.People.Where(p => p.Name == personName).FirstOrDefault().Posts[0]);
                Assert.Equal(post, context.Posts.Where(p => p.Id == post.Id).FirstOrDefault());
            }
        }
Esempio n. 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, WallContext wallContext)
        {
            wallContext.Database.Migrate();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            app.UseMvcWithDefaultRoute();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
            });
        }
Esempio n. 3
0
        //private ILogger _logger;


        public RetainingWallsController(WallContext context, IMapper mapper, IWallRepository repo)
        {
            _context = context;
            _repo    = repo;
            _mapper  = mapper;
            //_logger = logger;
        }
 // GET: Home
 public ActionResult Index()
 {
     using (var context = new WallContext())
     {
         var comments = context.Comments.ToList();
         ViewBag.Comments = comments;
     }
     return(View());
 }
        // GET: Home
        public ActionResult Index()
        {
            using (var context = new WallContext())
            {
                var posts = context.Posts.ToList();

                // 2 способ
                ViewData["Posts"] = posts;
            }
            return(View());
        }
Esempio n. 6
0
        public WallController(WallContext wallContext)
        {
            context = wallContext;

            if (context.WallItems.Count() == 0)
            {
                context.WallItems.Add(new Item {
                    Name = "first item"
                });
                context.SaveChanges();
            }
        }
        public ActionResult Index(string user, string text)
        {
            using (var context = new WallContext())
            {
                context.Comments.Add(new Models.Comment()
                {
                    Text = text, User = user
                });
                context.SaveChanges();
                ViewBag.Comments = context.Comments.ToList();
            }

            return(Json(new { user, text }));
        }
Esempio n. 8
0
        public async Task OnPostAsync_ShouldAddCommentToContext()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <WallContext>()
                          .UseInMemoryDatabase(databaseName: "CommentWallDataBase")
                          .Options;

            using (var context = new WallContext(options))
            {
                var post = new Post()
                {
                    Body = "Test post"
                };
                var reply = new Comment()
                {
                    Body = "Test comment"
                };
                context.Posts.Add(post);
                context.SaveChanges();
                string repliersName = "Mr Test";
                //Act
                CommentController commentController = new CommentController(context);

                /*commentController.RepliersName = repliersName;
                 * commentModel.Post = post;
                 * commentModel.Reply = reply;
                 * await commentModel.OnPostAsync(1);*/

                //Assert
                Assert.Equal(repliersName, context.People.Where(p => p.Name == repliersName).FirstOrDefault().Name);
                Assert.Equal(reply, context.People.Where(p => p.Name == repliersName).FirstOrDefault().Comments[0]);
                Assert.Equal(reply, context.Comments.Where(r => r.Body == reply.Body).FirstOrDefault());
                var post1 = context.Posts.Where(x => x.Comments.Contains(reply)).FirstOrDefault();
                Assert.Equal(reply, post1.Comments[0]);
            }
        }
Esempio n. 9
0
 public HomeController(WallContext context)
 {
     dbContext = context;
 }
Esempio n. 10
0
 public WallController(WallContext context)
 {
     _context = context;
 }
Esempio n. 11
0
 public LoginController(WallContext context)
 {
     _context = context;
 }
 // -------------------- CONSTRUCTOR
 public UserController(WallContext context)
 {
     database = context;
     Console.WriteLine("###### CONTEXT ACQUIRED");
 }
 public MessagesController(WallContext context)
 {
     _context = context;
 }
Esempio n. 14
0
 public MessageController(WallContext context)
 {
     dbContext = context;
 }