public async Task JunctionExistsInParentAtRuntime_ShouldDisableWrite() { var junction = Path.Combine(_testDir, "junction"); var dataDir = Path.Combine(junction, "data"); // setup var mockFileProvider = new Mock <IAppDataFileProvider>(MockBehavior.Loose); mockFileProvider.Setup(p => p.DisableWrite()).Verifiable(); var controller = new AppDataController(dataDir, TimeSpan.FromMilliseconds(1000), mockFileProvider.Object); await RunControllerWithActionAsync(controller, 500, 500, () => { // create the junction TestUtility.RunWindowsCommand($"mklink /j \"{junction}\" \"{_targetDir}\"", _output); // create the data directory Directory.CreateDirectory(dataDir); }); try { // make sure DisableWrite is called mockFileProvider.Verify(p => p.DisableWrite(), Times.AtLeastOnce); } finally { // delete the junction first to make sure clean-up doesn't fail Directory.Delete(junction); } }
public void JunctionExistsInSubDirOnStartup_ShouldDisableWrite(int depth) { // create data dir var dataDir = Path.Combine(_testDir, "data"); Directory.CreateDirectory(dataDir); // create the junction as sub-directory var junctionPath = dataDir; for (var i = 0; i < depth; i++) { junctionPath = Path.Combine(junctionPath, $"sub{i}"); Directory.CreateDirectory(junctionPath); } var junction = Path.Combine(junctionPath, "junction"); TestUtility.RunWindowsCommand($"mklink /j \"{junction}\" \"{_targetDir}\"", _output); try { // setup var mockFileProvider = new Mock <IAppDataFileProvider>(MockBehavior.Loose); mockFileProvider.Setup(p => p.DisableWrite()).Verifiable(); var controller = new AppDataController(dataDir, TimeSpan.FromMilliseconds(1000), mockFileProvider.Object); // make sure DisableWrite is called mockFileProvider.Verify(p => p.DisableWrite(), Times.Once); } finally { // delete the junction first to make sure clean-up doesn't fail Directory.Delete(junction); } }
/// <summary> /// Start the controller, wait for <paramref name="period1Ms"/>, execute the action, wait for <paramref name="period2Ms"/>, then stop controller. /// </summary> private static async Task RunControllerWithActionAsync(AppDataController controller, int period1Ms, int period2Ms, Action action) { using var cts = new CancellationTokenSource(); await controller.StartAsync(cts.Token); await Task.Delay(period1Ms); action.Invoke(); await Task.Delay(period2Ms); cts.Cancel(); await controller.StopAsync(default);
public async Task JunctionNotExist_ShouldNotDisableWrite() { // setup var mockFileProvider = new Mock <IAppDataFileProvider>(MockBehavior.Loose); mockFileProvider.Setup(p => p.DisableWrite()).Verifiable(); var controller = new AppDataController(_targetDir, TimeSpan.FromMilliseconds(100), mockFileProvider.Object); // make sure DisableWrite is not called in constructor mockFileProvider.Verify(p => p.DisableWrite(), Times.Never); // start the controller routine and wait for some time await RunControllerWithActionAsync(controller, 1000, 0, () => { }); // make sure DisableWrite is not called during runtime mockFileProvider.Verify(p => p.DisableWrite(), Times.Never); }
public async Task SymlinkExist_ShouldNotDisableWrite() { // create symlink var symlinkDir = Path.Combine(_testDir, "symlink"); TestUtility.RunWindowsCommand($"mklink /D \"{symlinkDir}\" \"{_targetDir}\"", _output); // setup var mockFileProvider = new Mock <IAppDataFileProvider>(MockBehavior.Loose); mockFileProvider.Setup(p => p.DisableWrite()).Verifiable(); var controller = new AppDataController(symlinkDir, TimeSpan.FromMilliseconds(100), mockFileProvider.Object); // make sure DisableWrite is not called in constructor mockFileProvider.Verify(p => p.DisableWrite(), Times.Never); // start the controller routine and wait for some time await RunControllerWithActionAsync(controller, 1000, 0, () => { }); // make sure DisableWrite is not called during runtime mockFileProvider.Verify(p => p.DisableWrite(), Times.Never); }
public void JunctionExistsAtStartup_ShouldDisableWrite() { // create the junction var junction = Path.Combine(_testDir, "junction"); TestUtility.RunWindowsCommand($"mklink /j \"{junction}\" \"{_targetDir}\"", _output); try { // setup var mockFileProvider = new Mock <IAppDataFileProvider>(MockBehavior.Loose); mockFileProvider.Setup(p => p.DisableWrite()).Verifiable(); var controller = new AppDataController(junction, TimeSpan.FromMilliseconds(1000), mockFileProvider.Object); // make sure DisableWrite is called mockFileProvider.Verify(p => p.DisableWrite(), Times.Once); } finally { // delete the junction first to make sure clean-up doesn't fail Directory.Delete(junction); } }
public void MyTestInitialize() { this.target = new AppDataController(); this.contact = new Contact { Email = "*****@*****.**", ID = 1, Website = "www.test.org", Phone = "9373608284", HelpLine = "9373608888" }; this.state = new State { Abbreviation = "OH", CountryID = 1, FullName = "Ohio", ID = 1 }; this.location1 = new Location { City = "testville 1", ContactID = 1, Contact = this.contact, ContactPersonID = 1, ID = 1, Display = true, Zip = 45344, Street = "Test way 1", State = this.state, StateID = this.state.ID }; this.location2 = new Location { City = "testville 2", ContactID = 2, Contact = this.contact, ContactPersonID = 2, ID = 2, Display = true, Zip = 45344, Street = "Test way 2", State = this.state, StateID = this.state.ID }; this.locations = new List <Location> { this.location1, this.location2 }; this.websiteAddress1 = string.Format( "{0}, {1}, {2}, {3}", this.location1.Street, this.location1.City, this.location1.State.Abbreviation, this.location1.Zip); this.websiteAddress2 = string.Format( "{0}, {1}, {2}, {3}", this.location2.Street, this.location2.City, this.location2.State.Abbreviation, this.location2.Zip); var providerService11 = new ProviderService { ID = 1, ProviderID = 1, ServiceID = 1 }; var providerService12 = new ProviderService { ID = 2, ProviderID = 1, ServiceID = 2 }; var providerService13 = new ProviderService { ID = 3, ProviderID = 1, ServiceID = 3 }; var providerService21 = new ProviderService { ID = 1, ProviderID = 2, ServiceID = 1 }; var providerService22 = new ProviderService { ID = 2, ProviderID = 2, ServiceID = 2 }; var providerService23 = new ProviderService { ID = 3, ProviderID = 2, ServiceID = 3 }; this.providerServices1 = new List <ProviderService> { providerService11, providerService12, providerService13, }; this.providerServices2 = new List <ProviderService> { providerService21, providerService22, providerService23 }; this.serviceProvider1 = new ServiceProvider { Description = "Test description for test 1", ID = 1, DisplayRank = 1, ProviderName = "Test 1", Locations = this.locations, ProviderServices = this.providerServices1 }; this.serviceProvider2 = new ServiceProvider { Description = "Test description for test 2", ID = 2, DisplayRank = 2, ProviderName = "Test 2", Locations = this.locations, ProviderServices = this.providerServices2 }; this.serviceProviderList = new List <ServiceProvider> { this.serviceProvider1, this.serviceProvider2 }; }
public void TestInitialize() { this.target = new AppDataController(); }