2020-12-20 08:36:11 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core;
|
2016-11-07 19:12:09 +01:00
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core
|
2016-11-07 19:12:09 +01:00
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class AttemptTests
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void AttemptIf()
|
|
|
|
|
{
|
2020-12-20 08:36:11 +01:00
|
|
|
// Just making sure that it is ok to use TryParse as a condition.
|
|
|
|
|
var attempt = Attempt.If(int.TryParse("1234", out int value), value);
|
2016-11-07 19:12:09 +01:00
|
|
|
Assert.IsTrue(attempt.Success);
|
|
|
|
|
Assert.AreEqual(1234, attempt.Result);
|
|
|
|
|
|
|
|
|
|
attempt = Attempt.If(int.TryParse("12xxx34", out value), value);
|
|
|
|
|
Assert.IsFalse(attempt.Success);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|