public void ConvertToDataTable_ValidCollection_ShouldReturnDataTableFilledWithData()
        {
            //arrange
            var collection = FakeCollectionData.GetTestData();

            //act
            var result = _collectionToDataTableConverter.ConvertToDataTable(collection);

            //assert

            // check rows and columns count
            result.Rows.Count.Should().Be(2);
            result.Columns.Count.Should().Be(2);

            //check columns names
            result.Columns[0].ColumnName.Should().Be("Id");
            result.Columns[1].ColumnName.Should().Be("Name");

            //check rows values
            result.Rows[0].ItemArray[0].Should().Be(collection.First().Id);
            result.Rows[0].ItemArray[1].Should().Be(collection.First().Name);

            result.Rows[1].ItemArray[0].Should().Be(collection.Last().Id);
            result.Rows[1].ItemArray[1].Should().Be(collection.Last().Name);
        }
Exemplo n.º 2
0
        public void BuildUserDefinedTableTypeParameter_ValidInput_ShouldCreateSqlParameter()
        {
            //arrange
            var parameterName  = "FalconMilleniumCrew";
            var parameterValue = FakeCollectionData.GetTestData();
            //act
            var result = _sqlParameterFactory.BuildUserDefinedTableTypeParameter(parameterName, parameterValue);
            var parameterValueAsDataTable = result.Value as DataTable;

            //assert
            result.ParameterName.Should().Be($"@{parameterName}");
            result.SqlDbType.Should().Be(SqlDbType.Structured);

            parameterValueAsDataTable.Rows.Count.Should().Be(2);
            parameterValueAsDataTable.Columns.Count.Should().Be(2);

            parameterValueAsDataTable.Columns[0].ColumnName.Should().Be("Id");
            parameterValueAsDataTable.Columns[1].ColumnName.Should().Be("Name");
        }
Exemplo n.º 3
0
        public void WithUserDefinedDataTableSqlParam_CorrectInput_ShouldCreateParameter()
        {
            //arrange
            var paramName = "Parameter";

            //act
            var result = _storedProcedure.WithUserDefinedDataTableSqlParam(paramName, FakeCollectionData.GetTestData());

            //assert
            result.Should().NotBeNull();
            result.StoredProcedureText.Should().Be("uspHighPerformatStoredProcedure @Parameter");
            result.SqlParametersCollection[0].ParameterName.Should().Be("@Parameter");
            result.SqlParametersCollection.Count.Should().Be(1);

            var parameterValueAsDataTable = result.SqlParametersCollection[0].Value as DataTable;

            parameterValueAsDataTable.Rows.Count.Should().Be(2);
            parameterValueAsDataTable.Columns.Count.Should().Be(2);

            parameterValueAsDataTable.Columns[0].ColumnName.Should().Be("Id");
            parameterValueAsDataTable.Columns[1].ColumnName.Should().Be("Name");
        }