// Copyright (C) Stichting Deltares 2016. All rights reserved.
//
// This file is part of Ringtoets.
//
// Ringtoets is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System;
using System.Linq;
using System.Windows.Forms;
using Core.Common.Gui.Commands;
using Core.Common.Gui.Forms.MainWindow;
using Core.Common.Gui.Plugin;
using NUnit.Extensions.Forms;
using NUnit.Framework;
using Rhino.Mocks;
namespace Core.Common.Gui.Test.Commands
{
[TestFixture]
public class GuiUpdateHandlerTest : NUnitFormTest
{
[Test]
public void Constructor_WithoutDialogParent_ThrowsArgumentNullException()
{
// Call
TestDelegate test = () => new GuiUpdateHandler(null, Enumerable.Empty());
// Assert
string paramName = Assert.Throws(test).ParamName;
Assert.AreEqual("dialogParent", paramName);
}
[Test]
public void Constructor_WithoutUpdateInfos_ThrowsArgumentNullException()
{
// Setup
var mockRepository = new MockRepository();
var mainWindow = mockRepository.Stub();
mockRepository.ReplayAll();
// Call
TestDelegate test = () => new GuiUpdateHandler(mainWindow, null);
// Assert
string paramName = Assert.Throws(test).ParamName;
Assert.AreEqual("updateInfos", paramName);
mockRepository.VerifyAll();
}
[Test]
public void UpdateOn_NoUpdaterAvailable_GivesMessageBox()
{
// Setup
var mockRepository = new MockRepository();
var mainWindow = mockRepository.Stub();
mockRepository.ReplayAll();
string messageBoxTitle = null, messageBoxText = null;
DialogBoxHandler = (name, wnd) =>
{
var messageBox = new MessageBoxTester(wnd);
messageBoxText = messageBox.Text;
messageBoxTitle = messageBox.Title;
messageBox.ClickOk();
};
var importHandler = new GuiUpdateHandler(mainWindow, Enumerable.Empty());
// Call
importHandler.UpdateOn(typeof(long));
// Assert
Assert.AreEqual("Fout", messageBoxTitle);
Assert.AreEqual("Geen enkele 'Updater' is beschikbaar voor dit element.", messageBoxText);
mockRepository.VerifyAll();
}
[Test]
public void UpdateOn_NoSupportedUpdateInfoAvailable_GivesMessageBox()
{
// Setup
var mockRepository = new MockRepository();
var mainWindow = mockRepository.Stub();
mockRepository.ReplayAll();
string messageBoxTitle = null, messageBoxText = null;
DialogBoxHandler = (name, wnd) =>
{
var messageBox = new MessageBoxTester(wnd);
messageBoxText = messageBox.Text;
messageBoxTitle = messageBox.Title;
messageBox.ClickOk();
};
var importHandler = new GuiUpdateHandler(mainWindow, new UpdateInfo[]
{
new UpdateInfo()
});
// Call
importHandler.UpdateOn(typeof(long));
// Assert
Assert.AreEqual("Fout", messageBoxTitle);
Assert.AreEqual("Geen enkele 'Updater' is beschikbaar voor dit element.", messageBoxText);
mockRepository.VerifyAll();
}
[Test]
public void CanUpdateOn_HasNoFileUpdatersForTarget_ReturnFalse()
{
// Setup
var mocks = new MockRepository();
var dialogParent = mocks.Stub();
mocks.ReplayAll();
var commandHandler = new GuiUpdateHandler(dialogParent, Enumerable.Empty());
// Call
bool isImportPossible = commandHandler.CanUpdateOn(new object());
// Assert
Assert.IsFalse(isImportPossible);
mocks.VerifyAll();
}
[Test]
public void CanUpdateOn_HasOneUpdateInfoForTarget_ReturnTrue()
{
// Setup
var target = new object();
var mocks = new MockRepository();
var dialogParent = mocks.Stub();
mocks.ReplayAll();
var commandHandler = new GuiUpdateHandler(dialogParent, new UpdateInfo[]
{
new UpdateInfo