public void SetRPTSettings_OnException_ExecuteCorrectly() { // Arrange var stringBuilder = new StringBuilder(); var epm = new ShimEPMData().Instance; var spSite = new ShimSPSite { RootWebGet = () => new ShimSPWeb { RegionalSettingsGet = () => { throw new Exception(); } } }.Instance; ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = code => code(); ShimEPMData.AllInstances.UpdateRPTSettingsStringInt32StringOut = UpdateRPTSettings; privateObject.SetFieldOrProperty(StringBuilderFieldName, new StringBuilder()); // Act privateObject.Invoke(SetRPTSettingsMethodName, epm, spSite); var errors = privateObject.GetFieldOrProperty(StringBuilderFieldName) as StringBuilder; // Assert this.ShouldSatisfyAllConditions( () => errors.ShouldNotBeNull(), () => errors.ToString().ShouldNotBeNullOrEmpty(), () => errors.ToString().ShouldContain("Error Updating RPTSettings")); }
public void UpdateResourcePool_OnValidCall_ConfirmResult() { // Arrange var dataTable = CreateDataTable(); var dataRow = dataTable.NewRow(); dataRow[SIDField] = DummyString; dataTable.Rows.Add(dataRow); var list = new ShimSPList { ItemsGet = () => new ShimSPListItemCollection { Add = () => { _listItemAdded = true; return(new ShimSPListItem()); } } }.Instance; var dao = new ShimEPMData().Instance; _privateObj.SetFieldOrProperty(AdUsersProperty, dataTable); _privateObj.SetFieldOrProperty(ListProperty, list); _privateObj.SetFieldOrProperty(DAOProperty, dao); // Act _privateObj.Invoke(UpdateResourcePoolMethod); // Assert this.ShouldSatisfyAllConditions( () => _listItemAdded.ShouldBeTrue(), () => _nonQueryExecuted.ShouldBeTrue()); }
public void CleanTables_BulkInsertFRF_ExecutsCorrectly() { // Arrange var destinationTable = string.Empty; const string ExpectedTableNAme = "FRF"; var bulkInserted = false; var site = new ShimSPSite(); var epmData = new ShimEPMData(); ShimSqlBulkCopy.AllInstances.WriteToServerDataTable = (_, dataTable) => { if (destinationTable == ExpectedTableNAme && dataTable.Rows.Count > 0 && !bulkInserted) { bulkInserted = true; } }; ShimSqlBulkCopy.AllInstances.DestinationTableNameSetString = (_, name) => { destinationTable = name; }; // Act DataScrubber.CleanTables(site, epmData, DummyGuid, ref ErrMsg); // Assert Assert.IsTrue(bulkInserted); }
public void CleanTables_Should_WipeTables() { // Arrange const string WipeReportListIds = "DELETE FROM ReportListIds"; const string WipeRPTWeb = "DELETE FROM RPTWeb"; const string WipeRPTWebGroups = "DELETE FROM RPTWEBGROUPS"; var commandsExecuted = new List <string>(); var site = new ShimSPSite { IDGet = () => DummyGuid }.Instance; var epmData = new ShimEPMData().Instance; ShimDataTable.AllInstances.RowsGet = _ => new ShimDataRowCollection { AddObjectArray = parameters => new ShimDataRow().Instance, CountGet = () => 0, GetEnumerator = () => new List <DataRow>().GetEnumerator() }; ShimSqlCommand.AllInstances.ExecuteNonQuery = instance => { commandsExecuted.Add(instance.CommandText); return(1); }; // Act DataScrubber.CleanTables(site, epmData, DummyGuid, ref ErrMsg); // Assert Assert.IsTrue(commandsExecuted.Contains(WipeReportListIds)); Assert.IsTrue(commandsExecuted.Contains(WipeRPTWeb)); Assert.IsTrue(commandsExecuted.Contains(WipeRPTWebGroups)); }
public void AddORRemoveForeignKey_AddOperationFalse_ExecutesCorrectly() { // Arrange var expectedCommands = new List <string> { "BEGIN TRY " + "WHILE EXISTS(select * from INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE where CONSTRAINT_NAME " + "like 'FK_EPMLIVE_%' AND TABLE_NAME=@tableName) BEGIN DECLARE @cName nvarchar(Max) " + "SELECT @cName = (SELECT TOP 1 [CONSTRAINT_NAME] FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE " + "WHERE CONSTRAINT_NAME LIKE 'FK_EPMLIVE_%' AND TABLE_NAME=@tableName) " + "DECLARE @sql nvarchar(Max) SELECT @sql = 'ALTER TABLE ' + @tableName + ' DROP CONSTRAINT ' + @cName " + "EXEC sp_executesql @sql END END TRY BEGIN CATCH PRINT 'Error Detected' END CATCH", "BEGIN TRY " + "WHILE EXISTS(select * from INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE where CONSTRAINT_NAME like" + " 'FK_EPMLIVE_%' AND TABLE_NAME=@tableName) BEGIN DECLARE @cName nvarchar(Max) " + "SELECT @cName = (SELECT TOP 1 [CONSTRAINT_NAME] FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE " + "WHERE CONSTRAINT_NAME LIKE 'FK_EPMLIVE_%' AND TABLE_NAME=@tableName) " + "DECLARE @sql nvarchar(Max) SELECT @sql = 'ALTER TABLE ' + @tableName + ' DROP CONSTRAINT ' + @cName " + "EXEC sp_executesql @sql END END TRY BEGIN CATCH PRINT 'Error Detected' END CATCH" }; var executedCommands = new List <string>(); var dao = new ShimEPMData { ExecuteNonQuerySqlConnection = _ => true, GetClientReportingConnectionGet = () => new SqlConnection(), Dispose = () => { }, CommandSetString = command => executedCommands.Add(command) }; ShimReportBiz.AllInstances.GetAllForeignKeysEPMData = (_, epmData) => new ShimDataTable { RowsGet = () => new ShimDataRowCollection { GetEnumerator = () => new List <DataRow> { new ShimDataRow { ItemGetString = name => DummyGuid } }.GetEnumerator() } }; var foreignKey = new ShimDataRow { ItemGetString = name => DummyString }; // Act var result = reportBiz.AddORRemoveForeignKey(dao, foreignKey, false); // Assert result.ShouldSatisfyAllConditions( () => result.ShouldBeTrue(), () => expectedCommands.All(p => executedCommands.Contains(p)).ShouldBeTrue()); }
private void DefaultPageInit() { ShimEPMData.ConstructorGuid = (sender, siteGuid) => { _shimDao = new ShimEPMData(sender) { remoteCsGet = () => DummyString, OpenClientReportingConnectionSetString = remoteCs => { }, CommandSetString = commandParam => _actualCommand = commandParam, AddParamStringObject = (nameParam, valueParam) => { }, GetTableSqlConnection = sqlConnection => { var dataTable = new DataTable(); if (_actualCommand == SelectListNameFromRptList) { dataTable.Columns.Add(ListNameField); var row = dataTable.NewRow(); row[ListNameField] = DummyListName; dataTable.Rows.Add(row); } if (_actualCommand == SelectFromTimerJobs) { dataTable.Columns.Add(JobNameField); dataTable.Columns.Add(RunTimeField); dataTable.Columns.Add(ScheduleTypeField); dataTable.Columns.Add(DaysField); dataTable.Columns.Add(JobDataField); var row = dataTable.NewRow(); row[JobNameField] = DummyJobName; row[RunTimeField] = 1; row[ScheduleTypeField] = 2; row[DaysField] = 3; row[JobDataField] = $"{DummyListName},{DummyString}"; dataTable.Rows.Add(row); } return(dataTable); }, GetEPMLiveConnectionGet = () => new ShimSqlConnection(), GetClientReportingConnectionGet = () => new ShimSqlConnection() }; }; _privateObject.Invoke(PageInitMethodName, this, EventArgs.Empty); }
public void HasForeignKey_OnSuccess_ReturnsTrue() { // Arrange var dao = new ShimEPMData { GetClientReportingConnectionGet = () => new SqlConnection(), ExecuteScalarSqlConnection = _ => 1 }.Instance; var args = new object[] { dao, DummyString, DummyString }; // Act var result = (bool)privateObject.Invoke(HasForeignKeyMethodName, args); // Assert result.ShouldBeTrue(); }
public void AddORRemoveForeignKey_AddOperation_ExecutesCorrectly() { // Arrange var expectedCommands = new List <string> { DummyString }; var executedCommands = new List <string>(); var dao = new ShimEPMData { ExecuteNonQuerySqlConnection = _ => true, GetClientReportingConnectionGet = () => new SqlConnection(), Dispose = () => { }, CommandSetString = command => executedCommands.Add(command) }; ShimReportBiz.AllInstances.GetAllForeignKeysEPMData = (_, epmData) => new ShimDataTable { RowsGet = () => new ShimDataRowCollection { GetEnumerator = () => new List <DataRow> { new ShimDataRow { ItemGetString = name => DummyGuid } }.GetEnumerator() } }; var foreignKey = new ShimDataRow { ItemGetString = name => DummyString }; // Act var result = reportBiz.AddORRemoveForeignKey(dao, foreignKey, true); // Assert result.ShouldSatisfyAllConditions( () => result.ShouldBeTrue(), () => expectedCommands.All(p => executedCommands.Contains(p)).ShouldBeTrue()); }
public void PageInit_CatchException_ResponseWrite() { // Arrange ShimEPMData.ConstructorGuid = (sender, siteGuid) => { _shimDao = new ShimEPMData(sender) { remoteCsGet = () => DummyString, OpenClientReportingConnectionSetString = remoteCs => { }, CommandSetString = commandParam => _actualCommand = commandParam, AddParamStringObject = (nameParam, valueParam) => { } }; }; // Act _privateObject.Invoke(PageInitMethodName, this, EventArgs.Empty); // Assert _actualResponseMessage.ToString().ShouldBe("Error: Object reference not set to an instance of an object."); }
public void GetReferencingTables_Should_ExecuteCorrectly() { // Arrange var expectedCommand = $"EXEC sp_MSdependencies N'{DummyString}', null, 1315327"; var commandExecuted = string.Empty; var dao = new ShimEPMData { GetTableSqlConnection = _ => new DataTable(), GetClientReportingConnectionGet = () => new SqlConnection(), Dispose = () => { }, CommandSetString = command => commandExecuted = command }; // Act var result = reportBiz.GetReferencingTables(dao, DummyString); // Assert result.ShouldSatisfyAllConditions( () => result.ShouldNotBeNull(), () => commandExecuted.ShouldNotBeNullOrEmpty(), () => commandExecuted.ShouldBe(expectedCommand)); }
public void CleanTables_Invoke_VerifyMemoryLeak() { // Arrange var sqlCommandConstructorInvoked = 0; var sqlCommandDisposeCalled = 0; var destinationTable = string.Empty; const string ExpectedTableNAme = "ReportListIds"; var bulkInserted = false; var site = new ShimSPSite(); var epmData = new ShimEPMData(); ShimSqlBulkCopy.AllInstances.WriteToServerDataTable = (_, dataTable) => { if (destinationTable == ExpectedTableNAme && dataTable.Rows.Count > 0 && !bulkInserted) { bulkInserted = true; } }; ShimSqlBulkCopy.AllInstances.DestinationTableNameSetString = (_, name) => destinationTable = name; ShimSqlCommand.ConstructorStringSqlConnection = (command, s, arg3) => sqlCommandConstructorInvoked++; ShimComponent.AllInstances.Dispose = component => { if (component is SqlCommand) { sqlCommandDisposeCalled++; } }; // Act DataScrubber.CleanTables(site, epmData, DummyGuid, ref ErrMsg); // Assert this.ShouldSatisfyAllConditions( () => sqlCommandConstructorInvoked.ShouldBeGreaterThanOrEqualTo(7), () => sqlCommandDisposeCalled.ShouldBeGreaterThanOrEqualTo(7), () => sqlCommandDisposeCalled.ShouldBe(sqlCommandConstructorInvoked)); }
public void GetAllForeignKeys_OnException_ExecutesCorrectly() { // Arrange var dao = new ShimEPMData { GetClientReportingConnectionGet = () => new SqlConnection(), GetTableSqlConnection = _ => new ShimDataTable { RowsGet = () => { throw new Exception(); } } }; // Act var result = reportBiz.GetAllForeignKeys(dao); // Assert result.ShouldSatisfyAllConditions( () => result.ShouldNotBeNull(), () => result.Rows.Count.ShouldBe(0)); }
public void PageInit_DropDownListScheduleType3_UpdateProperties() { // Arrange ShimEPMData.ConstructorGuid = (sender, siteGuid) => { _shimDao = new ShimEPMData(sender) { remoteCsGet = () => DummyString, OpenClientReportingConnectionSetString = remoteCs => { }, CommandSetString = commandParam => _actualCommand = commandParam, AddParamStringObject = (nameParam, valueParam) => { }, GetTableSqlConnection = sqlConnection => { var dataTable = new DataTable(); if (_actualCommand == SelectListNameFromRptList) { dataTable.Columns.Add(ListNameField); var row = dataTable.NewRow(); row[ListNameField] = DummyListName; dataTable.Rows.Add(row); } if (_actualCommand == SelectFromTimerJobs) { dataTable.Columns.Add(JobNameField); dataTable.Columns.Add(RunTimeField); dataTable.Columns.Add(ScheduleTypeField); dataTable.Columns.Add(DaysField); dataTable.Columns.Add(JobDataField); var row = dataTable.NewRow(); row[JobNameField] = DummyJobName; row[RunTimeField] = 1; row[ScheduleTypeField] = 3; row[DaysField] = 4; row[JobDataField] = $"{DummyListName},{DummyString}"; dataTable.Rows.Add(row); } return(dataTable); }, GetEPMLiveConnectionGet = () => new ShimSqlConnection(), GetClientReportingConnectionGet = () => new ShimSqlConnection() }; }; // Act _privateObject.Invoke(PageInitMethodName, this, EventArgs.Empty); // Assert LoadFields(); this.ShouldSatisfyAllConditions( () => _labelErrorSite.Visible.ShouldBeFalse(), () => _listBoxLists.Items.Count.ShouldBe(1), () => _listBoxLists.Items[0].Selected.ShouldBeTrue(), () => _dropDownListScheduleType.SelectedValue.ShouldBe("3"), () => _dropDownListDays.SelectedValue.ShouldBe("4"), () => _dropDownListDays.Visible.ShouldBeTrue(), () => _checkBoxListDays.Visible.ShouldBeFalse()); }
public void GetAllForeignKeys_OnSuccess_ExecutesCorrectly() { // Arrange var lookupId = Guid.NewGuid(); var dao = new ShimEPMData { GetClientReportingConnectionGet = () => new SqlConnection(), GetTableSqlConnection = _ => new ShimDataTable { RowsGet = () => new ShimDataRowCollection { GetEnumerator = () => new List <DataRow> { new ShimDataRow { ItemGetString = name => DummyString } }.GetEnumerator() } } }; ShimDataTable.AllInstances.SelectString = (_, query) => new DataRow[] { new ShimDataRow { ItemGetString = name => DummyString } }; ShimSPWeb.AllInstances.ListsGet = _ => new ShimSPListCollection { ItemGetString = name => null, ItemGetGuid = guid => { return(guid == lookupId ? new ShimSPList() : null); } }; ShimSPSite.AllInstances.AllWebsGet = _ => { var list = new List <SPWeb> { new ShimSPWeb { ListsGet = () => new ShimSPListCollection { ItemGetGuid = guid => new ShimSPList(), ItemGetString = name => new ShimSPList() } } }.AsEnumerable(); return(new ShimSPWebCollection().Bind(list)); }; ShimSPList.AllInstances.FieldsGet = _ => new ShimSPFieldCollection { GetFieldByInternalNameString = name => { return(new ShimSPFieldLookup { LookupListGet = () => lookupId.ToString() }.Instance); } }; ShimSPField.AllInstances.TypeAsStringGet = _ => DummyString; ShimSPList.AllInstances.TitleGet = _ => DummyString; // Act var result = reportBiz.GetAllForeignKeys(dao); // Assert result.ShouldSatisfyAllConditions( () => result.ShouldNotBeNull(), () => result.Rows.Count.ShouldBeGreaterThan(0)); }
public void GetSpecificForeignKey_Should_ExecuteCorrectly() { // Arrange var lookupId = Guid.NewGuid(); var dao = new ShimEPMData { GetTableSqlConnection = _ => new DataTable(), GetClientReportingConnectionGet = () => new SqlConnection() }; ShimSPWeb.AllInstances.ListsGet = _ => new ShimSPListCollection { ItemGetGuid = guid => { return(guid == lookupId ? new ShimSPList() : null); } }; ShimSPSite.AllInstances.AllWebsGet = _ => { var list = new List <SPWeb> { new ShimSPWeb { ListsGet = () => new ShimSPListCollection { ItemGetGuid = guid => new ShimSPList() } } }.AsEnumerable(); return(new ShimSPWebCollection().Bind(list)); }; ShimReportBiz.AllInstances.HasForeignKeyEPMDataStringString = (_, reportData, table, column) => true; ShimDataTable.AllInstances.RowsGet = _ => new ShimDataRowCollection { CountGet = () => 1, ItemGetInt32 = index => new ShimDataRow { ItemGetString = name => DummyString }, GetEnumerator = () => new List <DataRow> { new ShimDataRow { ItemGetString = name => DummyString } }.GetEnumerator() }; ShimSPList.AllInstances.FieldsGet = _ => new ShimSPFieldCollection { GetFieldByInternalNameString = name => new ShimSPFieldLookup { LookupListGet = () => lookupId.ToString() } }; ShimSPField.AllInstances.TypeAsStringGet = _ => DummyString; // Act var result = reportBiz.GetSpecificForeignKey(dao, DummyGuid.ToString(), DummyString, DummyString); // Assert result.ShouldSatisfyAllConditions( () => result.ShouldNotBeNull(), () => result.Rows.Count.ShouldBeGreaterThan(0)); }