public void TestData_URL_GetsCorrectNumber() { b.Info.Flow(); SampleTestData td = new SampleTestData(); var urls = td.GetTestURLs(10); int count = 0; foreach (var u in urls) { count++; Assert.False(string.IsNullOrWhiteSpace(u)); var f = u.ToLowerInvariant(); Assert.StartsWith("http", f); } Assert.Equal(10, count); }
/// <summary> /// Designed to use reflection to work out the type of a value passed to it then alter that value to something different, aimed at /// changing values for unit tests. All that can be said is that the return value will not equal the entry value for supported simple types. /// </summary> /// <remarks>If the val object is of an unsupported type it is returned unchanged.</remarks> /// <param name="target">The value to change</param> /// <returns>A new value for the object val</returns> public object AlterValue(object target) { var td = new SampleTestData(); if (target == null) { return(null); } var t = target.GetType(); if (t == typeof(long)) { return((long)target + td.RandomStore.Next(5)); } if (t == typeof(uint)) { return((uint)target + td.RandomStore.Next(5)); } if (t == typeof(double)) { return((double)target + td.RandomStore.Next(5)); } if (t == typeof(int)) { return((int)target + td.RandomStore.Next(5)); } if (t == typeof(bool)) { return(!(bool)target); // Invert it for bools } if (t == typeof(string)) { string s = td.GenerateFriendlyString(); int length = td.RandomStore.Next(5); if (s.Length < length) { length = s.Length; } return((string)target + s.Substring(0, length)); } return(target); }
public void GetConfig_FallbackProvider_CalledForAllStrings() { SampleTestData td = new SampleTestData(); ConfigHub sut = new ConfigHub(); int hits = 0; sut.RegisterFallbackProvider((pname) => { hits++; return("test"); }); int totalHits = td.RandomStore.Next(100) + 1; int i; for (i = 0; i < totalHits; i++) { sut.GetSetting("asetting" + i.ToString()); } Assert.Equal <int>(i, hits); }