Esempio n. 1
0
        public async Task <string> ScheduleTestDriveAsync(ScheduleTestDriveServiceModel model, ClaimsPrincipal user)
        {
            await this.ValidateCarIdAsync(model.CarId);

            var dbTestDrive = _mapper.Map <TestDrive>(model);

            var dbStatusId = await this.statusRepository
                             .Find(s => s.Name == TestDriveStatus.Upcoming.ToString())
                             .Select(s => s.Id)
                             .FirstAsync();

            var userId = this.userManager.GetUserId(user);

            DataValidator.ValidateNotNull(userId, new InvalidOperationException(ErrorConstants.NotSignIn));

            dbTestDrive.StatusId = dbStatusId;
            dbTestDrive.UserId   = userId;

            this.testDriveRepository.Add(dbTestDrive);

            var rowsAffected = await this.testDriveRepository.CompleteAsync();

            RepositoryValidator.ValidateCompleteChanges(rowsAffected);

            return(dbTestDrive.Id);
        }
Esempio n. 2
0
        public void Initialize()
        {
            _factory   = new Mock <IRepositoryValidationFactory>();
            _validator = new RepositoryValidator(_factory.Object);

            _context = new Mock <IExecutionContext>();
        }
Esempio n. 3
0
        public IEnumerable <IProjectValidationProblem> Execute()
        {
            var validationFactory         = new ValidationFactory();
            RepositoryValidator validator = new RepositoryValidator(validationFactory);

            return(validator.Validate(_context));
        }
Esempio n. 4
0
        public async Task CreateAsync <TEntity, TModel>(TModel creatingModel)
            where TEntity : class
            where TModel : class
        {
            var dbEntity = Mapper.Map <TEntity>(creatingModel);

            this.dbContext.Set <TEntity>().Add(dbEntity);

            var rowsAffected = await this.dbContext.SaveChangesAsync();

            RepositoryValidator.ValidateCompleteChanges(rowsAffected);
        }
Esempio n. 5
0
        public async Task CreateNewAsync <TCar>(CarServiceModel model) where TCar : BaseCar, new()
        {
            var dbCar = Mapper.Map <TCar>(model);

            dbCar.Pictures = Mapper.Map <ICollection <Picture> >(model.Pictures);

            this.carRepository.Add(dbCar);

            var rowsAffected = await this.carRepository.CompleteAsync();

            RepositoryValidator.ValidateCompleteChanges(rowsAffected);
        }
Esempio n. 6
0
        public async Task DeleteAsync <TEntity>(string id) where TEntity : class
        {
            var entity = await this.dbContext.Set <TEntity>()
                         .FindAsync(id);

            DataValidator.ValidateNotNull(entity, new ArgumentException(ErrorConstants.IncorrectId));

            this.dbContext.Remove(entity);

            var rowsAffected = await this.dbContext.SaveChangesAsync();

            RepositoryValidator.ValidateCompleteChanges(rowsAffected);
        }
Esempio n. 7
0
        public async Task DeleteAsync(string userId)
        {
            var dbUser = await this.userRepository.GetByIdAsync(userId);

            DataValidator.ValidateNotNull(dbUser, new ArgumentException(ErrorConstants.IncorrectId));
            await this.ValidateUserRoleAsync(dbUser);

            this.userRepository.Remove(dbUser);

            var rowsAffected = await userRepository.CompleteAsync();

            RepositoryValidator.ValidateCompleteChanges(rowsAffected);
        }
        public async Task EditAsync <TEntity, TModel>(TModel editingModel, string id)
            where TEntity : class
            where TModel : class
        {
            var dbEntity = await this.dbContext.FindAsync <TEntity>(id);

            DataValidator.ValidateNotNull(dbEntity, new ArgumentException(ErrorConstants.IncorrectId));

            Mapper.Map(editingModel, dbEntity);

            var rowsAffected = await this.dbContext.SaveChangesAsync();

            RepositoryValidator.ValidateCompleteChanges(rowsAffected);
        }
Esempio n. 9
0
        public async Task UnbanUserAsync(string userId)
        {
            var dbUser = await this.GetValidatedUser(userId);

            if (this.IsUserBanned(dbUser) == false)
            {
                throw new InvalidOperationException(ErrorConstants.IncorrectUser);
            }

            dbUser.LockoutEnd = null;

            var rowsAffected = await userRepository.CompleteAsync();

            RepositoryValidator.ValidateCompleteChanges(rowsAffected);
        }
Esempio n. 10
0
        public async Task BanUserAsync(string userId)
        {
            var dbUser = await this.GetValidatedUser(userId);

            if (this.IsUserBanned(dbUser))
            {
                throw new InvalidOperationException(ErrorConstants.IncorrectUser);
            }

            dbUser.LockoutEnd = DateTimeOffset.UtcNow.AddDays(WebConstants.UserBanDays);

            var rowsAffected = await userRepository.CompleteAsync();

            RepositoryValidator.ValidateCompleteChanges(rowsAffected);
        }
Esempio n. 11
0
        public async Task CancelTestDriveAsync(string testDriveId, ClaimsPrincipal user)
        {
            var dbTestDrive = await this.testDriveRepository.GetByIdAsync(testDriveId);

            DataValidator.ValidateNotNull(dbTestDrive, new ArgumentException(ErrorConstants.IncorrectId));
            this.ValidateTestDriveUser(dbTestDrive, user);
            await this.ValidateStatusAsync(dbTestDrive.StatusId);

            var dbCanceledStatusId = await this.statusRepository
                                     .GetIdByNameAsync(TestDriveStatus.Canceled.ToString());

            dbTestDrive.StatusId = dbCanceledStatusId;

            var rowsAffected = await this.testDriveRepository.CompleteAsync();

            RepositoryValidator.ValidateCompleteChanges(rowsAffected);
        }
Esempio n. 12
0
        public async Task ChangeTestDriveStatusToPassedAsync(string testDriveId)
        {
            var dbTestDrive = await this.testDriveRepository.GetByIdAsync(testDriveId);

            DataValidator.ValidateNotNull(dbTestDrive, new ArgumentException(ErrorConstants.IncorrectId));
            await this.ValidateTestDriveStatus(dbTestDrive);

            var dbPassedStatusId = await this.statusRepository
                                   .Find(s => s.Name == TestDriveStatus.Passed.ToString())
                                   .Select(s => s.Id)
                                   .FirstAsync();

            dbTestDrive.StatusId = dbPassedStatusId;

            var rowsAffected = await this.testDriveRepository.CompleteAsync();

            RepositoryValidator.ValidateCompleteChanges(rowsAffected);
        }
        public void SetUp()
        {
            var mockLogger = Substitute.For <ILogger <RepositoryValidator> >();

            _mockClient = Substitute.For <IGitHubClient>();

            _mockRules = new IValidationRule[]
            {
                Substitute.For <IValidationRule>(),
                Substitute.For <IValidationRule>(),
                Substitute.For <IValidationRule>()
            };

            _repositoryValidator = new RepositoryValidator(mockLogger, _mockClient, _mockRules);

            _mockRepositoryContentsClient = Substitute.For <IRepositoryContentsClient>();
            _mockClient.Repository.Content.Returns(_mockRepositoryContentsClient);
        }
Esempio n. 14
0
        public async Task SeedUserAsync(UserServiceModel model, string password, string roleName)
        {
            if (await this.IsUserExist(model.Email))
            {
                return;
            }
            if (await this.IsRoleExist(roleName) == false)
            {
                throw new ArgumentException(ErrorConstants.RoleNotFound);
            }

            var dbUser = await this.CreateUserAsync(model, password);

            var result = await this.userManager.AddToRoleAsync(dbUser, roleName);

            DataValidator.ValidateIdentityResult(result);

            var rowsAffected = await this.userRepository.CompleteAsync();

            RepositoryValidator.ValidateCompleteChanges(rowsAffected);
        }
Esempio n. 15
0
        public async Task EditAsync <TCar>(CarServiceModel model) where TCar : BaseCar
        {
            var dbCar = await this.carRepository.Set <TCar>().FindAsync(model.Id);

            DataValidator.ValidateNotNull(dbCar, new ArgumentException(ErrorConstants.IncorrectId));

            // TODO: Optimize
            if (model.Pictures.Count() > 0)
            {
                await this.pictureRepository.RemoveRangeWhereAsync(p => p.CarId == dbCar.Id);

                dbCar.Pictures = Mapper.Map <ICollection <Picture> >(model.Pictures);
            }
            if (model.Options.Count() > 0)
            {
                await this.carOptionRepository.RemoveAllWithCarIdAsync(dbCar.Id);
            }

            Mapper.Map(model, dbCar);

            var rowsAffected = await this.carOptionRepository.CompleteAsync();

            RepositoryValidator.ValidateCompleteChanges(rowsAffected);
        }
 public RepositoriesController(Storage storage, RepositoryValidator repositoryValidator, ErrorFactory errorFactory)
 {
     _repositoryValidator = repositoryValidator;
     _errorFactory = errorFactory;
     _storage = storage;
 }
Esempio n. 17
0
        static async Task Main(string[] args)
        {
            bool          collectAuthors  = false;
            string        path            = null;
            SearchOptions options         = new SearchOptions();
            ISearchRange  range           = null;
            ActionType    requestedAction = ActionType.List;

            void SetBranchRange(string baseBranch, string branch)
            {
                if (range != null && !(range is BranchSearchRange))
                {
                    Errors.Die("Can not mix hash and branch ranges");
                }
                BranchSearchRange current = range != null ? (BranchSearchRange)range : new BranchSearchRange();

                if (baseBranch != null)
                {
                    current.Base = baseBranch;
                }
                if (branch != null)
                {
                    current.Branch = branch;
                }
                range = current;
            }

            void SetHashRange(string oldest, string newest)
            {
                if (range != null && !(range is HashSearchRange))
                {
                    Errors.Die("Can not mix hash and branch ranges");
                }
                HashSearchRange current = range != null ? (HashSearchRange)range : new HashSearchRange();

                if (oldest != null)
                {
                    current.Oldest = oldest;
                }
                if (newest != null)
                {
                    current.Newest = newest;
                }
                range = current;
            }

            OptionSet os = new OptionSet()
            {
                { "h|?|help", "Displays the help", v => requestedAction = ActionType.Help },
                { "verbose", "Print more details", v => Explain.Enabled = true },
                { "explain-commit=", "Parse a single commit and explain.", v => {
                      requestedAction = ActionType.ExplainCommit;
                      range           = new SingleHashSearchRange {
                          Hash = v
                      };
                  } },
                { "oldest=", "Starting hash to consider (hash range mode)", s => SetHashRange(s, null) },
                { "newest=", "Ending hash to consider (hash range mode)", e => SetHashRange(null, e) },
                { "base=", "Starting base to consider (branch/base mode)", b => SetBranchRange(b, null) },
                { "branch=", "Ending branch to consider (branch/base mode)", b => SetBranchRange(null, b) },

                { "explain", "Explain why each commit is considered a bug", v => Explain.Enabled = true },
                { "github-pat=", "Sets the PAT required to access github issues", v => options.GithubPAT = v },
                { "github-pat-file=", "Sets a file to read to use for github-path", v => options.GithubPAT = File.ReadLines(v).First() },
                { "github=", "Project to search issues of, such as xamarin/xamarin-macios. Must be '/' seperated", v => {
                      options.GithubLocation = v;
                  } },
                { "collect-authors", "Generate a list of unique authors to commits listed", v => collectAuthors = true },
                { "ignore=", "Commit hashes to ignore", v => options.CommitsToIgnore.Add(v) },
                new ResponseFileSource(),
            };

            try {
                IList <string> unprocessed = os.Parse(args);
                if (requestedAction == ActionType.Help || unprocessed.Count != 1)
                {
                    ShowHelp(os);
                    return;
                }
                path = unprocessed[0];
            }
            catch (Exception e) {
                Console.Error.WriteLine("Could not parse the command line arguments: {0}", e.Message);
                return;
            }

            if (String.IsNullOrEmpty(options.GithubLocation) || !options.GithubLocation.Contains("/"))
            {
                Errors.Die("--github formatted incorrectly");
            }

            if (!RepositoryValidator.ValidateGitHashes(path, range))
            {
                Environment.Exit(-1);
            }

            if (String.IsNullOrEmpty(options.GithubPAT))
            {
                Errors.Die("Unable to read GitHub PAT token");
            }

            Explain.Print("Finding Commits in Range");
            Explain.Indent();
            var commits = RangeFinder.Find(path, options, range).ToList();

            Explain.Print($"Found: {commits.Count}");
            Explain.Deindent();

            Explain.Print("Finding Pull Requests");
            Explain.Indent();
            var finder = new RequestFinder(options.GithubPAT);
            await finder.AssertLimits();

            var requestCollection = await finder.FindPullRequests(options.GithubLocation, commits);

            Explain.Print($"Found: {requestCollection.All.Count}");
            Explain.Deindent();

            var printer = new ConsolePrinter(requestCollection, options.GithubLocation);

            printer.Print(collectAuthors);
        }