public void Should_be_possible_to_collect_FileEffectiveRights() { // Arrange WmiObject fakeWmiObject = new WmiObject(); fakeWmiObject.Add("Descriptor.DACL.AccessMask", (uint)128); fakeWmiObject.Add("Descriptor.DACL.AceFlags", (uint)123); fakeWmiObject.Add("Descriptor.DACL.Trustee.SID", "{500}"); fakeWmiObject.Add("Descriptor.DACL.Trustee.Domain", "mss"); fakeWmiObject.Add("Descriptor.DACL.Trustee.Name", "lfernandes"); MockRepository mocks = new MockRepository(); WmiDataProvider fakeWmiDataProvider = mocks.DynamicMock <WmiDataProvider>(); Expect.Call(fakeWmiDataProvider.InvokeMethodByWmiPath(null)).IgnoreArguments().Return(new WmiObject[] { fakeWmiObject }); FileEffectiveRightsObjectCollector fileEffectiveRightsSysDataSource = new FileEffectiveRightsObjectCollector(); fileEffectiveRightsSysDataSource.WmiDataProvider = fakeWmiDataProvider; mocks.ReplayAll(); // Act IEnumerable <CollectedItem> collectedItem = fileEffectiveRightsSysDataSource.CollectDataForSystemItem(this.getFakeFileItem()); Assert.IsNotNull(collectedItem, "The return of collect data cannot be null"); Assert.AreEqual(1, collectedItem.Count(), "Unexpected collected items count."); Assert.IsNotNull(collectedItem.ElementAt(0).ItemType, "The file item cannot be null."); Assert.IsInstanceOfType(collectedItem.ElementAt(0).ItemType, typeof(fileeffectiverights_item), "The item of collected item must be file_item"); fileeffectiverights_item collectedFileEffectiveRights = (fileeffectiverights_item)collectedItem.ElementAt(0).ItemType; Assert.AreEqual("{500}", collectedFileEffectiveRights.trustee_sid.Value, "Unexpected item value."); Assert.AreEqual("1", collectedFileEffectiveRights.file_read_attributes.Value, "Unexpected file attribute found."); this.AssertFileEffectiveRight(collectedFileEffectiveRights.file_append_data, false, "file_append_data"); this.AssertFileEffectiveRight(collectedFileEffectiveRights.file_delete_child, false, "file_delete_child"); this.AssertFileEffectiveRight(collectedFileEffectiveRights.file_execute, false, "file_execute"); this.AssertFileEffectiveRight(collectedFileEffectiveRights.file_read_data, false, "file_read_data"); this.AssertFileEffectiveRight(collectedFileEffectiveRights.file_read_ea, false, "file_read_ea"); this.AssertFileEffectiveRight(collectedFileEffectiveRights.file_write_attributes, false, "file_write_attributes"); this.AssertFileEffectiveRight(collectedFileEffectiveRights.file_write_data, false, "file_write_data"); this.AssertFileEffectiveRight(collectedFileEffectiveRights.file_write_ea, false, "file_write_ea"); this.AssertFileEffectiveRight(collectedFileEffectiveRights.generic_all, true, "generic_all"); this.AssertFileEffectiveRight(collectedFileEffectiveRights.generic_execute, true, "generic_execute"); this.AssertFileEffectiveRight(collectedFileEffectiveRights.generic_read, true, "generic_read"); this.AssertFileEffectiveRight(collectedFileEffectiveRights.generic_write, false, "generic_write"); this.AssertFileEffectiveRight(collectedFileEffectiveRights.standard_delete, false, "standard_delete"); this.AssertFileEffectiveRight(collectedFileEffectiveRights.standard_read_control, false, "standard_delete"); this.AssertFileEffectiveRight(collectedFileEffectiveRights.standard_synchronize, false, "standard_sync"); this.AssertFileEffectiveRight(collectedFileEffectiveRights.standard_write_dac, false, "standard_write_dac"); this.AssertFileEffectiveRight(collectedFileEffectiveRights.standard_write_owner, false, "standard_write_owner"); }
private FileEffectiveRightsProber createMockedFileEffectiveRightsProber(IEnumerable <CollectedItem> fakeCollectedItems) { MockRepository mocks = new MockRepository(); IConnectionManager fakeConnectionManager = mocks.DynamicMock <IConnectionManager>(); ISystemInformationService fakeSysInfoService = mocks.DynamicMock <ISystemInformationService>(); FileConnectionProvider fakeProvider = mocks.DynamicMock <FileConnectionProvider>(); FileEffectiveRightsObjectCollector fakeSystemDataSource = mocks.DynamicMock <FileEffectiveRightsObjectCollector>(); Expect.Call(fakeSystemDataSource.CollectDataForSystemItem(null)).IgnoreArguments().Return(fakeCollectedItems); mocks.ReplayAll(); return(new FileEffectiveRightsProber() { ConnectionManager = fakeConnectionManager, ObjectCollector = fakeSystemDataSource }); }