Files
Karl Burtram f288bee294 Make nullable warnings a per file opt-in (#1842)
* Make nullable warnings a per file opt-in

* Remove unneeded compiler directives

* Remove compiler directive for User Data
2023-02-03 18:10:07 -08:00

69 lines
3.2 KiB
C#

//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
#nullable disable
using System;
using Microsoft.SqlTools.ServiceLayer.TableDesigner;
using Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TableDesigner
{
public class DesignerPathUtilsTest
{
[Test]
public void ParseDesignerPathTest()
{
DesignerEditType editType = DesignerEditType.Add;
this.RunTest(new object[] { "property1" }, editType, false);
this.RunTest(new object[] { "property1", 1, "property2" }, editType, false);
this.RunTest(new object[] { "property1", "xx", "property2" }, editType, false);
this.RunTest(new object[] { "property1", 1 }, editType, true);
this.RunTest(new object[] { "property1", 1, "property2", 1 }, editType, true);
this.RunTest(new object[] { "property1", 1, "property2", 1, "property3" }, editType, false);
this.RunTest(new object[] { }, editType, false);
this.RunTest(null, editType, false);
editType = DesignerEditType.Remove;
this.RunTest(new object[] { "property1", 0 }, editType, true);
this.RunTest(new object[] { "property1", 1, "property2", 1 }, editType, true);
this.RunTest(new object[] { "property1" }, editType, false);
this.RunTest(new object[] { "property1", 1, "property2" }, editType, false);
this.RunTest(new object[] { "property1", 1, "property2", 1, "property3", 1 }, editType, false);
this.RunTest(new object[] { }, editType, false);
this.RunTest(null, editType, false);
editType = DesignerEditType.Update;
this.RunTest(new object[] { "property1" }, editType, true);
this.RunTest(new object[] { "property1", 1, "property2" }, editType, true);
this.RunTest(new object[] { "property1", 1, "property2", 1, "property3" }, editType, true);
this.RunTest(new object[] { "property1", "abc" }, editType, false);
this.RunTest(new object[] { "property1", 1, "property2", 1 }, editType, false);
this.RunTest(new object[] { "property1", 1, "property2", 1, "property3", 2, "property4" }, editType, false);
this.RunTest(new object[] { }, editType, false);
this.RunTest(null, editType, false);
}
private void RunTest(object[] path, DesignerEditType editType, bool isValidPath)
{
if (isValidPath)
{
Assert.DoesNotThrow(() =>
{
DesignerPathUtils.Validate(path, editType);
}, string.Format("Path '{0}' should be a valid path for edit type: '{1}'.", path, editType.ToString()));
}
else
{
Assert.Throws<ArgumentException>(() =>
{
DesignerPathUtils.Validate(path, editType);
}, string.Format("Path '{0}' should not be a valid path for edit type: '{1}'.", path, editType.ToString()));
}
}
}
}