Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs =================================================================== diff -u -r99a9ff7746c6c38cfe963c8702fd386b34f98701 -r91f159bc90faf3c55a62ae1441e9ff2bc6fd180b --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs (.../StorageSqLiteIntegrationTest.cs) (revision 99a9ff7746c6c38cfe963c8702fd386b34f98701) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs (.../StorageSqLiteIntegrationTest.cs) (revision 91f159bc90faf3c55a62ae1441e9ff2bc6fd180b) @@ -1,8 +1,11 @@ using System; using System.IO; using Core.Common.Base.Data; +using Core.Common.Gui; +using Core.Common.Gui.Forms.MainWindow; using Core.Common.TestUtil; using NUnit.Framework; +using Rhino.Mocks; using Ringtoets.Integration.Data; namespace Application.Ringtoets.Storage.Test.IntegrationTests @@ -95,6 +98,93 @@ Assert.AreNotSame(project, loadedProject); } + [Test] + [STAThread] + public void GivenRingtoetsGuiWithStorageSql_WhenRunWithValidFile_ProjectSet() + { + // Setup + var testFile = Path.Combine(testDataPath, "ValidRingtoetsDatabase.rtd"); + var projectStore = new StorageSqLite(); + + using (var gui = new RingtoetsGui(new MainWindow(), projectStore)) + { + // Call + Action action = () => gui.Run(testFile); + + // Assert + var expectedMessages = new[] + { + "Openen van bestaand Ringtoetsproject.", + "Bestaand Ringtoetsproject succesvol geopend.", + }; + TestHelper.AssertLogMessagesAreGenerated(action, expectedMessages, 13); + Assert.AreEqual(testFile, gui.ProjectFilePath); + Assert.NotNull(gui.Project); + Assert.AreEqual("ValidRingtoetsDatabase", gui.Project.Name); + Assert.AreEqual("Test description", gui.Project.Description); + CollectionAssert.IsEmpty(gui.Project.Items); + } + } + + [Test] + [STAThread] + public void GivenRingtoetsGuiWithStorageSql_WhenRunWithInvalidFile_EmptyProjectSet() + { + // Setup + var testFile = "SomeFile"; + var projectStore = new StorageSqLite(); + + using (var gui = new RingtoetsGui(new MainWindow(), projectStore)) + { + // Call + Action action = () => gui.Run(testFile); + + // Assert + var expectedMessages = new[] + { + "Openen van bestaand Ringtoetsproject.", + string.Format("Fout bij het lezen van bestand '{0}': ", testFile), + "Het is niet gelukt om het Ringtoetsproject te laden.", + "Nieuw project aanmaken..." + }; + TestHelper.AssertLogMessagesAreGenerated(action, expectedMessages, 15); + Assert.AreEqual(null, gui.ProjectFilePath); + Assert.NotNull(gui.Project); + Assert.AreEqual("Project", gui.Project.Name); + Assert.IsEmpty(gui.Project.Description); + CollectionAssert.IsEmpty(gui.Project.Items); + } + } + + [Test] + [STAThread] + [TestCase(null)] + [TestCase("")] + [TestCase(" ")] + public void GivenRingtoetsGuiWithStorageSql_WhenRunWithEmptyFile_EmptyProjectSet(string testFile) + { + // Setup + var projectStore = new StorageSqLite(); + + using (var gui = new RingtoetsGui(new MainWindow(), projectStore)) + { + // Call + Action action = () => gui.Run(testFile); + + // Assert + var expectedMessages = new[] + { + "Nieuw project aanmaken..." + }; + TestHelper.AssertLogMessagesAreGenerated(action, expectedMessages, 12); + Assert.AreEqual(null, gui.ProjectFilePath); + Assert.NotNull(gui.Project); + Assert.AreEqual("Project", gui.Project.Name); + Assert.IsEmpty(gui.Project.Description); + CollectionAssert.IsEmpty(gui.Project.Items); + } + } + private void TearDownTempRingtoetsFile(string filePath) { GC.Collect();