public void GetDatetime_ReturnTheCurrentTime() { var service = new DatetimeService(); var expected = DateTime.Now; var actual = service.GetDateTime(); Assert.Equal(expected.DayOfWeek, actual.DayOfWeek); }
public async Task ItShouldReturnTheMatchingAccountWithTransaction() { var id = "123"; var accountDetailViewModel = new AccountDetailViewModel { AccountId = 123, Balance = 0m, PayeSchemes = new ResourceList( new List <ResourceViewModel> { new ResourceViewModel { Id = "123/123456", Href = "https://tempuri.org/payescheme/{1}" } }), LegalEntities = new ResourceList( new List <ResourceViewModel> { new ResourceViewModel { Id = "TempUri Limited", Href = "https://tempuri.org/organisation/{1}" } }), HashedAccountId = "DFGH", DateRegistered = DateTime.Today.AddYears(-2), OwnerEmail = "*****@*****.**", DasAccountName = "Test Account 1" }; AccountApiClient.Setup(x => x.GetResource <AccountDetailViewModel>($"/api/accounts/{id}")) .ReturnsAsync(accountDetailViewModel); var obscuredPayePayeScheme = "123/123456"; PayeSchemeObfuscator.Setup(x => x.ObscurePayeScheme(It.IsAny <string>())) .Returns(obscuredPayePayeScheme); var payeSchemeViewModel = new PayeSchemeViewModel { AddedDate = DateTime.Today.AddMonths(-4), Ref = "123/123456", Name = "123/123456", DasAccountId = "123", RemovedDate = null }; AccountApiClient.Setup(x => x.GetResource <PayeSchemeViewModel>(It.IsAny <string>())) .ReturnsAsync(payeSchemeViewModel); /* * This is a testing HACK to avoid using a concrete datetime service * because our collegues used DateTime.Now in the code! * See ASCS-83 for a fix */ var now = DateTime.Now.Date; var startOfFirstFinancialYear = new DateTime(2017, 4, 1); var monthsToQuery = (now.Year - startOfFirstFinancialYear.Year) * 12 + (now.Month - startOfFirstFinancialYear.Month) + 1; DatetimeService.Setup(x => x.GetBeginningFinancialYear(startOfFirstFinancialYear)) .Returns(startOfFirstFinancialYear); var isNotZero = 100m; var isTxDateCreated = DateTime.Today; var transactionsViewModel = new TransactionsViewModel { new TransactionViewModel { Description = "Is Not Null", Amount = isNotZero, DateCreated = isTxDateCreated }, new TransactionViewModel { Description = "Is Not Null 2", Amount = isNotZero, DateCreated = isTxDateCreated } }; AccountApiClient.Setup(x => x.GetTransactions(accountDetailViewModel.HashedAccountId, It.IsAny <int>(), It.IsAny <int>())) .ReturnsAsync(transactionsViewModel ); var actual = await _sut.Get(id, AccountFieldsSelection.Finance); Logger.Verify(x => x.Debug(It.IsAny <string>()), Times.Exactly(2)); PayeSchemeObfuscator .Verify(x => x.ObscurePayeScheme(It.IsAny <string>()), Times.Exactly(2)); AccountApiClient .Verify(x => x.GetTransactions(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>()), Times.Exactly(monthsToQuery)); Assert.IsNotNull(actual); Assert.IsNotNull(actual.PayeSchemes); Assert.AreEqual(1, actual.PayeSchemes.Count()); Assert.IsNotNull(actual.Transactions); Assert.AreEqual(2 * monthsToQuery, actual.Transactions.Count()); Assert.IsNull(actual.LegalEntities); Assert.IsNull(actual.TeamMembers); }
public void Init() { _sut = new DatetimeService(); }
public void Setup() { _unit = new DatetimeService(); }
static void Main(string[] args) { ConsumeEventSync objsync = new ConsumeEventSync(); IConfiguration config = new ConfigurationBuilder() .AddJsonFile("appsettings.json", true, true) .Build(); //de 24 em 24 horas executa esta task começando as 10:20 TaskScheduler.Instance.ScheduleTask(10, 20, 24, () => { objsync.UpdateWeatherConditionsForAllActiveNodes(); objsync.UpdateHistoryEvaporationForAllActiveCounties(); }); // DE 30 EM 30 min TEMPO VER OS PARAMETROS QUE ESTAO NA BASE DE DADOS E COMPRAR COM AS METRICAS E COM ISSO LIGAR OU NAO O SISTEMA DE REGA TaskScheduler.Instance.ScheduleTask(10, 20, 0.5, () => { MetricsComparisonLogicService metricsService = new MetricsComparisonLogicService(); List <List <Read_Hourly> > activeNodesWith24HoursReadings = objsync.GetWeatherConditionsForAllActiveNodes(); foreach (var node in activeNodesWith24HoursReadings) { #region AlertRegion List <double> temperaturesOfANode = node.Select(x => (double)x.Temperature).ToList(); List <double> pressureOfANode = node.Select(x => (double)x.Pres).ToList(); List <double> precipitationOfANode = node.Select(x => (double)x.Prcp).ToList(); List <double> humidityOfANode = node.Select(x => (double)x.Rhum).ToList(); List <string> Errors = new List <string>(); string MailBody = string.Empty; if (MathService.getOutliers(temperaturesOfANode).Count > 0) { MathService.getOutliers(temperaturesOfANode).ForEach(x => temperaturesOfANode.Remove(x)); MailBody += $"There is a error found on Temperature sensor in {node.Select(z => z.IdNode).FirstOrDefault()} \n"; Errors.Add(MailBody); } if (MathService.getOutliers(pressureOfANode).Count > 0) { MathService.getOutliers(pressureOfANode).ForEach(x => pressureOfANode.Remove(x)); MailBody += $"There is a error found on Pressure sensor in {node.Select(z => z.IdNode).FirstOrDefault()} \n"; Errors.Add(MailBody); } if (MathService.getOutliers(precipitationOfANode).Count > 0) { MathService.getOutliers(precipitationOfANode).ForEach(x => precipitationOfANode.Remove(x)); MailBody += $"There is a error found on Precipitation sensor in {node.Select(z => z.IdNode).FirstOrDefault()}\n"; Errors.Add(MailBody); } if (MathService.getOutliers(humidityOfANode).Count > 0) { MathService.getOutliers(humidityOfANode).ForEach(x => humidityOfANode.Remove(x)); MailBody += $"There is a error found on Humidity sensor in {node.Select(z => z.IdNode).FirstOrDefault()}\n"; Errors.Add(MailBody); } if (Errors.Count > 0) { EmailSevice.SendEmail(MailBody, node.Select(z => z.IdNode).FirstOrDefault()); } #endregion RootWeatherForecast <Daily> forecast = objsync.GetWeatherForecast(); float EvapoTranspirationForLast30Days = objsync.GetEvapoTranspirationForLast30Days(node.Select(z => z.IdNode).FirstOrDefault()); int timeSprinklerActivated = 0; if (EvapoTranspirationForLast30Days <= float.Parse(config["Evapotranspiracao:Humida"], CultureInfo.InvariantCulture.NumberFormat)) { timeSprinklerActivated = int.Parse(config["TempoDeRegaEmMin:Humida"], CultureInfo.InvariantCulture.NumberFormat); } if (EvapoTranspirationForLast30Days > float.Parse(config["Evapotranspiracao:Humida"], CultureInfo.InvariantCulture.NumberFormat) && EvapoTranspirationForLast30Days <= float.Parse(config["Evapotranspiracao:SubHumida"])) { timeSprinklerActivated = int.Parse(config["TempoDeRegaEmMin:SubHumida"], CultureInfo.InvariantCulture.NumberFormat); } if (EvapoTranspirationForLast30Days > float.Parse(config["Evapotranspiracao:SubHumida"], CultureInfo.InvariantCulture.NumberFormat) && EvapoTranspirationForLast30Days <= float.Parse(config["Evapotranspiracao:SubHumidaSeca"])) { timeSprinklerActivated = int.Parse(config["TempoDeRegaEmMin:SubHumidaSeca"], CultureInfo.InvariantCulture.NumberFormat); } if (EvapoTranspirationForLast30Days > float.Parse(config["Evapotranspiracao:SubHumidaSeca"], CultureInfo.InvariantCulture.NumberFormat)) { timeSprinklerActivated = int.Parse(config["TempoDeRegaEmMin:Semiarida"], CultureInfo.InvariantCulture.NumberFormat); } //Checks The temperature if (metricsService.IsTheTemperatureOkToSprinkle(activeNodesWith24HoursReadings)) { DateTime sunset = DatetimeService.UnixTimeStampToDateTime( double.Parse(forecast.Daily.FirstOrDefault().Sunset)); DateTime sunrise = DatetimeService.UnixTimeStampToDateTime( double.Parse(forecast.Daily.FirstOrDefault().Sunrise)); //checks if the time that is running is after sunset and before sunrise if (DateTime.Now < sunrise && DateTime.Now > sunset) { if (!forecast.Daily.FirstOrDefault().Weather.FirstOrDefault().Main.ToLower() .Contains("rain") || !forecast.Daily.FirstOrDefault().Weather.FirstOrDefault().Main.ToLower() .Contains("rain")) { //activate sprinkler objsync.ActivateSprinkler(node.Select(z => z.IdNode).FirstOrDefault()); Thread.Sleep(timeSprinklerActivated * 60 * 1000); objsync.DeactivateSprinkler(node.Select(z => z.IdNode).FirstOrDefault()); } } } } }); }