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 <IActionResult> Create(CreateGuideInputModel model, IFormFile file) { var games = await this.gamesService.GetAll <GamesDropDownViewModel>(); var user = await this.userManager.GetUserAsync(this.User); var userId = await this.userManager.GetUserIdAsync(user); var imageUrl = await this.cloudinaryHelper.UploadGuideImageAsync(this.cloudinary, file); model.ImageUrl = imageUrl; model.UserId = userId; model.Games = games; if (!this.ModelState.IsValid || string.IsNullOrWhiteSpace(userId) || file == null) { return(this.View(model)); } if (!Enum.TryParse(typeof(CategoryOfGuide), model.Category, out _)) { return(this.View(model)); } if (!games.Select(x => x.Id).Contains(model.GameId)) { return(this.View(model)); } var guideId = await this.guidesService.CreateAsync(model, userId); return(this.RedirectToAction("Details", new { id = guideId })); }
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 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 <IActionResult> Create() { var games = await this.gamesService.GetAll <GamesDropDownViewModel>(); var model = new CreateGuideInputModel() { Games = games }; return(this.View(model)); }
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 <CreateGuideResponseViewModel> GuideAdd([FromBody] CreateGuideInputModel model) { try { var data = await _sessionProvider.Get(); //sample API call var createGuideCommandResult = await _commandSender.Send <Contracts.Commands.Redemption.GuideDetailsCommand, Contracts.Commands.Redemption.GuideDetailsCommandResult>(new Contracts.Commands.Redemption.GuideDetailsCommand { AccountNumber = model.AccountNumber, AddressLineOne = model.AddressLineOne, AddressLineTwo = model.AddressLineTwo, CityId = model.ResidentCityId, ZipCode = model.Zip, AddressProofType = "AddressProofType", BankName = model.BankName, BranchName = model.BranchCode, CountryCode = model.PhoneCode, CurrencyId = model.CurrencyId, EmailId = model.Email, EventIDs = model.EventIDs, FirstName = model.FirstName, IPAddress = "IPAddress", LanguageIds = model.LanguageId, LastName = model.LastName, MobileNo = model.PhoneNumber, Notes = model.ServiceNotes, ModifiedBy = data.IsAuthenticated ? data.User.AltId : new Guid("A101F398-2FFE-47A2-82AE-11A9220C06F4"), Services = model.Services, State = model.FinanceStateId, SwiftCode = model.BranchCode, TaxCountry = model.FinanceCountryAltId, TaxNumber = model.TaxId, Url = "Url", VenueID = 1, RoutingNumber = model.RoutingNumber, BankAccountType = model.BankAccountType, AccountType = model.AccountType, Document = model.Document }); if (createGuideCommandResult.Success) { return(new CreateGuideResponseViewModel { Success = true, IsSaving = true, }); } else { return(new CreateGuideResponseViewModel { Success = false, IsSaving = false }); } } catch (Exception e) { _logger.Log(LogCategory.Error, e); return(new CreateGuideResponseViewModel { }); } }
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); }