public void Test_TryParseStringToTime_Given_Hours_Returns_True(string inputTime) { var parser = new TimeStringParser(); var result = parser.TryParse(inputTime, out TimeSpan outputTime); Assert.True(result); }
public void ParseShouldIdentify12HourPMPatternAndReturnCorrectResult() { var parser = new TimeStringParser(); var result = parser.Parse("10:12:55 PM"); Assert.AreEqual(GetSerialNumber(22, 12, 55), result); }
public void Test_TryParseStringToTime_Given_Null_Returns_False() { var parser = new TimeStringParser(); var result = parser.TryParse(null, out TimeSpan parsedTime); Assert.False(result); }
/// <summary> /// Get the records and filter by a given predicate /// </summary> /// <param name="filter">The filter to apply</param> /// <param name="start">The start record</param> /// <param name="pageSize">The page size</param> /// <param name="ago">The time in the past to search e.g. 10m, 1h, etc.</param> /// <returns>The records filtered</returns> public IEnumerable <T> GetRecordsByFilter(Func <T, bool> filter, int start, int pageSize, string ago) { bool CombineFilter(T x) => filter(x) && x.Timestamp >= TimeStringParser.GetTimeAgo(ago); var items = GetRecordsByFilter(CombineFilter); return(items.Page(start, pageSize)); }
/// <summary> /// Get the records and filter by a given predicate and time in the past /// </summary> /// <param name="filter">The filter to apply</param> /// <param name="ago">The time in the past to search e.g. 10m, 1h, etc.</param> /// <returns>The records filtered</returns> public IEnumerable <T> GetRecordsByFilter(Func <T, bool> filter, string ago) { var utcTime = new DateTimeOffset(TimeStringParser.GetTimeAgo(ago), TimeSpan.Zero); bool CombineFilter(T x) => filter(x) && x.Timestamp >= utcTime; return(GetAllRecords().Where(CombineFilter)); }
public void given_time_string_parser_get_time_ago_when_value_does_not_contain_valid_time_type_string_then_an_exception_is_thrown() { // Arrange // Act Action act = () => TimeStringParser.GetTimeAgo("1"); // Assert act.Should().Throw <ArgumentException>().WithMessage("Time ago value '1' is invalid. Values must be in the format of 1m, 1h, 1d.*"); }
/// <summary> /// Get the records and filter by a given predicate and time in the past /// </summary> /// <param name="filter">The filter to apply</param> /// <param name="start">The start record</param> /// <param name="pageSize">The page size</param> /// <param name="ago">The time in the past to search e.g. 10m, 1h, etc.</param> /// <returns>The records filterted</returns> public async Task <IEnumerable <T> > GetRecordsByFilterAsync(Func <T, bool> filter, int start, int pageSize, string ago) { bool CombineFilter(T x) => filter(x) && x.Timestamp >= TimeStringParser.GetTimeAgo(ago); var allRecords = GetAllRecords(); var data = allRecords.Where(CombineFilter).Page(start, pageSize); return(await Task.FromResult(data)); }
public void given_time_string_parser_get_time_ago_when_value_contains_additional_characters_after_the_valid_time_then_an_exception_is_thrown() { // Arrange // Act Action act = () => TimeStringParser.GetTimeAgo("1hdfyskdhfkds"); // Assert act.Should().Throw <ArgumentException>().WithMessage("Time ago value '1hdfyskdhfkds' is invalid. Values must be in the format of 1m, 1h, 1d.\r\nParameter Name: ago"); }
public void CanParseShouldHandleValid12HourPatterns() { var parser = new TimeStringParser(); Assert.IsTrue(parser.CanParse("10:12:55 AM"), "Could not parse 10:12:55 AM"); Assert.IsTrue(parser.CanParse("9:12:55 PM"), "Could not parse 9:12:55 PM"); Assert.IsTrue(parser.CanParse("7 AM"), "Could not parse 7 AM"); Assert.IsTrue(parser.CanParse("4:12 PM"), "Could not parse 4:12 PM"); }
public void CanParseShouldHandleValid24HourPatterns() { var parser = new TimeStringParser(); Assert.IsTrue(parser.CanParse("10:12:55"), "Could not parse 10:12:55"); Assert.IsTrue(parser.CanParse("22:12:55"), "Could not parse 13:12:55"); Assert.IsTrue(parser.CanParse("13"), "Could not parse 13"); Assert.IsTrue(parser.CanParse("13:12"), "Could not parse 13:12"); }
public async Task <IEnumerable <T> > GetByRowKeyAsync(string rowKey, string ago) { EnsureRowKey(rowKey); var utcTime = new DateTimeOffset(TimeStringParser.GetTimeAgo(ago), TimeSpan.Zero); var queryResults = CloudTable.QueryAsync <T>(x => x.RowKey == rowKey && x.Timestamp >= utcTime); return(await queryResults.ToListAsync()); }
public void given_time_string_parser_get_time_ago_when_value_contains_additional_characters_after_the_valid_time_then_an_exception_is_thrown() { // Arrange var invalidAgo = "1hiudadlj"; // Act Action act = () => TimeStringParser.GetTimeAgo(invalidAgo); // Assert act.Should().Throw <ArgumentException>().WithMessage($"Time ago value '{invalidAgo}' is invalid. Values must be in the format of 1m, 1h, 1d.*"); }
/// <summary> /// Get the records and filter by a given predicate /// </summary> /// <param name="filter">The filter to apply</param> /// <param name="start">The start record</param> /// <param name="pageSize">The page size</param> /// <param name="ago">The time in the past to search e.g. 10m, 1h, etc.</param> /// <returns>The records filtered</returns> public IEnumerable <T> GetRecordsByFilter(Func <T, bool> filter, int start, int pageSize, string ago) { var utcTime = new DateTimeOffset(TimeStringParser.GetTimeAgo(ago), TimeSpan.Zero); bool CombineFilter(T x) => filter(x) && x.Timestamp >= utcTime; var items = GetRecordsByFilter(CombineFilter); return(items.Page(start, pageSize)); }
/// <summary> /// Build the row key table query /// </summary> /// <param name="rowKey">The row key</param> /// <param name="ago">The time in the past to search e.g. 10m, 1h, etc.</param> /// <returns>The table query</returns> private static TableQuery <T> BuildGetByRowKeyAndTimeQuery(string rowKey, string ago) { var utcTime = new DateTimeOffset(TimeStringParser.GetTimeAgo(ago), TimeSpan.Zero); var query = new TableQuery <T>().Where(TableQuery.CombineFilters(TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, rowKey), TableOperators.And, TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.GreaterThanOrEqual, utcTime))); return(query); }
public void given_time_string_parser_get_time_ago_when_30s_then_the_result_is_30_seconds_in_the_past(string ago) { // Arrange var expected = new DateTime(2018, 01, 01, 08, 9, 30); // Act var result = TimeStringParser.GetTimeAgo(ago); // Assert result.Should().Be(expected); }
public void given_time_string_parser_get_time_ago_when_1d_then_the_result_is_1_day_in_the_past(string ago) { // Arrange var expected = new DateTime(2017, 12, 31, 08, 10, 00); // Act var result = TimeStringParser.GetTimeAgo(ago); // Assert result.Should().Be(expected); }
public void Test_TryParseStringToTime_Given_Hours_Returns_Matching_TimeSpan(string inputTime) { string formattedInput = "01:00:00"; var expected = TimeSpan.Parse(formattedInput); var parser = new TimeStringParser(); TimeSpan result; parser.TryParse(inputTime, out result); Assert.Equal(expected, result); }
public void Test_TryParseStringToTime_Given_HHMMSS_Returns_True(string inputTime) { string formattedInput = "01:02:03"; var expected = TimeSpan.Parse(formattedInput); var parser = new TimeStringParser(); TimeSpan result; parser.TryParse(inputTime, out result); Assert.Equal(expected, result); }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { var parser = new TimeStringParser(); var inputString = value.ToString(); if (!parser.TryParse(inputString, out TimeSpan time)) { return(null); } return(time); }
/// <summary> /// Get the records and filter by a given predicate and time in the past /// </summary> /// <param name="filter">The filter to apply</param> /// <param name="start">The start record</param> /// <param name="pageSize">The page size</param> /// <param name="ago">The time in the past to search e.g. 10m, 1h, etc.</param> /// <returns>The records filtered</returns> public async Task <IEnumerable <T> > GetRecordsByFilterAsync(Func <T, bool> filter, int start, int pageSize, string ago) { var utcTime = new DateTimeOffset(TimeStringParser.GetTimeAgo(ago), TimeSpan.Zero); bool CombineFilter(T x) => filter(x) && x.Timestamp >= utcTime; var allRecords = await GetAllRecordsAsync(); var data = allRecords.Where(CombineFilter).Page(start, pageSize); return(data); }
/// <summary> /// Get the records and filter by a given predicate via observable /// </summary> /// <param name="filter">The filter to apply</param> /// <param name="start">The start record</param> /// <param name="pageSize">The page size</param> /// <param name="ago">The time in the past to search e.g. 10m, 1h, etc.</param> /// <returns>The observable for the results</returns> public IObservable <T> GetRecordsByFilterObservable(Func <T, bool> filter, int start, int pageSize, string ago) { bool CombineFilter(T x) => filter(x) && x.Timestamp >= TimeStringParser.GetTimeAgo(ago); return(Observable.Create <T>(o => { foreach (var result in GetAllRecords().Where(CombineFilter).Page(start, pageSize)) { o.OnNext(result); } return Disposable.Empty; })); }
public void CanParseShouldHandleValid12HourPatterns() { var parser = new TimeStringParser(); Assert.IsTrue(parser.CanParse("10:12:55 AM"), "Could not parse 10:12:55 AM"); Assert.IsTrue(parser.CanParse("9:12:55 PM"), "Could not parse 9:12:55 PM"); Assert.IsTrue(parser.CanParse("7 AM"), "Could not parse 7 AM"); Assert.IsTrue(parser.CanParse("4:12 PM"), "Could not parse 4:12 PM"); Assert.IsTrue(parser.CanParse("1/1/2017 7 AM"), "Could not parse 1/1/2017 7 AM"); Assert.IsTrue(parser.CanParse("1.17.2011 2:00 am"), "Could not parse 1.17.2011 2:00 am"); Assert.IsTrue(parser.CanParse("Jan 17, 2011 2:00 am"), "Could not parse Jan 17, 2011 2:00 am"); Assert.IsTrue(parser.CanParse("1-17-2017 2:00 am"), "Could not parse 1-17-2017 2:00 am"); Assert.AreEqual(0.291666667, Math.Round(parser.Parse("1/1/2017 7 AM"), 9)); }
public void CanParseShouldHandleValid24HourPatterns() { var parser = new TimeStringParser(); Assert.IsTrue(parser.CanParse("10:12:55"), "Could not parse 10:12:55"); Assert.IsTrue(parser.CanParse("22:12:55"), "Could not parse 13:12:55"); Assert.IsTrue(parser.CanParse("13"), "Could not parse 13"); Assert.IsTrue(parser.CanParse("13:12"), "Could not parse 13:12"); Assert.IsTrue(parser.CanParse("1/1/2017 13:12"), "Could not parse 1/1/2017 13:12"); Assert.IsTrue(parser.CanParse("1.17.2011 22:00"), "Could not parse 1.17.2011 22:00"); Assert.IsTrue(parser.CanParse("Jan 17, 2011 22:00"), "Could not parse Jan 17, 2011 22:00"); Assert.IsTrue(parser.CanParse("1-17-2017 22:00"), "Could not parse 1-17-2017 22:00"); Assert.IsTrue(parser.CanParse("25:00"), "Could not parse 25:00"); Assert.AreEqual(0.55, Math.Round(parser.Parse("1/1/2017 13:12"), 9)); Assert.AreEqual(1.041666667, Math.Round(parser.Parse("25:00"), 9)); }
public static async Task SetupRecordsAgo(ITableStore <TestTableEntity> tableStorage, string ago) { await tableStorage.DeleteAllAsync(); var entityList = new List <TestTableEntity> { new TestTableEntity("Kevin", "Bacon") { Age = 21, Email = "*****@*****.**" }, new TestTableEntity("Steven", "Jones") { Age = 32, Email = "*****@*****.**" } }; await tableStorage.CreateTableAsync().ConfigureAwait(false); await tableStorage.InsertAsync(entityList).ConfigureAwait(false); await Task.Delay(TimeStringParser.GetTimeAgoTimeSpan(ago)); var anotherEntityList = new List <TestTableEntity> { new TestTableEntity("Liam", "Matthews") { Age = 28, Email = "*****@*****.**" }, new TestTableEntity("Mary", "Gates") { Age = 45, Email = "*****@*****.**" } }; await tableStorage.InsertAsync(anotherEntityList).ConfigureAwait(false); }
/// <summary> /// Get the records and filter by a given predicate and time in the past /// </summary> /// <param name="filter">The filter to apply</param> /// <param name="ago">The time in the past to search e.g. 10m, 1h, etc.</param> /// <returns>The records filtered</returns> public IEnumerable <T> GetRecordsByFilter(Func <T, bool> filter, string ago) { bool CombineFilter(T x) => filter(x) && x.Timestamp >= TimeStringParser.GetTimeAgo(ago); return(GetAllRecords().Where(CombineFilter)); }
public void ParseShouldThrowExceptionIfSecondIsOutOfRange() { var parser = new TimeStringParser(); var result = parser.Parse("10:12:60"); }
public void ParseShouldThrowExceptionIfMinuteIsOutOfRange() { var parser = new TimeStringParser(); var result = parser.Parse("10:60:55"); }
/// <summary> /// Build the row key table query /// </summary> /// <param name="rowKey">The row key</param> /// <param name="ago">The time in the past to search e.g. 10m, 1h, etc.</param> /// <returns>The table query</returns> //private static TableQuery<T> BuildGetByRowKeyAndTimeQuery(string rowKey, string ago) private Pageable <T> BuildGetByRowKeyAndTimeQuery(string rowKey, string ago) { var utcTime = new DateTimeOffset(TimeStringParser.GetTimeAgo(ago), TimeSpan.Zero); return(CloudTable.Query <T>(x => x.RowKey == rowKey && x.Timestamp >= utcTime)); }