-
Ratings(0)
programming
Category
1
Conversations
Capabilities
Data Analysis
Visual data analysis Browser
Online Search and Web Reading Dall·e
Image GenerationDescription
致力于使用NUnit、XUnit或MSTest中的任一测试框架,设计和执行单元测试
Prompts
- 使用NUnit框架为以下代码生成单元测试 ``` csharp /// <summary> /// Class RunHelper. /// SourceLink:https://github.com/FoundatioFx/Foundatio/blob/master/src/Foundatio/Utility/Run.cs /// </summary> public static class RunHelper { /// <summary> /// Withes the retries. /// </summary> /// <param name="action">The action.</param> /// <param name="maxAttempts">The maximum attempts.</param> /// <param name="retryInterval">The retry interval.</param> public static void WithRetries(Action action, int maxAttempts = 5, TimeSpan? retryInterval = null) { WithRetries<object>(() => { action(); return null; }, maxAttempts, retryInterval); } /// <summary> /// Withes the retries. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="action">The action.</param> /// <param name="maxAttempts">The maximum attempts.</param> /// <param name="retryInterval">The retry interval.</param> /// <returns>T.</returns> /// <exception cref="System.ArgumentNullException">action</exception> /// <exception cref="Kmmp.Core.Models.KmHttpError.Exception">不应该到这里</exception> public static T WithRetries<T>(Func<T> action, int maxAttempts = 5, TimeSpan? retryInterval = null) { if (action == null) { throw new ArgumentNullException(nameof(action)); } int attempts = 1; var startTime = System.DateTime.Now; int currentBackoffTime = _defaultBackoffIntervals[0]; if (retryInterval != null) { currentBackoffTime = (int)retryInterval.Value.TotalMilliseconds; } do { if (attempts > 1) { SysLogHelper.Info("WithRetries", "Retrying {0} attempt after {1:g}...".Fmt(attempts.ToOrdinal(), DateTime.Now.Subtract(startTime))); } try { return action(); } catch (Exception ex) { if (attempts >= maxAttempts) { throw; } string strAddition = $"Retry error,action:{action.Method.Name}"; SysLogHelper.Error(ex, strAddition: strAddition); SleepSafe(currentBackoffTime); } if (retryInterval == null) { currentBackoffTime = _defaultBackoffIntervals[Math.Min(attempts, _defaultBackoffIntervals.Length - 1)]; } attempts++; } while (attempts <= maxAttempts); throw new Exception("不应该到这里"); } /// <summary> /// The default backoff intervals /// </summary> private static readonly int[] _defaultBackoffIntervals = new int[] { 100, 1000, 2000, 2000, 5000, 5000, 10000, 30000, 60000 }; /// <summary> /// Sleeps the safe. /// </summary> /// <param name="milliseconds">The milliseconds.</param> public static void SleepSafe(int milliseconds) { try { Thread.Sleep(milliseconds); } catch (OperationCanceledException) { } catch (Exception) { } } } ```
- 使用XUnit框架为C#冒泡排序算法生成单元测试
- 使用MSTest框架为C#快速排序算法生成单元测试
More GPTs by Deloris Huels
More programming GPTs
2.425.0K
2.425.0K
2.325.0K
2.625.0K
2.425.0K
2.625.0K
2.410.0K
2.210.0K
2.510.0K