Exemple #1
0
 public void DeletePerson(int id)
 {
     using (RepositoryHelpers.GetUnitOfWorkFactory().Create())
     {
         RepositoryHelpers.GetPeopleRepository().Remove(id);
     }
 }
Exemple #2
0
        public IQueryable <EmailAddress> ListEmailAddresses([QueryString("Id")] int personId)
        {
            var repo   = RepositoryHelpers.GetPeopleRepository();
            var person = repo.FindById(personId, x => x.EmailAddresses);

            return(person.EmailAddresses.AsQueryable());
        }
Exemple #3
0
        public void DeleteObjectsCacheAndCacheMappingBeforeMount()
        {
            GVFSFunctionalTestEnlistment enlistment1 = this.CloneAndMountEnlistment();
            GVFSFunctionalTestEnlistment enlistment2 = this.CloneAndMountEnlistment();

            enlistment1.UnmountGVFS();

            string objectsRoot = GVFSHelpers.GetPersistedGitObjectsRoot(enlistment1.DotGVFSRoot).ShouldNotBeNull();

            objectsRoot.ShouldBeADirectory(this.fileSystem);
            RepositoryHelpers.DeleteTestDirectory(objectsRoot);

            string metadataPath = Path.Combine(this.localCachePath, "mapping.dat");

            metadataPath.ShouldBeAFile(this.fileSystem);
            this.fileSystem.DeleteFile(metadataPath);

            enlistment1.MountGVFS();

            Task task1 = Task.Run(() => this.HydrateRootFolder(enlistment1));
            Task task2 = Task.Run(() => this.HydrateRootFolder(enlistment2));

            task1.Wait();
            task2.Wait();
            task1.Exception.ShouldBeNull();
            task2.Exception.ShouldBeNull();

            enlistment1.Status().ShouldContain("Mount status: Ready");
            enlistment2.Status().ShouldContain("Mount status: Ready");

            this.AlternatesFileShouldHaveGitObjectsRoot(enlistment1);
            this.AlternatesFileShouldHaveGitObjectsRoot(enlistment2);
        }
Exemple #4
0
        public void DeleteCacheDuringHydrations()
        {
            GVFSFunctionalTestEnlistment enlistment1 = this.CloneAndMountEnlistment();

            string objectsRoot = GVFSHelpers.GetPersistedGitObjectsRoot(enlistment1.DotGVFSRoot).ShouldNotBeNull();

            objectsRoot.ShouldBeADirectory(this.fileSystem);

            Task task1 = Task.Run(() =>
            {
                this.HydrateEntireRepo(enlistment1);
            });

            while (!task1.IsCompleted)
            {
                try
                {
                    // Delete objectsRoot rather than this.localCachePath as the blob sizes database cannot be deleted while GVFS is mounted
                    RepositoryHelpers.DeleteTestDirectory(objectsRoot);
                    Thread.Sleep(100);
                }
                catch (IOException)
                {
                    // Hydration may have handles into the cache, so failing this delete is expected.
                }
            }

            task1.Exception.ShouldBeNull();

            enlistment1.Status().ShouldContain("Mount status: Ready");
        }
Exemple #5
0
 public void InsertPhoneNumber([QueryString("Id")] int personId, PhoneNumber phoneNumber)
 {
     if (ModelState.IsValid)
     {
         try
         {
             using (RepositoryHelpers.GetUnitOfWorkFactory().Create())
             {
                 var repo       = RepositoryHelpers.GetPeopleRepository();
                 var person     = repo.FindById(personId, x => x.PhoneNumbers);
                 var userNumber = new PhoneNumber {
                     OwnerId = personId
                 };
                 TryUpdateModel(userNumber);
                 person.PhoneNumbers.Add(userNumber);
             }
         }
         catch (ModelValidationException mvex)
         {
             foreach (var error in mvex.ValidationErrors)
             {
                 ModelState.AddModelError(error.MemberNames.FirstOrDefault() ?? "", error.ErrorMessage);
             }
         }
     }
 }
Exemple #6
0
        public void CloneWithDefaultLocalCacheLocation()
        {
            FileSystemRunner fileSystem    = FileSystemRunner.DefaultRunner;
            string           homeDirectory = Environment.GetEnvironmentVariable("HOME");

            homeDirectory.ShouldBeADirectory(fileSystem);

            string newEnlistmentRoot = GSDFunctionalTestEnlistment.GetUniqueEnlistmentRoot();

            ProcessStartInfo processInfo = new ProcessStartInfo(GSDTestConfig.PathToGSD);

            processInfo.Arguments              = $"clone {Properties.Settings.Default.RepoToClone} {newEnlistmentRoot} --no-mount --no-prefetch";
            processInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            processInfo.CreateNoWindow         = true;
            processInfo.UseShellExecute        = false;
            processInfo.RedirectStandardOutput = true;

            ProcessResult result = ProcessHelper.Run(processInfo);

            result.ExitCode.ShouldEqual(0, result.Errors);

            string dotGSDRoot = Path.Combine(newEnlistmentRoot, GSDTestConfig.DotGSDRoot);

            dotGSDRoot.ShouldBeADirectory(fileSystem);
            string localCacheRoot = GSDHelpers.GetPersistedLocalCacheRoot(dotGSDRoot);
            string gitObjectsRoot = GSDHelpers.GetPersistedGitObjectsRoot(dotGSDRoot);

            string defaultGSDCacheRoot = Path.Combine(homeDirectory, ".gvfsCache");

            localCacheRoot.StartsWith(defaultGSDCacheRoot, StringComparison.Ordinal).ShouldBeTrue($"Local cache root did not default to using {homeDirectory}");
            gitObjectsRoot.StartsWith(defaultGSDCacheRoot, StringComparison.Ordinal).ShouldBeTrue($"Git objects root did not default to using {homeDirectory}");

            RepositoryHelpers.DeleteTestDirectory(newEnlistmentRoot);
        }
Exemple #7
0
 public void UpdatePhoneNumber([QueryString("Id")] int personId, int id, PhoneNumber phoneNumber)
 {
     if (ModelState.IsValid)
     {
         try
         {
             using (RepositoryHelpers.GetUnitOfWorkFactory().Create())
             {
                 var         repo       = RepositoryHelpers.GetPeopleRepository();
                 var         person     = repo.FindById(personId, x => x.PhoneNumbers);
                 PhoneNumber userNumber = person.PhoneNumbers.Single(x => x.Id == id);
                 TryUpdateModel(userNumber);
                 PhoneNumbersGrid.EditIndex = -1;
                 PhoneNumbersGrid.DataBind();
             }
         }
         catch (ModelValidationException mvex)
         {
             foreach (var error in mvex.ValidationErrors)
             {
                 ModelState.AddModelError(error.MemberNames.FirstOrDefault() ?? "", error.ErrorMessage);
             }
         }
     }
 }
Exemple #8
0
        public void MountReusesLocalCacheKeyWhenGitObjectsRootDeleted()
        {
            GVFSFunctionalTestEnlistment enlistment = this.CloneAndMountEnlistment();

            enlistment.UnmountGVFS();

            // Find the current git objects root and ensure it's on disk
            string objectsRoot = GVFSHelpers.GetPersistedGitObjectsRoot(enlistment.DotGVFSRoot).ShouldNotBeNull();

            objectsRoot.ShouldBeADirectory(this.fileSystem);

            string mappingFilePath     = Path.Combine(enlistment.LocalCacheRoot, "mapping.dat");
            string mappingFileContents = this.fileSystem.ReadAllText(mappingFilePath);

            mappingFileContents.Length.ShouldNotEqual(0, "mapping.dat should not be empty");

            // Delete the git objects root folder, mount should re-create it and the mapping.dat file should not change
            RepositoryHelpers.DeleteTestDirectory(objectsRoot);

            enlistment.MountGVFS();

            GVFSHelpers.GetPersistedGitObjectsRoot(enlistment.DotGVFSRoot).ShouldEqual(objectsRoot);
            objectsRoot.ShouldBeADirectory(this.fileSystem);
            mappingFilePath.ShouldBeAFile(this.fileSystem).WithContents(mappingFileContents);

            this.AlternatesFileShouldHaveGitObjectsRoot(enlistment);
        }
Exemple #9
0
        public IQueryable <PhoneNumber> ListPhoneNumbers([QueryString("Id")] int personId)
        {
            var repo   = RepositoryHelpers.GetPeopleRepository();
            var person = repo.FindById(personId, x => x.PhoneNumbers);

            return(person.PhoneNumbers.AsQueryable());
        }
Exemple #10
0
        public void CloneWithDefaultLocalCacheLocation()
        {
            FileSystemRunner fileSystem    = FileSystemRunner.DefaultRunner;
            string           homeDirectory = Environment.GetEnvironmentVariable("HOME");

            homeDirectory.ShouldBeADirectory(fileSystem);

            string newEnlistmentRoot = ScalarFunctionalTestEnlistment.GetUniqueEnlistmentRoot();

            ProcessStartInfo processInfo = new ProcessStartInfo(ScalarTestConfig.PathToScalar);

            processInfo.Arguments              = $"clone {Properties.Settings.Default.RepoToClone} {newEnlistmentRoot} --no-fetch-commits-and-trees";
            processInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            processInfo.CreateNoWindow         = true;
            processInfo.UseShellExecute        = false;
            processInfo.RedirectStandardOutput = true;
            processInfo.WorkingDirectory       = Properties.Settings.Default.EnlistmentRoot;

            ProcessResult result = ProcessHelper.Run(processInfo);

            result.ExitCode.ShouldEqual(0, result.Errors);

            string gitObjectsRoot = ScalarHelpers.GetObjectsRootFromGitConfig(Path.Combine(newEnlistmentRoot, "src"));

            string defaultScalarCacheRoot = Path.Combine(homeDirectory, ".scalarCache");

            gitObjectsRoot.StartsWith(defaultScalarCacheRoot, StringComparison.Ordinal).ShouldBeTrue($"Git objects root did not default to using {homeDirectory}");

            RepositoryHelpers.DeleteTestDirectory(newEnlistmentRoot);
        }
Exemple #11
0
        public async Task <T[]> GetManyAsync <T, TId>(CancellationToken cancellationToken, params TId[] ids) where T : class, IHasId <TId>
        {
            var result = await FindManyAsync <T, TId>(cancellationToken, ids);

            RepositoryHelpers.ThrowIfGetManyFailed(result, ids);
            return(result);
        }
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            try
            {
                using (RepositoryHelpers.GetUnitOfWorkFactory().Create())
                {
                    var    repository = RepositoryHelpers.GetPeopleRepository();
                    Person person;
                    if (_personId == 0)
                    {
                        person = new Person();
                        repository.Add(person);
                    }
                    else
                    {
                        person = repository.FindById(_personId);
                    }

                    person.FirstName   = FirstName.Text;
                    person.LastName    = LastName.Text;
                    person.DateOfBirth = Convert.ToDateTime(DateOfBirth.Text);
                    person.Type        = (PersonType)Enum.Parse(typeof(PersonType), Type.SelectedValue);
                }
                Response.Redirect("Default.aspx");
            }
            catch (ModelValidationException mvex)
            {
                foreach (var error in mvex.ValidationErrors)
                {
                    ModelState.AddModelError(error.MemberNames.FirstOrDefault() ?? "", error.ErrorMessage);
                }
            }
        }
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            var address = new Address(Street.Text, City.Text, ZipCode.Text, Country.Text, _contactType);
            var errors  = address.Validate();

            foreach (var error in errors)
            {
                ModelState.AddModelError("", error.ErrorMessage);
            }
            if (ModelState.IsValid)
            {
                using (RepositoryHelpers.GetUnitOfWorkFactory().Create())
                {
                    var    repository = RepositoryHelpers.GetPeopleRepository();
                    Person person     = repository.FindById(_personId);
                    switch (_contactType)
                    {
                    case ContactType.Business:
                        person.WorkAddress = address;
                        break;

                    case ContactType.Personal:
                        person.HomeAddress = address;
                        break;

                    default:
                        throw new Exception("Unsupported ContactType.");
                    }
                }
                Response.Redirect("Default.aspx");
            }
        }
 public void UpdatePerson(int id)
 {
     using (RepositoryHelpers.GetUnitOfWorkFactory().Create())
     {
         var person = RepositoryHelpers.GetPeopleRepository().FindById(id);
         TryUpdateModel(person);
     }
 }
Exemple #15
0
        public T Get <T>(params object[] id) where T : class
        {
            T t = DatabaseAccess.GetDbContext(typeof(T)).Set <T>().Find(id);

            t = FilterResult(t);
            RepositoryHelpers.ThrowIfGetFailed <T>(t, id);
            return(t);
        }
Exemple #16
0
        public async Task <T> GetAsync <T>(object id) where T : class
        {
            T t = await DatabaseAccess.GetDbContext(typeof(T)).Set <T>().FindAsync(id);

            t = FilterResult(t);
            RepositoryHelpers.ThrowIfGetFailed <T>(t, id);
            return(t);
        }
Exemple #17
0
 public void DeletePhoneNumber([QueryString("Id")] int personId, int id)
 {
     using (RepositoryHelpers.GetUnitOfWorkFactory().Create())
     {
         var repo   = RepositoryHelpers.GetPeopleRepository();
         var person = repo.FindById(personId, x => x.PhoneNumbers);
         person.PhoneNumbers.Remove(person.PhoneNumbers.Single(x => x.Id == id));
     }
 }
        private string CreateListOf(Type t)
        {
            var caption = RepositoryHelpers.GetStorageName(t);

            if (!_items.ContainsKey(caption))
            {
                _items.Add(caption, new List <object>());
            }
            return(caption);
        }
        public void InsertPerson()
        {
            var person = new Person();

            TryUpdateModel(person);
            using (RepositoryHelpers.GetUnitOfWorkFactory().Create())
            {
                RepositoryHelpers.GetPeopleRepository().Add(person);
            }
        }
Exemple #20
0
        protected virtual void DeleteEnlistment()
        {
            if (this.Enlistment != null)
            {
                this.Enlistment.UnmountAndDeleteAll();
            }

            if (this.ControlGitRepo != null)
            {
                RepositoryHelpers.DeleteTestDirectory(this.ControlGitRepo.RootPath);
            }
        }
        private void LoadPerson()
        {
            var peopleRepository = RepositoryHelpers.GetPeopleRepository();
            var person           = peopleRepository.FindById(_personId);

            if (person != null)
            {
                FirstName.Text   = person.FirstName;
                LastName.Text    = person.LastName;
                DateOfBirth.Text = person.DateOfBirth.ToString("d");
                Type.Text        = person.Type.ToString();
            }
        }
        private void LoadAddress()
        {
            var peopleRepository = RepositoryHelpers.GetPeopleRepository();
            var person           = peopleRepository.FindById(_personId);

            if (person != null)
            {
                Address address = _contactType == ContactType.Personal ? person.HomeAddress : person.WorkAddress;
                Street.Text  = address.Street;
                City.Text    = address.City;
                ZipCode.Text = address.ZipCode;
                Country.Text = address.Country;
            }
        }
        private void LoadPerson()
        {
            var peopleRepository = RepositoryHelpers.GetPeopleRepository();
            var person           = peopleRepository.FindById(_personId);

            if (person != null)
            {
                FirstName.Text   = person.FirstName;
                LastName.Text    = person.LastName;
                DateOfBirth.Text = person.DateOfBirth.ToString("d");
                Type.DataBind();
                var item = Type.Items.FindByValue(((int)person.Type).ToString());
                if (item != null)
                {
                    item.Selected = true;
                }
            }
        }
Exemple #24
0
        [Test] // WorkDirDeleted
        public async Task CommittedSubmodule_True()
        {
            using (var subRepoDir = new TempDirectory())
                using (var subRepo = CreateRepository(subRepoDir))
                    using (var repoDir = new TempDirectory())
                        using (var repo = CreateRepository(repoDir))
                        {
                            RepositoryHelpers.CommitFile(subRepo, "readme.txt", "content", Author);
                            RepositoryHelpers.AddSubmodule(repo, "sub_name", "sub/path", subRepo);
                            repo.Commit($"Add submodule", Author, Author);
                            var service         = CreatePullRequestService(repo);
                            var repositoryModel = CreateLocalRepositoryModel(repo);

                            var count = await service.CountSubmodulesToSync(repositoryModel).FirstAsync();

                            Assert.That(1, Is.EqualTo(count));
                        }
        }
Exemple #25
0
        public void MountUsesNewLocalCacheKeyWhenLocalCacheDeleted()
        {
            GVFSFunctionalTestEnlistment enlistment = this.CloneAndMountEnlistment();

            enlistment.UnmountGVFS();

            // Find the current git objects root and ensure it's on disk
            string objectsRoot = GVFSHelpers.GetPersistedGitObjectsRoot(enlistment.DotGVFSRoot).ShouldNotBeNull();

            objectsRoot.ShouldBeADirectory(this.fileSystem);

            string mappingFilePath     = Path.Combine(enlistment.LocalCacheRoot, "mapping.dat");
            string mappingFileContents = this.fileSystem.ReadAllText(mappingFilePath);

            mappingFileContents.Length.ShouldNotEqual(0, "mapping.dat should not be empty");

            // Delete the local cache folder, mount should re-create it and generate a new mapping file and local cache key
            RepositoryHelpers.DeleteTestDirectory(enlistment.LocalCacheRoot);

            enlistment.MountGVFS();

            // Mount should recreate the local cache root
            enlistment.LocalCacheRoot.ShouldBeADirectory(this.fileSystem);

            // Determine the new local cache key
            string    newMappingFileContents = mappingFilePath.ShouldBeAFile(this.fileSystem).WithContents();
            const int GuidStringLength       = 32;
            string    mappingFileKey         = "A {\"Key\":\"https://gvfs.visualstudio.com/ci/_git/fortests\",\"Value\":\"";
            int       localKeyIndex          = newMappingFileContents.IndexOf(mappingFileKey);
            string    newCacheKey            = newMappingFileContents.Substring(localKeyIndex + mappingFileKey.Length, GuidStringLength);

            // Validate the new objects root is on disk and uses the new key
            objectsRoot.ShouldNotExistOnDisk(this.fileSystem);
            string newObjectsRoot = GVFSHelpers.GetPersistedGitObjectsRoot(enlistment.DotGVFSRoot);

            newObjectsRoot.ShouldNotEqual(objectsRoot);
            newObjectsRoot.ShouldContain(newCacheKey);
            newObjectsRoot.ShouldBeADirectory(this.fileSystem);

            this.AlternatesFileShouldHaveGitObjectsRoot(enlistment);
        }
Exemple #26
0
        public void CreateCommitGraphWhenMissing()
        {
            RepositoryHelpers.DeleteTestDirectory(this.CommitGraphsRoot);

            this.Enlistment.RunVerb("commit-graph");

            this.fileSystem
            .FileExists(this.CommitGraphsChain)
            .ShouldBeTrue($"{this.CommitGraphsChain} does not exist");

            string chain = this.fileSystem.ReadAllText(this.CommitGraphsChain);

            string[] lines = chain.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
            lines.Length.ShouldEqual(1, $"Too many lines in '{chain}'");

            string graphFileName = Path.Combine(this.CommitGraphsRoot, $"graph-{lines[0]}.graph");

            this.fileSystem
            .FileExists(graphFileName)
            .ShouldBeTrue($"{graphFileName} does not exist");
        }
        public void GitObjectsRecreatedWhenDownloadingObjects()
        {
            ScalarFunctionalTestEnlistment enlistment = this.CloneEnlistment();

            // Find the current git objects root and ensure it's on disk
            string objectsRoot = ScalarHelpers.GetObjectsRootFromGitConfig(enlistment.RepoRoot);

            objectsRoot.ShouldBeADirectory(this.fileSystem);

            RepositoryHelpers.DeleteTestDirectory(objectsRoot);

            ScalarHelpers.GetObjectsRootFromGitConfig(enlistment.RepoRoot).ShouldEqual(objectsRoot);

            // Downloading objects should recreate the objects directory
            this.LoadBlobsViaGit(enlistment);

            objectsRoot.ShouldBeADirectory(this.fileSystem);

            // The alternates file shouldn't have changed
            this.AlternatesFileShouldHaveGitObjectsRoot(enlistment);
        }
Exemple #28
0
        [Test] // WorkDirModified
        public async Task ChangedSubmodule_True()
        {
            using (var subRepoDir = new TempDirectory())
                using (var subRepo = CreateRepository(subRepoDir))
                    using (var repoDir = new TempDirectory())
                        using (var repo = CreateRepository(repoDir))
                        {
                            RepositoryHelpers.CommitFile(subRepo, "readme.txt", "content", Author);
                            RepositoryHelpers.AddSubmodule(repo, "sub_name", "sub/path", subRepo);
                            repo.Commit("Add submodule", Author, Author);
                            RepositoryHelpers.UpdateSubmodules(repo);
                            RepositoryHelpers.CommitFile(subRepo, "readme.txt", "content2", Author);
                            RepositoryHelpers.AddSubmodule(repo, "sub_name", "sub/path", subRepo);
                            repo.Commit("Update submodule", Author, Author);
                            var service         = CreatePullRequestService(repo);
                            var repositoryModel = CreateLocalRepositoryModel(repo);

                            var isClean = await service.IsWorkingDirectoryClean(repositoryModel).FirstAsync();

                            Assert.True(isClean);
                        }
        }
 public void DeleteControlRepo()
 {
     RepositoryHelpers.DeleteTestDirectory(this.fastFetchControlRoot);
 }
Exemple #30
0
 // Override OnTearDownEnlistmentsDeleted rathern than using [TearDown] as the enlistments need to be unmounted before
 // localCacheParentPath can be deleted (as the SQLite blob sizes database cannot be deleted while GVFS is mounted)
 protected override void OnTearDownEnlistmentsDeleted()
 {
     RepositoryHelpers.DeleteTestDirectory(this.localCacheParentPath);
 }