public PostController(IHostingEnvironment hostingEnvironment) { if (postsServices == null) { postsServices = new PostsServices(); } if (postCategoriesServices == null) { postCategoriesServices = new PostCategoriesServices(); } _hostingEnvironment = hostingEnvironment; }
public async void TestPostServicesMethodPostById() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: "BlogWebApp").Options; var db = new ApplicationDbContext(options); var context = new PostsServices(db); var post1 = new Post { Title = "First Post", Description = "Kuku", Genre = "it" }; var post1Edit = new Post { Title = "Second Post", Description = "Test", Genre = "it" }; await context.CreateOrEdit(post1); await context.CreateOrEdit(post1Edit); await Task.Delay(10000); //Add post with valid data var firstPostById = await context.PostById(1); Assert.Equal("First Post", firstPostById.Title); Assert.Equal(1, firstPostById.Id); var secondPostById = await context.PostById(2); Assert.Equal("First Post", secondPostById.Title); Assert.Equal(2, secondPostById.Id); //Task<InvalidDataException> exception = Assert.ThrowsAsync<InvalidDataException>(async () => await context.CreateOrEdit(post2)); //Assert.Equal("no empty fields allowed ", exception.Result.Message); //Task<InvalidDataException> exception2 = Assert.ThrowsAsync<InvalidDataException>(async () => await context.CreateOrEdit(post3)); //Assert.Equal("no empty fields allowed ", exception2.Result.Message); //Task<InvalidDataException> exception3 = Assert.ThrowsAsync<InvalidDataException>(async () => await context.CreateOrEdit(post4)); //Assert.Equal("no empty fields allowed ", exception3.Result.Message); }
public async void TestPostServicesMethodCreateOrEdit() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: "BlogWebApp").Options; var db = new ApplicationDbContext(options); var post1 = new Post { Title = "First Post", Description = "IT", Genre = "it" }; var post2 = new Post { Description = "IT", Genre = "it" }; var post3 = new Post { Title = "First Post", Genre = "it" }; var post4 = new Post { Title = "First Post", Description = "IT" }; var context = new PostsServices(db); //Add post with valid data var result = await context.CreateOrEdit(post1); Assert.Equal(post1, result); Assert.Equal(5, post1.Id); Task <InvalidDataException> exception = Assert.ThrowsAsync <InvalidDataException>(async() => await context.CreateOrEdit(post2)); Assert.Equal("no empty fields allowed ", exception.Result.Message); Task <InvalidDataException> exception2 = Assert.ThrowsAsync <InvalidDataException>(async() => await context.CreateOrEdit(post3)); Assert.Equal("no empty fields allowed ", exception2.Result.Message); Task <InvalidDataException> exception3 = Assert.ThrowsAsync <InvalidDataException>(async() => await context.CreateOrEdit(post4)); Assert.Equal("no empty fields allowed ", exception3.Result.Message); }
public void TestPostServicesMethodAllPost() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: "BlogWebApp").Options; var db = new ApplicationDbContext(options); var posts = new[] { new Post { Title = "First Post", Description = "IT", Genre = "it" }, new Post { Title = "First Post", Description = "IT", Genre = "it" } }; db.Posts.AddRange(posts); db.SaveChangesAsync(); var count = new PostsServices(db); var result = count.AllPosts(); Assert.NotEqual(1, result.Result.Count); Assert.Equal(2, result.Result.Count); }
public PostsViewModel() { var postServices = new PostsServices(); UsersList = postServices.GetUsers(); }
static void Main(string[] args) { PersonService psdb = new PersonService(); PostsServices podb = new PostsServices(); PollServices pldb = new PollServices(); CircleService ccdb = new CircleService(); while (true) { Console.WriteLine("Enter User Name: "); string User = Console.ReadLine(); while (true) { try { var personTest = psdb.GetName(User); break; } catch (Exception e) { Console.WriteLine(e + "User Name doesn't exist"); Console.WriteLine("Enter User Name:"); User = Console.ReadLine(); } } var person = psdb.GetName(User); bool stayUserMode = true; do { Console.WriteLine("Options:\n" + "\t1. watch posts\n" + "\t2. watch polls\n" + "\t3. create circle\n" + "\t4. create post\n" + "\t5. create poll\n" + "\t6. block User\n" + "\t0. exit User Mode\n"); string choice = Console.ReadLine(); if (choice == "1") { bool stayCircle = false; bool stay = true; Console.WriteLine("1. watch for circle\n" + "2. watch public\n"); string circleChoice = Console.ReadLine(); var circle = new Circle(); if (circleChoice == "1") { Console.WriteLine("Enter Circle name:"); string CircleName = Console.ReadLine(); while (true) { try { var circleTest = ccdb.GetName(CircleName); break; } catch (Exception e) { Console.WriteLine(e + "Circle Name doesn't exist"); Console.WriteLine("Enter Circle Name:"); User = Console.ReadLine(); } } circle = ccdb.GetName(CircleName); } else { circle = ccdb.GetName("public"); } int currentId = 0; do { Console.Clear(); while (stayCircle == true) { Console.Clear(); Console.WriteLine("Options:\n" + "\t1. display next post\n" + "\t2. display previous post\n" + "\t3. comment\n" + "\t0. exit Circle\n"); string WallChoice = Console.ReadLine(); ccdb.PrintPost(circle, currentId); if (WallChoice == "1") { currentId++; } if (WallChoice == "2") { if (currentId > 0) { currentId--; } } if (WallChoice == "3") { Console.WriteLine("Write comment:\n"); string comment = Console.ReadLine(); } if (WallChoice == "0") { stayCircle = false; } else { Console.WriteLine("invalid option. try again\n"); } } while (stayCircle == true) { ; } } while (stay == true); } if (choice == "2") { } if (choice == "3") { } if (choice == "4") { } if (choice == "5") { } if (choice == "6") { } if (choice == "0") { stayUserMode = false; } else { Console.WriteLine("invalid option. try again\n"); } } while (stayUserMode == true); } }
public PostsController() { _postsServices = new PostsServices(); }