public async Task IsUserApplied_WithCorrectData_ShouldReturnCorrectResult() { var errorMessage = "JobsService IsUserApplied() method does not work properly."; // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var applicationsRepository = new EfRepository <Application>(context); var userManager = this.GetUserManagerMock(); var jobsService = new JobsService(applicationsRepository, userManager.Object); var userId = Guid.NewGuid().ToString(); var applicationModel = new ApplicationInputModel { Age = 18, Name = "Nikola", Country = "Bulgaria", Position = GlobalConstants.BoosterRoleName, Rank = "Diamond 2", Champions = "Katarina, Yasuo", Description = "Very good midlaner", }; // Act await jobsService.CreateAsync(applicationModel, userId); var result = jobsService.IsUserApplied(userId); // Assert Assert.True(result, errorMessage); }
public async Task CreateAsync(ApplicationInputModel inputModel, string userId) { var application = new Application { UserId = userId, Age = inputModel.Age, Name = inputModel.Name, Country = inputModel.Country, Position = inputModel.Position, Rank = inputModel.Rank, Champions = inputModel.Champions, Description = inputModel.Description, }; await this.applicationsRepository.AddAsync(application); await this.applicationsRepository.SaveChangesAsync(); }
public async Task CreateAsync_WithCorrectData_ShouldSuccessfullyCreate() { var errorMessage = "JobsService CreateAsync() method does not work properly."; // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var applicationsRepository = new EfRepository <Application>(context); var userManager = this.GetUserManagerMock(); var jobsService = new JobsService(applicationsRepository, userManager.Object); var userId = Guid.NewGuid().ToString(); var applicationModel = new ApplicationInputModel { Age = 18, Name = "Nikola", Country = "Bulgaria", Position = GlobalConstants.BoosterRoleName, Rank = "Diamond 2", Champions = "Katarina, Yasuo", Description = "Very good midlaner", }; // Act await jobsService.CreateAsync(applicationModel, userId); var actualResult = applicationsRepository.All().First(); var expectedResult = applicationModel; // Assert Assert.True(userId == actualResult.UserId, errorMessage); Assert.True(expectedResult.Age == actualResult.Age, errorMessage); Assert.True(expectedResult.Name == actualResult.Name, errorMessage); Assert.True(expectedResult.Country == actualResult.Country, errorMessage); Assert.True(expectedResult.Position == actualResult.Position, errorMessage); Assert.True(expectedResult.Rank == actualResult.Rank, errorMessage); Assert.True(expectedResult.Champions == actualResult.Champions, errorMessage); Assert.True(expectedResult.Description == actualResult.Description, errorMessage); }
public async Task <IActionResult> Apply(ApplicationInputModel inputModel) { if (!this.ModelState.IsValid) { return(this.View()); } var userId = this.userManager.GetUserId(this.User); var editModel = new EditInputModel { UserId = userId, Champions = inputModel.Champions, Rank = inputModel.Rank, }; await this.jobsService.CreateAsync(inputModel, userId); await this.usersService.UpdateAsync(editModel); return(this.Redirect("/")); }