handle add column request (#1272)

* handle add column request

* comments

* rename data to ViewModel
This commit is contained in:
Alan Ren
2021-10-19 09:54:57 -07:00
committed by GitHub
parent 791c3594a9
commit 192f7fccd4
18 changed files with 310 additions and 83 deletions

View File

@@ -0,0 +1,30 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts;
using NUnit.Framework;
using Newtonsoft.Json;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TableDesigner
{
public class TableColumnCollectionTest
{
[Test]
public void AutoNameForNewItemTest()
{
var collection = new TableColumnCollection();
collection.AddNew();
Assert.AreEqual(1, collection.Data.Count, "The item count should be 1");
Assert.AreEqual("column1", collection.Data[0].Name.Value);
collection.Data.Add(new TableColumnViewModel() { Name = new InputBoxProperties() { Value = "column3" } });
Assert.AreEqual(2, collection.Data.Count, "The item count should be 2");
collection.AddNew();
Assert.AreEqual(3, collection.Data.Count, "The item count should be 3");
// the name that is not yet used should be picked
Assert.AreEqual("column2", collection.Data[2].Name.Value);
}
}
}

View File

@@ -0,0 +1,30 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts;
using NUnit.Framework;
using Newtonsoft.Json;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TableDesigner
{
public class TableDesignerChangeInfoTest
{
[Test]
public void DeserializeTableChangeProperty()
{
string testJsonStringType = "{\"type\": 1, \"property\": \"columns\"}";
TableDesignerChangeInfo changeInfo = JsonConvert.DeserializeObject<TableDesignerChangeInfo>(testJsonStringType);
Assert.IsNotNull(changeInfo, "string property: the changeInfo shouldn't be null.");
Assert.IsNotNull(changeInfo.Property, "string property: the property shouldn't be null.");
Assert.IsTrue(changeInfo.Property.GetType() == typeof(string));
string testJsonObjectType = "{\"type\": 1, \"property\": {\"parentProperty\": \"columns\",\"index\": 0,\"property\": \"length\"}}";
changeInfo = JsonConvert.DeserializeObject<TableDesignerChangeInfo>(testJsonObjectType);
Assert.IsNotNull(changeInfo, "object property: the changeInfo shouldn't be null.");
Assert.IsNotNull(changeInfo.Property, "object property: the property shouldn't be null.");
Assert.IsTrue(changeInfo.Property.GetType() == typeof(TableDesignerPropertyIdentifier));
}
}
}