// 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 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 General Public License for more details.
//
// You should have received a copy of the GNU 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 Application.Ringtoets.Storage.Create;
using Application.Ringtoets.Storage.DbContext;
using NUnit.Framework;
using Ringtoets.Common.Data.Probability;
namespace Application.Ringtoets.Storage.Test.Create
{
[TestFixture]
public class ProbabilisticAssessmentOutputCreateExtensionsTest
{
[Test]
public void Create_PersistenceRegistryNull_ThrowArgumentNullException()
{
// Setup
var output = new ProbabilityAssessmentOutput(1, 1, 1, 1, 1);
// Call
TestDelegate call = () => output.Create(null);
// AssertL
string paramName = Assert.Throws(call).ParamName;
Assert.AreEqual("registry", paramName);
}
[Test]
public void Create_ValidValues_ReturnProbabilisticOutputEntity()
{
// Setup
var random = new Random(456);
var output = new ProbabilityAssessmentOutput(random.NextDouble(), random.NextDouble(),
random.NextDouble(), random.NextDouble(),
random.NextDouble());
var registry = new PersistenceRegistry();
// Call
ProbabilisticOutputEntity entity = output.Create(registry);
// Assert
Assert.AreEqual(output.FactorOfSafety.Value, entity.FactorOfSafety);
Assert.AreEqual(output.Probability, entity.Probability);
Assert.AreEqual(output.Reliability.Value, entity.Reliability);
Assert.AreEqual(output.RequiredProbability, entity.RequiredProbability);
Assert.AreEqual(output.RequiredReliability.Value, entity.RequiredReliability);
}
[Test]
public void Create_NaNValues_ReturnProbabilisticOutputEntityWithNullValues()
{
// Setup
var output = new ProbabilityAssessmentOutput(double.NaN, double.NaN, Double.NaN,
double.NaN, double.NaN);
var registry = new PersistenceRegistry();
// Call
ProbabilisticOutputEntity entity = output.Create(registry);
// Assert
Assert.IsNull(entity.FactorOfSafety);
Assert.IsNull(entity.Probability);
Assert.IsNull(entity.Reliability);
Assert.IsNull(entity.RequiredProbability);
Assert.IsNull(entity.RequiredReliability);
}
[Test]
public void Create_ValidValues_RegistersEntity()
{
// Setup
var output = new ProbabilityAssessmentOutput(1,1,1,1,1);
var registry = new PersistenceRegistry();
// Call
ProbabilisticOutputEntity entity = output.Create(registry);
// Assert
entity.ProbabilisticOutputEntityId = 948576;
registry.TransferIds();
Assert.AreEqual(entity.ProbabilisticOutputEntityId, output.StorageId);
}
}
}