// 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.Base.IO;
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()
{
// Setup
var mockRepository = new MockRepository();
var inquiryHelper = mockRepository.Stub();
mockRepository.ReplayAll();
// Call
TestDelegate test = () => new GuiUpdateHandler(null, Enumerable.Empty(), inquiryHelper);
// Assert
string paramName = Assert.Throws(test).ParamName;
Assert.AreEqual("dialogParent", paramName);
mockRepository.VerifyAll();
}
[Test]
public void Constructor_WithoutUpdateInfos_ThrowsArgumentNullException()
{
// Setup
var mockRepository = new MockRepository();
var mainWindow = mockRepository.Stub();
var inquiryHelper = mockRepository.Stub();
mockRepository.ReplayAll();
// Call
TestDelegate test = () => new GuiUpdateHandler(mainWindow, null, inquiryHelper);
// Assert
string paramName = Assert.Throws(test).ParamName;
Assert.AreEqual("updateInfos", paramName);
mockRepository.VerifyAll();
}
[Test]
public void Constructor_WithoutInquiryHelper_ThrowsArgumentNullException()
{
// Setup
var mockRepository = new MockRepository();
var mainWindow = mockRepository.Stub();
mockRepository.ReplayAll();
// Call
TestDelegate test = () => new GuiUpdateHandler(mainWindow, Enumerable.Empty(), null);
// Assert
string paramName = Assert.Throws(test).ParamName;
Assert.AreEqual("inquiryHelper", paramName);
mockRepository.VerifyAll();
}
[Test]
public void CanUpdateOn_HasNoFileUpdatersForTarget_ReturnFalse()
{
// Setup
var mocks = new MockRepository();
var dialogParent = mocks.Stub();
var inquiryHelper = mocks.Stub();
mocks.ReplayAll();
var commandHandler = new GuiUpdateHandler(dialogParent, Enumerable.Empty(), inquiryHelper);
// Call
bool isUpdatePossible = commandHandler.CanUpdateOn(new object());
// Assert
Assert.IsFalse(isUpdatePossible);
mocks.VerifyAll();
}
[Test]
public void CanUpdateOn_HasOneUpdateInfoForTarget_ReturnTrue()
{
// Setup
var target = new object();
var mocks = new MockRepository();
var dialogParent = mocks.Stub();
var inquiryHelper = mocks.Stub();
mocks.ReplayAll();
var commandHandler = new GuiUpdateHandler(dialogParent, new UpdateInfo[]
{
new UpdateInfo