本文整理汇总了C#中Bridge.QUnit.Assert.Expect方法的典型用法代码示例。如果您正苦于以下问题:C# Assert.Expect方法的具体用法?C# Assert.Expect怎么用?C# Assert.Expect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bridge.QUnit.Assert
的用法示例。
在下文中一共展示了Assert.Expect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test
public static void Test(Assert assert)
{
assert.Expect(5);
// TEST
var numbers = new[] { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
var filteredNumbers = (from n in numbers where n <= 6 select n).ToArray();
assert.DeepEqual(filteredNumbers, new[] { 5, 4, 1, 3, 6, 2, 0 }, "Where elements in integer array are below or equal 6");
// TEST
var filteredCounts = (from p in Person.GetPersons() where p.Count < 501 select p.Count).ToArray();
assert.DeepEqual(filteredCounts, new[] {300, 100, 500, 50 }, "Where elements in Person array have Count below 501");
// TEST
filteredCounts = (from p in Person.GetPersons() where p.Count < 501 && p.Group == "A" select p.Count).ToArray();
assert.DeepEqual(filteredCounts, new[] { 300 }, "Where elements in Person array have Count below 501 ang in group 'A'");
// TEST
var persons = Person.GetPersons();
var filteredPersonByCounts = (from p in Person.GetPersons() where p.Count < 501 select p).ToArray();
assert.DeepEqual(filteredPersonByCounts, new[] { persons[0], persons[1], persons[3], persons[4] },
"Where elements in Person array have Count below 501. Returns Person instances");
// TEST
var filteredPersonByCountAndIndex = persons.Where((p, index) => p.Count < index * 100).ToArray();
assert.DeepEqual(filteredPersonByCountAndIndex, new[] { persons[4] },
"Where elements in Person array have Count meet condition (p.Count < index * 100). Returns Person instances");
}
示例2: ThrownExceptions
public static void ThrownExceptions(Assert assert)
{
assert.Expect(12);
// #230
assert.Throws(TryCatchWithNotCaughtTypedException, "catch me", "A.Typed exception is not Caught");
assert.Ok(IsATry, "A. exception not caught - try section called");
assert.Ok(!IsACatch, "A. exception not caught - catch section not called");
// #229
assert.Throws(TryCatchWithNotCaughtTypedExceptionAndArgument, "catch me", "[#229] B. Typed exception is not Caught; and argument");
assert.Ok(IsBTry, "[#229] B. exception not caught - try section called");
assert.Ok(!IsBCatch, "B. exception not caught - catch section not called");
// #231
assert.Throws(TryCatchWithRethrow, "catch me", "[#231] C. Rethrow");
assert.Ok(IsCTry, "C. exception caught and re-thrown - try section called");
assert.Ok(IsCCatch, "C. exception caught and re-thrown - catch section called");
assert.Throws(TryCatchWithRethrowEx, new Func<object, bool>((error) =>
{
return error.ToString() == "catch me";
}), "D. Rethrow with parameter");
assert.Ok(IsDTry, "D. exception caught and re-thrown - try section called");
assert.Ok(IsDCatch, "D. exception caught and re-thrown - catch section called");
}
示例3: Test
public static void Test(Assert assert)
{
assert.Expect(4);
// TEST
string[] words = { "count", "tree", "mount", "five", "doubt" };
bool anyOu = words.Any(w => w.Contains("ou"));
assert.Ok(anyOu, "Any() to return words containing 'ou'");
// TEST
int[] oddNumbers = { 3, 7, 9, 5, 247, 1000001 };
bool onlyOdd = oddNumbers.All(n => n % 2 == 1);
assert.Ok(onlyOdd, "All() is odd");
// TEST
int[] someNumbers = { 2, 3, 7, 9, 5, 247, 1000001 };
bool notOnlyOdd = !someNumbers.All(n => n % 2 == 1);
assert.Ok(notOnlyOdd, "All() is not only odd");
// TEST
var productGroups =
(from p in Person.GetPersons()
group p by p.Group into pGroup
where pGroup.Any(p => p.Count >= 500)
select new { Group = pGroup.Key, Names = pGroup.Select(x => x.Name).ToArray() }).ToArray();
object[] productGroupsExpected = { new {Group = "C", Names = new[]{"Zeppa", "Billy"}},
new {Group = "B", Names = new[]{"John", "Dora", "Ian", "Mary"}},
new {Group = (string)null, Names = new[]{"Nemo"}}
};
assert.DeepEqual(productGroups, productGroupsExpected, "Any() to return a grouped array of names only for groups having any item with Count > 500");
}
示例4: TestUseCase
public static void TestUseCase(Assert assert)
{
assert.Expect(12);
Func<object> item11 = () => 11;
assert.Equal(item11.IsNullOrUndefined(), false, "Bridge655 IsNullOrUndefined11");
assert.Equal(item11(), 11, "Bridge655 item11");
Func<int, int> item12 = (i) => i;
assert.Equal(item12.IsNullOrUndefined(), false, "Bridge655 IsNullOrUndefined12");
assert.Equal(item12(12), 12, "Bridge655 item12");
Func<object> item21 = () => 21;
assert.Equal(item21.IsNullOrUndefined(21), false, "Bridge655 IsNullOrUndefined21 false");
assert.Equal(item21.IsNullOrUndefined(0), true, "Bridge655 IsNullOrUndefined21 true");
assert.Equal(item21(), 21, "Bridge655 item21");
Func<int, string, int> item22 = (i, s) => i + s.Length;
assert.Equal(item22.IsNullOrUndefined("22"), "false", "Bridge655 IsNullOrUndefined22 false");
assert.Equal(item22.IsNullOrUndefined(string.Empty), "true", "Bridge655 IsNullOrUndefined22 true");
assert.Equal(item22(19, "two"), 22, "Bridge655 item22");
Action<int, string> item32 = (i, s) => { var b = i == s.Length; };
assert.Equal(item32.IsNullOrUndefined("32"), "false", "Bridge655 IsNullOrUndefined32 false");
assert.Equal(item32.IsNullOrUndefined(string.Empty), "true", "Bridge655 IsNullOrUndefined32 true");
}
示例5: TestUseCase
public static void TestUseCase(Assert assert)
{
assert.Expect(6);
var s1 = string.Join(",", new[] { "a", "b" });
assert.Equal(s1, "a,b", "Join1");
var animals = new List<Animal>();
animals.Add(new Animal("Squirrel", "Rodent"));
animals.Add(new Animal("Gray Wolf", "Carnivora"));
animals.Add(new Animal("Capybara", "Rodent"));
string s2 = String.Join(" ", animals);
assert.Equal(s2, "Squirrel Gray Wolf Capybara", "Join2");
object[] values = { null, "Cobb", 4189, 11434, .366 };
string s31 = String.Join("|", values);
assert.Equal(s31, "|Cobb|4189|11434|0.366", "Join31");
values[0] = String.Empty;
string s32 = String.Join("|", values);
assert.Equal(s32, "|Cobb|4189|11434|0.366", "Join32");
string[] sArr = new string[10];
for (int i = 0; i < 10; i++)
sArr[i] = String.Format("{0,-3}", i * 5);
string s4 = String.Join(":", sArr);
assert.Equal(s4, "0 :5 :10 :15 :20 :25 :30 :35 :40 :45 ", "Join4");
var val = new string[] { "apple", "orange", "grape", "pear" };
var s5 = string.Join(", ", val, 1, 2);
assert.Equal(s5, "orange, grape", "Join5");
}
示例6: TestUseCase
public static void TestUseCase(Assert assert)
{
assert.Expect(1);
var ted = new Bridge566B();
assert.Equal(ted.Data, "Ted", "#566 Ted");
}
示例7: TestUseCase
public static void TestUseCase(Assert assert)
{
assert.Expect(1);
object o = Script.Undefined;
assert.Throws(() => { var s = (string)o; }, "Unable to cast type 'null' to type String");
}
示例8: Test
public static void Test(Assert assert)
{
assert.Expect(2);
// TEST
var numbers = (from n in Enumerable.Range(0, 6)
select new
{
Number = n,
IsOdd = n % 2 == 1
}).ToArray();
var numbersExpected = new object[] {
new { Number = 0, IsOdd = false},
new { Number = 1, IsOdd = true},
new { Number = 2, IsOdd = false},
new { Number = 3, IsOdd = true},
new { Number = 4, IsOdd = false},
new { Number = 5, IsOdd = true},
};
assert.DeepEqual(numbers, numbersExpected, "Range() 6 items from 0");
// TEST
var repeatNumbers = Enumerable.Repeat(-3, 4).ToArray();
var repeatNumbersExpected = new[] { -3, -3, -3, -3 };
assert.DeepEqual(repeatNumbers, repeatNumbersExpected, "Repeat() -3 four times");
}
示例9: TestStatic
public static void TestStatic(Assert assert)
{
assert.Expect(16);
assert.Equal(Static.Foo(1), "Foo(int x)", "Static Foo(int x)");
assert.Equal(Static.Foo("string"), "Foo(string s)", "Static Foo(string s)");
assert.Equal(Static.Foo(1.1), "Foo(double d)", "Static Foo(double d)");
assert.Equal(Static.Foo(1, 2), "Foo(int x, int y)", "Static Foo(int x, int y)");
assert.Equal(Static.Foo(1, 1.1), "Foo(int x, double y)", "Static Foo(int x, double y)");
assert.Equal(Static.Foo(1.1, 1), "Foo(double x, int y)", "Static Foo(double x, int y)");
assert.Equal(Static.FooReturnType(1), 'C', "Static char FooReturnType(int y)");
assert.Equal(Static.FooReturnType(1.1), "string FooReturnType(double d)", "Static string FooReturnType(double d)");
assert.Equal(Static.FooOptionalParameters(1), "FooOptionalParameters(int x)", "Static FooOptionalParameters(int x)");
assert.Equal(Static.FooOptionalParameters(1, 2), "FooOptionalParameters(int x, int y = 5)", "Static FooOptionalParameters(int x, int y = 5)");
assert.Equal(Static.FooMultipleOptionalParameters(1, 2), "FooMultipleOptionalParameters(int x, int y = 5)", "Static FooMultipleOptionalParameters(int x, int y = 5)");
assert.Equal(Static.FooMultipleOptionalParameters(1, z: 2), "FooMultipleOptionalParameters(int x, int y = 5, int z = 10)", "Static FooMultipleOptionalParameters(int x, int y = 5, int z = 10)");
assert.Equal(Static.FooMultipleOptionalParameters(1, 2, 3), "FooMultipleOptionalParameters(int x, int y = 5, int z = 10)", "Static FooMultipleOptionalParameters(int x, int y = 5, int z = 10)");
assert.Equal(Static.FooMultipleOptionalParameters(1, z: 2, y: 3), "FooMultipleOptionalParameters(int x, int y = 5, int z = 10)", "Static FooMultipleOptionalParameters(int x, int y = 5, int z = 10)");
assert.Equal(Static.FooNamedArgument(x: 1), "FooNamedArgument(int x)", "Static FooNamedArgument(int x)");
assert.Equal(Static.FooNamedArgument(d: 1), "FooNamedArgument(double d)", "Static FooNamedArgument(double d)");
}
示例10: TesForeach
public static void TesForeach(Assert assert)
{
assert.Expect(2);
string[] keys = new[] { "1", "2", "3" };
Action[] handlers = new Action[3];
int i = 0;
string result = "";
foreach (var itm in keys)
handlers[i++] = () => result += itm;
foreach (var handler in handlers)
{
handler();
}
assert.Equal(result, "123", "Bridge563 No block foreach loop");
i = 0;
result = "";
foreach (var itm in keys)
{
handlers[i++] = () => result += itm;
}
foreach (var handler in handlers)
{
handler();
}
assert.Equal(result, "123", "Bridge563 block foreach loop");
}
示例11: TestUseCase
public static void TestUseCase(Assert assert)
{
assert.Expect(1);
int[] numbers = { 1, 2, 3 };
int sum = 0;
foreach (int a in numbers)
{
sum = sum + a;
}
foreach (int a in numbers)
{
sum = sum + a;
}
foreach (int a in numbers)
{
sum = sum + a;
}
foreach (int a in numbers)
{
sum = sum + a;
}
assert.Equal(sum, 24, "Bridge502 sum");
}
示例12: TestCloneCompare
public static void TestCloneCompare(Assert assert)
{
assert.Expect(13);
var v1 = new Version(1, 2, 3, (4 << 16) + 5);
var o = v1.Clone();
assert.Ok(o != null, "v1 Cloned");
var v2 = o as Version;
assert.Ok(v2 != null, "v1 Cloned as Version");
assert.Equal(v2.Major, 1, "v2.Major 1");
assert.Equal(v2.Minor, 2, "v2.Minor 2");
assert.Equal(v2.Build, 3, "v2.Build 3");
assert.Equal(v2.Revision, 262149, "v2.Revision (4 << 16) + 5 = 262149");
assert.Equal(v2.MajorRevision, 4, "v2.MajorRevision 4");
assert.Equal(v2.MinorRevision, 5, "v2.MinorRevision 5");
var v3 = new Version(1, 2, 2, (4 << 16) + 5);
assert.Equal(v1.CompareTo(v3), 1, "v1.CompareTo(v3)");
var v4 = new Version(1, 3, 3, (4 << 16) + 5);
assert.Equal(v1.CompareTo(v4), -1, "v1.CompareTo(v4)");
assert.Equal(v1.CompareTo(o), 0, "v1.CompareTo(o)");
assert.Equal(v1.CompareTo(v2), 0, "v1.CompareTo(v2)");
assert.NotEqual(v1.CompareTo(null), 0, "v1.CompareTo(null)");
}
示例13: TestUseCase
public static void TestUseCase(Assert assert)
{
assert.Expect(6);
SByte i8_1 = -2;
SByte i8_2 = (SByte)(i8_1 >> 4);
Byte u8_1 = 0xFE;
Byte u8_2 = (Byte)(u8_1 >> 4);
Int16 i16_1 = -2;
Int16 i16_2 = (Int16)(i16_1 >> 8);
UInt16 u16_1 = 0xFFFE;
UInt16 u16_2 = (UInt16)(u16_1 >> 8);
Int32 i32_1 = -2;
Int32 i32_2 = i32_1 >> 16;
UInt32 u32_1 = 0xFFFFFFFE;
UInt32 u32_2 = u32_1 >> 16;
assert.Equal(i8_2, -1, "Bridge592 i8_2");
assert.Equal(u8_2, 0xF, "Bridge592 u8_2");
assert.Equal(i16_2, -1, "Bridge592 i16_2");
assert.Equal(u16_2, 0xFF, "Bridge592 u16_2");
assert.Equal(i32_2, -1, "Bridge592 i32_2");
assert.Equal(u32_2, 0xFFFF, "Bridge592 u32_2");
}
示例14: TestUseCase
public static void TestUseCase(Assert assert)
{
assert.Expect(7);
var t1 = new Type();
assert.Ok(t1 != null, "#565 t1");
var t2 = new ValueType();
assert.Ok(t2 != null, "#565 t2");
var t3 = new IntPtr();
assert.Ok(t3.GetType() == typeof(IntPtr) , "#565 t3");
var t4 = new UIntPtr();
assert.Ok(t4.GetType() == typeof(UIntPtr), "#565 t4");
var t5 = new ParamArrayAttribute();
assert.Ok(t5 != null, "#565 t5");
var t6 = new RuntimeTypeHandle();
assert.Ok(t6.GetType() == typeof(RuntimeTypeHandle), "#565 t6");
var t7 = new RuntimeFieldHandle();
assert.Ok(t7.GetType() == typeof(RuntimeFieldHandle), "#565 t7");
}
示例15: TestUseCase
public static void TestUseCase(Assert assert)
{
assert.Expect(1);
var o = JSON.Parse<bool>("true");
assert.Equal(o, true, "Bridge544 bool");
}