mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-17 02:51:45 -05:00
Adding EditCell constructor validation (#301)
* New unit tests! * New CopyTo method! * New null validation! YEAH!!!
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
|
using Microsoft.SqlTools.Utility;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.EditData.Contracts
|
namespace Microsoft.SqlTools.ServiceLayer.EditData.Contracts
|
||||||
{
|
{
|
||||||
@@ -24,11 +25,10 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.Contracts
|
|||||||
/// <param name="isDirty">Whether or not the edit cell is dirty</param>
|
/// <param name="isDirty">Whether or not the edit cell is dirty</param>
|
||||||
public EditCell(DbCellValue dbCellValue, bool isDirty)
|
public EditCell(DbCellValue dbCellValue, bool isDirty)
|
||||||
{
|
{
|
||||||
IsDirty = isDirty;
|
Validate.IsNotNull(nameof(dbCellValue), dbCellValue);
|
||||||
|
dbCellValue.CopyTo(this);
|
||||||
|
|
||||||
DisplayValue = dbCellValue.DisplayValue;
|
IsDirty = isDirty;
|
||||||
IsNull = dbCellValue.IsNull;
|
|
||||||
RawObject = dbCellValue.RawObject;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
using Microsoft.SqlTools.Utility;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -24,5 +26,18 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
|
|||||||
/// The raw object for the cell, for use internally
|
/// The raw object for the cell, for use internally
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal object RawObject { get; set; }
|
internal object RawObject { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Copies the values of this DbCellValue into another DbCellValue (or child object)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="other">The DbCellValue (or child) that will receive the values</param>
|
||||||
|
public virtual void CopyTo(DbCellValue other)
|
||||||
|
{
|
||||||
|
Validate.IsNotNull(nameof(other), other);
|
||||||
|
|
||||||
|
other.DisplayValue = DisplayValue;
|
||||||
|
other.IsNull = IsNull;
|
||||||
|
other.RawObject = RawObject;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
//
|
||||||
|
// 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.EditData.Contracts;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||||
|
{
|
||||||
|
public class EditCellTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void ConstructNullDbCell()
|
||||||
|
{
|
||||||
|
// If: I construct an EditCell with a null DbCellValue
|
||||||
|
// Then: It should throw
|
||||||
|
Assert.Throws<ArgumentNullException>(() => new EditCell(null, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ConstructValid()
|
||||||
|
{
|
||||||
|
// Setup: Create a DbCellValue to copy the values from
|
||||||
|
DbCellValue source = new DbCellValue
|
||||||
|
{
|
||||||
|
DisplayValue = "qqq",
|
||||||
|
IsNull = true,
|
||||||
|
RawObject = 12
|
||||||
|
};
|
||||||
|
|
||||||
|
// If: I construct an EditCell with a valid DbCellValue
|
||||||
|
EditCell ec = new EditCell(source, true);
|
||||||
|
|
||||||
|
// Then:
|
||||||
|
// ... The values I provided in the DbCellValue should be present
|
||||||
|
Assert.Equal(source.DisplayValue, ec.DisplayValue);
|
||||||
|
Assert.Equal(source.IsNull, ec.IsNull);
|
||||||
|
Assert.Equal(source.RawObject, ec.RawObject);
|
||||||
|
|
||||||
|
// ... The is dirty value I set should be present
|
||||||
|
Assert.True(ec.IsDirty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
//
|
||||||
|
// 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.QueryExecution.Contracts;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||||
|
{
|
||||||
|
public class DbCellValueTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void ConstructValid()
|
||||||
|
{
|
||||||
|
// If: I construct a new DbCellValue
|
||||||
|
DbCellValue dbc = new DbCellValue
|
||||||
|
{
|
||||||
|
DisplayValue = "qqq",
|
||||||
|
IsNull = true,
|
||||||
|
RawObject = 12
|
||||||
|
};
|
||||||
|
|
||||||
|
// Then: It should have the values I specified in it
|
||||||
|
Assert.Equal("qqq", dbc.DisplayValue);
|
||||||
|
Assert.Equal(12, dbc.RawObject);
|
||||||
|
Assert.True(dbc.IsNull);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CopyToNullOther()
|
||||||
|
{
|
||||||
|
// If: I copy a DbCellValue to null
|
||||||
|
// Then: I should get an exception
|
||||||
|
Assert.Throws<ArgumentNullException>(() => new DbCellValue().CopyTo(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CopyToValid()
|
||||||
|
{
|
||||||
|
// If: I copy a DbCellValue to another DbCellValue
|
||||||
|
DbCellValue source = new DbCellValue {DisplayValue = "qqq", IsNull = true, RawObject = 12};
|
||||||
|
DbCellValue dest = new DbCellValue();
|
||||||
|
source.CopyTo(dest);
|
||||||
|
|
||||||
|
// Then: The source values should be in the dest
|
||||||
|
Assert.Equal(source.DisplayValue, dest.DisplayValue);
|
||||||
|
Assert.Equal(source.IsNull, dest.IsNull);
|
||||||
|
Assert.Equal(source.RawObject, dest.RawObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user