Skip to content

Commit b0c3e05

Browse files
committed
More unit tests
1 parent 5b208ae commit b0c3e05

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

RubberduckTests/SourceControl/BranchesViewModelTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,5 +761,39 @@ public void OnCreateBranch_WhenCreateFails_ActionFailedEventIsRaised()
761761
//assert
762762
Assert.IsTrue(wasRaised, "ActionFailedEvent was not raised.");
763763
}
764+
765+
[TestMethod]
766+
public void PublishPublishesBranch()
767+
{
768+
//arrange
769+
var branch = "dev";
770+
var vm = new BranchesViewViewModel
771+
{
772+
Provider = _provider.Object
773+
};
774+
775+
//act
776+
vm.PublishBranchToolbarButtonCommand.Execute(branch);
777+
778+
//Assert
779+
_provider.Verify(git => git.Publish(branch));
780+
}
781+
782+
[TestMethod]
783+
public void UnpublishUnpublishesBranch()
784+
{
785+
//arrange
786+
var branch = "master";
787+
var vm = new BranchesViewViewModel
788+
{
789+
Provider = _provider.Object
790+
};
791+
792+
//act
793+
vm.UnpublishBranchToolbarButtonCommand.Execute(branch);
794+
795+
//Assert
796+
_provider.Verify(git => git.Unpublish(branch));
797+
}
764798
}
765799
}

RubberduckTests/SourceControl/ChangesViewModelTests.cs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,6 @@ public void ExcludeFileExcludesFile()
260260
Assert.AreEqual(1, vm.ExcludedChanges.Count);
261261
}
262262

263-
// I need to figure out how to make this throw.
264-
[Ignore]
265263
[TestMethod]
266264
public void ChangesPresenter_WhenCommitFails_ActionFailedEventIsRaised()
267265
{
@@ -278,6 +276,12 @@ public void ChangesPresenter_WhenCommitFails_ActionFailedEventIsRaised()
278276
}
279277
};
280278

279+
_providerMock.Setup(p => p.Commit(It.IsAny<string>()))
280+
.Throws(
281+
new SourceControlException("A source control exception was thrown.",
282+
new LibGit2Sharp.LibGit2SharpException("With an inner libgit2sharp exception"))
283+
);
284+
281285
var wasRaised = false;
282286

283287
vm.ErrorThrown += (e, sender) => wasRaised = true;
@@ -288,5 +292,35 @@ public void ChangesPresenter_WhenCommitFails_ActionFailedEventIsRaised()
288292
//assert
289293
Assert.IsTrue(wasRaised, "ActionFailedEvent was not raised.");
290294
}
295+
296+
[TestMethod]
297+
public void UndoUndoesChanges()
298+
{
299+
//arrange
300+
var fileStatusEntries = new List<FileStatusEntry>
301+
{
302+
new FileStatusEntry(@"C:\path\to\module.bas", FileStatus.Modified),
303+
new FileStatusEntry(@"C:\path\to\class.cls", FileStatus.Unaltered),
304+
new FileStatusEntry(@"C:\path\to\added.bas", FileStatus.Added | FileStatus.Modified),
305+
new FileStatusEntry(@"C:\path\to\addedUnmodified.bas", FileStatus.Added),
306+
new FileStatusEntry(@"C:\path\to\untracked.frx", FileStatus.Untracked)
307+
};
308+
309+
var vm = new ChangesViewViewModel
310+
{
311+
Provider = _providerMock.Object
312+
};
313+
314+
var localLocation = "C:\\users\\desktop\\git\\";
315+
316+
_providerMock.Setup(git => git.Status()).Returns(fileStatusEntries);
317+
_providerMock.SetupGet(git => git.CurrentRepository).Returns(new Repository{LocalLocation = localLocation});
318+
319+
//act
320+
vm.UndoChangesToolbarButtonCommand.Execute(fileStatusEntries[0]);
321+
322+
//Assert
323+
_providerMock.Verify(git => git.Undo(localLocation + fileStatusEntries[0].FilePath));
324+
}
291325
}
292326
}

0 commit comments

Comments
 (0)