public async Task SearchGuideShouldFindOneByTitle() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var context = new ApplicationDbContext(options.Options); await context.Users.AddAsync(new ApplicationUser() { Id = "2" }); await context.Games.AddAsync(new Game() { Id = "1" }); var postRepository = new EfDeletableEntityRepository <Post>(context); var guideRepository = new EfDeletableEntityRepository <Guide>(context); var searchBarService = new SearchBarService(postRepository, guideRepository); var guideService = new GuidesService(guideRepository); var guideModel = new CreateGuideInputModel() { Title = "testtesttest", Category = "Action", Description = "sssss", GameId = "1", ImageUrl = "test", }; await guideService.CreateAsync(guideModel, "2"); var actual = await searchBarService.SearchGuide <GuideViewModel>("test", 5, 0); Assert.Single(actual); }
public async Task GetReportsShouldGetOne() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var context = new ApplicationDbContext(options.Options); var guideRepository = new EfDeletableEntityRepository <Guide>(context); var guideService = new GuidesService(guideRepository); var guideModel = new CreateGuideInputModel() { Category = "Action", Description = "someDesc", GameId = "1", ImageUrl = "google", Title = "test", }; var guideId = await guideService.CreateAsync(guideModel, "1"); var repository = new EfRepository <Report>(context); var service = new ReportsService(repository); var model = new AddReportToGuideInputModel() { UserId = "1", GuideId = guideId, Reason = "tupooooo", }; await service.AddReportToGuideAsync(model); var actual = await service.GetByGuideAsync <ReportForGuideViewModel>(model.GuideId); Assert.Single(actual); }
public async Task GetLatestShouldReturnModel() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var context = new ApplicationDbContext(options.Options); await context.Users.AddAsync(new ApplicationUser() { Id = "1" }); await context.Games.AddAsync(new Game() { Id = "1" }); var repository = new EfDeletableEntityRepository <Guide>(context); var service = new GuidesService(repository); var model = new CreateGuideInputModel() { Title = "new", GameId = "1", Category = "Action", Description = "test", ImageUrl = "google", }; await service.CreateAsync(model, "1"); var actual = await service.TakeLatestGuideAsync <LatestGuideViewModel>(); Assert.IsType <LatestGuideViewModel>(actual); }
public async Task EditGuideShouldEditContent() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var context = new ApplicationDbContext(options.Options); await context.Users.AddAsync(new ApplicationUser() { Id = "1" }); await context.Games.AddAsync(new Game() { Id = "1" }); var repository = new EfDeletableEntityRepository <Guide>(context); var service = new GuidesService(repository); var model = new CreateGuideInputModel() { Title = "new", GameId = "1", Category = "Action", Description = "test", ImageUrl = "google", }; var guideId = await service.CreateAsync(model, "1"); var oldGuide = await service.GetByIdAsync <EditGuideViewModel>(guideId); var contentOldValue = oldGuide.Content; await service.EditGuideAsync(oldGuide.Id, oldGuide.Title, "newwwwwwwwwwwwwwwwwwwwwwwwwwwww"); var newGuide = await service.GetByIdAsync <EditGuideViewModel>(guideId); Assert.NotEqual(contentOldValue, newGuide.Title); }
public async Task AddOnGuideShouldAdd() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var context = new ApplicationDbContext(options.Options); var repository = new EfDeletableEntityRepository <Guide>(context); var service = new GuidesService(repository); var model = new CreateGuideInputModel() { Title = "test", Category = "Action", Description = "test", GameId = "1", ImageUrl = "test", }; await service.CreateAsync(model, "1"); var actual = await service.GetAllCountAsync(); Assert.Equal(1, actual); }
public async Task SearchGuideShouldTakeFive() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var context = new ApplicationDbContext(options.Options); await context.Users.AddAsync(new ApplicationUser() { Id = "1" }); await context.Games.AddAsync(new Game() { Id = "1" }); var postRepository = new EfDeletableEntityRepository <Post>(context); var guideRepository = new EfDeletableEntityRepository <Guide>(context); var searchBarService = new SearchBarService(postRepository, guideRepository); var guideService = new GuidesService(guideRepository); var guideModels = new List <CreateGuideInputModel>() { new CreateGuideInputModel() { Title = "new", Category = "Action", Description = "test", GameId = "1", ImageUrl = "google", }, new CreateGuideInputModel() { Title = "new", Category = "Action", Description = "test1", ImageUrl = "google", GameId = "1", }, new CreateGuideInputModel() { Title = "testttt", Category = "Action", Description = "new", ImageUrl = "google", GameId = "1", }, new CreateGuideInputModel() { Title = "new", Category = "Action", Description = "test5", ImageUrl = "google", GameId = "1", }, new CreateGuideInputModel() { Title = "new", Category = "Action", Description = "test7", ImageUrl = "google", GameId = "1", }, new CreateGuideInputModel() { Title = "newtest3", Category = "Action", Description = "eee", ImageUrl = "google", GameId = "1", }, }; foreach (var guideModel in guideModels) { await guideService.CreateAsync(guideModel, "1"); } var actual = await searchBarService.SearchGuide <GuideViewModel>("test", 5, 0); Assert.Equal(5, actual.Count()); }
public async Task GetAllForAdminShouldGetFive() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var context = new ApplicationDbContext(options.Options); await context.Users.AddAsync(new ApplicationUser() { Id = "1" }); await context.Games.AddAsync(new Game() { Id = "1" }); var repository = new EfDeletableEntityRepository <Guide>(context); var service = new GuidesService(repository); var models = new List <CreateGuideInputModel>() { new CreateGuideInputModel() { Title = "new", GameId = "1", Category = "Action", Description = "test", ImageUrl = "google", }, new CreateGuideInputModel() { Title = "new2", GameId = "1", Category = "Action", Description = "test2", ImageUrl = "google2", }, new CreateGuideInputModel() { Title = "new3", GameId = "1", Category = "Action", Description = "test3", ImageUrl = "google3", }, new CreateGuideInputModel() { Title = "new4", GameId = "1", Category = "Action", Description = "test4", ImageUrl = "google4", }, new CreateGuideInputModel() { Title = "new5", GameId = "1", Category = "Action", Description = "test5", ImageUrl = "google5", }, new CreateGuideInputModel() { Title = "new6", GameId = "1", Category = "Action", Description = "test6", ImageUrl = "google6", }, }; foreach (var model in models) { await service.CreateAsync(model, "1"); } var actual = await service.GetAllForAdminAsync <GuideViewModel>(5, 0); Assert.Equal(5, actual.Count()); }
public async Task GetCountBySearchShouldGetFour() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var context = new ApplicationDbContext(options.Options); await context.Users.AddAsync(new ApplicationUser() { Id = "1" }); await context.Games.AddAsync(new Game() { Id = "1" }); var repository = new EfDeletableEntityRepository <Guide>(context); var service = new GuidesService(repository); var models = new List <CreateGuideInputModel>() { new CreateGuideInputModel() { Title = "new", GameId = "1", Category = "Action", Description = "test", ImageUrl = "google", }, new CreateGuideInputModel() { Title = "new2", GameId = "1", Category = "Action", Description = "test2", ImageUrl = "google2", }, new CreateGuideInputModel() { Title = "new3", GameId = "1", Category = "Mmo", Description = "test3", ImageUrl = "google3", }, }; foreach (var model in models) { await service.CreateAsync(model, "1"); } var lastModel = new CreateGuideInputModel() { Title = "teeest", GameId = "1", Category = "Mmo", Description = "newwwwwwww", ImageUrl = "google4", }; await service.CreateAsync(lastModel, "2"); var actual = await service.GetCountBySearchAsync("new"); Assert.Equal(4, actual); }