public void ValidAppConfig_WithCorrectConfig_ReturnsTrue() { using (AutoMock mock = AutoMock.GetLoose()) { mock.Mock <IGetAppConfig>().Setup(s => s.FindAppConfig()).Returns(new AppConfig(60, true, "D:\\Backups", "123abc", "456def", "#general", "DEV", true, "D:\\LoggingDir")); ValidateAppConfig sut = mock.Create <ValidateAppConfig>(); bool isValid = sut.Validate(); Assert.True(isValid); } }
public void ValidAppConfig_WithNullOrEmptyEnvironment_ReturnsFalse(string environment) { using (AutoMock mock = AutoMock.GetLoose()) { mock.Mock <IGetAppConfig>().Setup(s => s.FindAppConfig()).Returns(new AppConfig(60, true, "D:\\Backups", "123abc", "456def", "#general", environment, true, "D:\\LoggingDir")); ValidateAppConfig sut = mock.Create <ValidateAppConfig>(); bool isValid = sut.Validate(); Assert.False(isValid); } }
public SlackConfigProvider() { ValidateAppConfig validateAppConfig = new ValidateAppConfig(new GetAppConfig()); bool isValid = validateAppConfig.Validate(); if (!isValid) { return; } AppConfig appConfig = new GetAppConfig().FindAppConfig(); AccessCode = appConfig.AccessCode; ChannelName = appConfig.SlackChannel; }
static async Task <int> Main(string[] args) { ValidateAppConfig validateAppConfig = new ValidateAppConfig(new GetAppConfig()); bool isValid = validateAppConfig.Validate(); if (!isValid) { MySlackClient slackClient = new MySlackClient(new SlackConfigProvider()); await slackClient.Send("You're missing your parameters in config.json"); return(1); } AppConfig appConfig = new GetAppConfig().FindAppConfig(); try { FindBackups findBackups = new FindBackups(); await findBackups.DeleteFiles( path : appConfig.BackupDirectory, daysAgoMax : appConfig.MaxDaysAgo, safeMode : appConfig.SafeMode, environment : appConfig.Environment, shouldLogToSlack : appConfig.ShouldLogToSlack, fileSystemLoggingDirectory : appConfig.FileSystemLoggingDirectory); } catch (System.Exception ex) { Console.WriteLine($"Error: {ex.Message}"); Console.WriteLine($"StackTrace: {ex.StackTrace}"); // failed to run return(1); } // ran correctly return(0); }