public async Task ListUpstreamMultiple()
        {
            using (var dir = new SelfDeletingDirectory(Path.GetFullPath(Path.Combine(basePath, nameof(this.ListUpstreamMultiple)))))
            {
                var upstreamPath   = Path.Combine(dir.Path, "Upstream");
                var authorPath     = Path.Combine(dir.Path, "Author");
                var downstreamPath = Path.Combine(dir.Path, "Downstream");
                var identity       = new Identity("Test Bot", "*****@*****.**");

                Repository.Init(upstreamPath, true);
                Repository.Clone(upstreamPath, authorPath);
                using (var repo = new Repository(authorPath))
                {
                    var testFilePath = Path.Combine(dir.Path, "Author/test.txt");
                    File.WriteAllText(testFilePath, "Some test data.");
                    Commands.Stage(repo, testFilePath);
                    var signature = new Signature(identity, DateTime.Now);
                    repo.Commit("Added test data", signature, signature);

                    //Sync main branch
                    var syncRepo = new SyncRepository(repo, mockup.Get <ICommitRepository>(), mockup.Get <IGitCredentialsProvider>(), mockup.Get <IProcessRunner>());
                    await syncRepo.Push();

                    var authorBranchRepo = new BranchRepository(repo, mockup.Get <ICommitRepository>());

                    //Create side branch
                    authorBranchRepo.Add("sidebranch");
                    authorBranchRepo.Checkout("sidebranch", new Signature(identity, DateTime.Now));
                    File.WriteAllText(testFilePath, "Some test data sidebranch.");
                    Commands.Stage(repo, testFilePath);
                    signature = new Signature(identity, DateTime.Now);
                    repo.Commit("Added test data", signature, signature);
                    await syncRepo.Push();

                    //Create another branch
                    authorBranchRepo.Add("another");
                    authorBranchRepo.Checkout("another", new Signature(identity, DateTime.Now));
                    File.WriteAllText(testFilePath, "Some test data another.");
                    Commands.Stage(repo, testFilePath);
                    signature = new Signature(identity, DateTime.Now);
                    repo.Commit("Added test data", signature, signature);
                    await syncRepo.Push();
                }

                Repository.Clone(upstreamPath, downstreamPath);
                using (var repo = new Repository(downstreamPath))
                {
                    var branchRepo = new BranchRepository(repo, mockup.Get <ICommitRepository>());
                    var branches   = branchRepo.List();
                    Assert.Equal(3, branches.Items.Count());
                }
            }
        }
        public void GetCurrentNonMaster()
        {
            using (var dir = new SelfDeletingDirectory(Path.GetFullPath(Path.Combine(basePath, nameof(this.GetCurrentNonMaster)))))
            {
                Repository.Init(dir.Path, false);
                using (var repo = new Repository(dir.Path))
                {
                    var testFilePath = Path.Combine(dir.Path, "test.txt");
                    File.WriteAllText(testFilePath, "Some test data.");
                    Commands.Stage(repo, testFilePath);
                    var identity  = new Identity("Test Bot", "*****@*****.**");
                    var signature = new Signature(identity, DateTime.Now);
                    repo.Commit("Added test data", signature, signature);

                    var branchRepo = new BranchRepository(repo, mockup.Get <ICommitRepository>());

                    branchRepo.Add("side");
                    branchRepo.Checkout("side", new Signature(identity, DateTime.Now));

                    var current = branchRepo.GetCurrent();
                    Assert.Equal("side", current.FriendlyName);
                    Assert.Equal("refs/heads/side", current.CanonicalName);
                }
            }
        }
        public void IsRepositoryAddsBranch()
        {
            Branch branchToInsert = new Branch {
                Id = 1, BranchName = "Anushka Sales", BranchAddress = "Kamptee Road, Indora Square", BranchCity = "Nagpur", BranchPinCode = 440014
            };

            repo.Add(branchToInsert);
            var result = repo.FindById(1);

            Assert.IsNotNull(result);
        }
Beispiel #4
0
        //Add Data
        public bool Add(Branch objBranch)
        {
            var isAdded = false;

            isAdded = _branchReository.Add(objBranch);
            if (isAdded)
            {
                return(true);
            }
            return(isAdded);
        }
Beispiel #5
0
 public void Add(Branch branch)
 {
     try
     {
         branchRepository.Add(branch);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #6
0
        public ActionResult Create([Bind(Include = "BranchCode,BranchName,BranchLocation")] Branch branch)
        {
            if (ModelState.IsValid)
            {
                _db.Add(branch);

                return(RedirectToAction("Index"));
            }

            return(View(branch));
        }
        public void ListCreated()
        {
            using (var dir = new SelfDeletingDirectory(Path.GetFullPath(Path.Combine(basePath, nameof(this.ListCreated)))))
            {
                Repository.Init(dir.Path, false);
                using (var repo = new Repository(dir.Path))
                {
                    var testFilePath = Path.Combine(dir.Path, "test.txt");
                    File.WriteAllText(testFilePath, "Some test data.");
                    Commands.Stage(repo, testFilePath);
                    var signature = new Signature("Test Bot", "*****@*****.**", DateTime.Now);
                    repo.Commit("Added test data", signature, signature);

                    var branchRepo = new BranchRepository(repo, mockup.Get <ICommitRepository>());

                    branchRepo.Add("side");
                    branchRepo.Add("anotherbranch");

                    var branches = branchRepo.List();
                    Assert.Equal(3, branches.Items.Count());
                }
            }
        }
        public void UnableToCheckout()
        {
            using (var dir = new SelfDeletingDirectory(Path.GetFullPath(Path.Combine(basePath, nameof(this.UnableToCheckout)))))
            {
                Repository.Init(dir.Path, false);
                using (var repo = new Repository(dir.Path))
                {
                    var testFilePath = Path.Combine(dir.Path, "test.txt");
                    File.WriteAllText(testFilePath, "Some test data.");
                    Commands.Stage(repo, testFilePath);
                    var identity  = new Identity("Test Bot", "*****@*****.**");
                    var signature = new Signature(identity, DateTime.Now);
                    repo.Commit("Added test data", signature, signature);

                    var commitRepo = new Mock <ICommitRepository>();
                    commitRepo.Setup(i => i.HasUncommittedChanges()).Returns(true);
                    var branchRepo = new BranchRepository(repo, commitRepo.Object);

                    branchRepo.Add("side");
                    Assert.Throws <InvalidOperationException>(() => branchRepo.Checkout("side", new Signature(identity, DateTime.Now)));
                }
            }
        }
        public async Task UpstreamWithCheckout()
        {
            using (var dir = new SelfDeletingDirectory(Path.GetFullPath(Path.Combine(basePath, nameof(this.UpstreamWithCheckout)))))
            {
                var upstreamPath              = Path.Combine(dir.Path, "Upstream");
                var authorPath                = Path.Combine(dir.Path, "Author");
                var downstreamPath            = Path.Combine(dir.Path, "Downstream");
                var contents                  = "Main Branch";
                var sideContents              = "Side branch";
                var sideContentsRemoteChanges = "Side branch remote changes";
                var identity                  = new Identity("Test Bot", "*****@*****.**");

                Repository.Init(upstreamPath, true);
                Repository.Clone(upstreamPath, authorPath);
                using (var repo = new Repository(authorPath))
                {
                    var testFilePath = Path.Combine(dir.Path, "Author/test.txt");

                    //Create some test data on master
                    File.WriteAllText(testFilePath, contents);
                    Commands.Stage(repo, testFilePath);
                    var sig = new Signature(identity, DateTime.Now);
                    repo.Commit("Added test data", sig, sig);

                    //Switch to side branch, and make update
                    var authorBranchRepo = new BranchRepository(repo, mockup.Get <ICommitRepository>());
                    authorBranchRepo.Add("sidebranch");
                    authorBranchRepo.Checkout("sidebranch", new Signature(identity, DateTime.Now));
                    File.WriteAllText(testFilePath, sideContents);
                    Commands.Stage(repo, testFilePath);
                    sig = new Signature(identity, DateTime.Now);
                    repo.Commit("Updated branch data", sig, sig);
                    var syncRepo = new SyncRepository(repo, mockup.Get <ICommitRepository>(), mockup.Get <IGitCredentialsProvider>(), mockup.Get <IProcessRunner>());
                    //Push side branch
                    await syncRepo.Push();

                    //Back to master
                    authorBranchRepo.Checkout("master", new Signature(identity, DateTime.Now));
                    String masterText = File.ReadAllText(testFilePath);
                    Assert.Equal(contents, masterText);
                    await syncRepo.Push();
                }

                Repository.Clone(upstreamPath, downstreamPath);
                using (var repo = new Repository(downstreamPath))
                {
                    var testFilePath = Path.Combine(dir.Path, "Downstream/test.txt");
                    var branchRepo   = new BranchRepository(repo, mockup.Get <ICommitRepository>());

                    //First check master
                    String masterText = File.ReadAllText(testFilePath);
                    Assert.Equal(contents, masterText);

                    //Swith to side branch and check
                    branchRepo.Checkout("sidebranch", new Signature(identity, DateTime.Now));
                    String sideText = File.ReadAllText(testFilePath);
                    Assert.Equal(sideContents, sideText);

                    //Now make some changes and send them back
                    File.WriteAllText(testFilePath, sideContentsRemoteChanges);
                    Commands.Stage(repo, testFilePath);
                    var sig = new Signature(identity, DateTime.Now);
                    repo.Commit("Updated branch remotely", sig, sig);

                    var syncRepo = new SyncRepository(repo, mockup.Get <ICommitRepository>(), mockup.Get <IGitCredentialsProvider>(), mockup.Get <IProcessRunner>());
                    await syncRepo.Push();
                }

                using (var repo = new Repository(authorPath))
                {
                    var syncRepo = new SyncRepository(repo, mockup.Get <ICommitRepository>(), mockup.Get <IGitCredentialsProvider>(), mockup.Get <IProcessRunner>());
                    await syncRepo.Pull(new Signature(identity, DateTime.Now));

                    var testFilePath = Path.Combine(dir.Path, "Author/test.txt");
                    var branchRepo   = new BranchRepository(repo, mockup.Get <ICommitRepository>());
                    branchRepo.Checkout("sidebranch", new Signature(identity, DateTime.Now));

                    String text = File.ReadAllText(testFilePath);
                    Assert.Equal(sideContentsRemoteChanges, text);
                }
            }
        }