public void IsLessThanOrEqualTo_Expression_IComparable_succeeds_when_less_than( int candidate, int value) => Invoking(() => Ensure.That(() => candidate) .IsLessThanOrEqualTo(() => value, TestComparer <int> .AlwaysLess())) .Should().NotThrow();
public void IsGreaterThan_T_IComparable_succeeds_when_greater_than( int candidate, int value) => Invoking(() => Ensure.That(() => candidate) .IsGreaterThan(value, TestComparer <int> .AlwaysGreater())) .Should().NotThrow();
public void IsOrdered_HandlesCustomComparison2() { TestComparer comparer = new TestComparer(); Assert.That(new[] { 2, 1 }, Is.Ordered.Using(comparer)); Assert.That(comparer.CallCount, Is.GreaterThan(0), "TestComparer was not called"); }
public void ComparerIsCalled() { TestComparer comparer = new TestComparer(); Assert.That(new int[] { 1, 2, 3 }, Contains.Item(2).Using(comparer)); Assert.That(comparer.Called, "Comparer was not called"); }
public void ComparerIsCalledInExpression() { TestComparer comparer = new TestComparer(); Assert.That(new int[] { 1, 2, 3 }, Has.Length.EqualTo(3).And.Contains(2).Using(comparer)); Assert.That(comparer.Called, "Comparer was not called"); }
public void ComparerIsCalled() { TestComparer comparer = new TestComparer(); Assert.That(new string[] { "Hello", "World" }, Contains.Item("World").Using(comparer)); Assert.That(comparer.Called, "Comparer was not called"); }
public void ComparerIsCalledInExpression() { TestComparer comparer = new TestComparer(); Assert.That(new string[] { "Hello", "World" }, Has.Length.EqualTo(2).And.Contains("World").Using(comparer)); Assert.That(comparer.Called, "Comparer was not called"); }
public void IsGreaterThan_T_IComparable_fails_when_less_than( int candidate, int value) => Invoking(() => Ensure.That(() => candidate) .IsGreaterThan(value, TestComparer <int> .AlwaysLess())) .Should().Throw <GuardClauseNotMetException>() .WithMessage(nameof(candidate).ShouldBeGreaterThan(value));
public void IsLessThanOrEqualTo_Expression_IComparable_fails_when_greater_than( int candidate, int value) => Invoking(() => Ensure.That(() => candidate) .IsLessThanOrEqualTo(() => value, TestComparer <int> .AlwaysGreater())) .Should().Throw <GuardClauseNotMetException>() .WithMessage(nameof(candidate).ShouldBeLessThanOrEqualTo(nameof(value)));
public void IsOrdered_Handles_custom_comparison2() { ICollection collection = new SimpleObjectCollection(2, 1); TestComparer comparer = new TestComparer(); Assert.That(collection, Is.Ordered.Using(comparer)); Assert.That(comparer.Called, "TestComparer was not called"); }
public void IsOrdered_Handles_custom_comparison2() { ArrayList al = new ArrayList(); al.Add(2); al.Add(1); TestComparer comparer = new TestComparer(); Assert.That(al, Is.Ordered.Using(comparer)); Assert.That(comparer.Called, "TestComparer was not called"); }
/// <summary> /// 协变性 /// </summary> public void T17D3() { //TODO:协变性指的是泛型类型参数可以从一个基类隐式的转化为派生类 List <object> listobject = new List <object>(); List <string> liststrs = new List <string>(); IComparer <object> objComparer = new TestComparer(); IComparer <string> strComparer = new TestComparer(); liststrs.Sort(objComparer); //listobject.Sort(strComparer); }
public void MultipleComparersUsedInDifferentSteps() { var comparer1 = new TestComparer(); var comparer2 = new AlwaysEqualComparer(); var collection = new[] { new TestClass3("XYZ", 2), new TestClass3("ABC", 42), new TestClass3("ABC", 1) }; Assert.That(collection, Is.Ordered.By("A").Using(comparer1).Then.By("B").Using(comparer2)); // First comparer is called for every pair of items in the collection Assert.That(comparer1.CallCount, Is.EqualTo(2), "First comparer should be called twice"); // Second comparer is only called where the first property matches Assert.That(comparer2.CallCount, Is.EqualTo(1), "Second comparer should be called once"); }
public static void TestRun() { int n1 = 4, n2 = 8; ArrayList a1 = new ArrayList { 1 }; ArrayList a2 = new ArrayList { 2 }; GenericSwitchVal(ref a1, ref a2); Console.WriteLine($"n1:{n1} n2:{n2}"); //TestMethods<>.Test(""); //使用反射调用泛型方法 TestC2 c = new TestC2(); Type t1 = c.GetType(); // 首先,获得方法的定义 // 如果不传入BindFlags实参,GetMethod方法只返回公共成员 // 这里我指定了NonPublic,也就是返回私有成员 // (这里要注意的是,如果指定了Public或NonPublic的话, // 必须要同时指定Instance|Static,否则不返回成员,具体大家可以用代码来测试的) var m1 = t1.GetMethod("PrintType", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); m1.MakeGenericMethod(typeof(FileInfo)).Invoke(null, null); //测试泛型的可变性(协变,逆变) List <object> st1 = new List <object>(); List <string> st2 = new List <string>(); st1.AddRange(st2); //协变 IComparer <object> tc1 = new TestComparer(); IComparer <string> tc2 = new TestComparer(); st2.Sort(tc1); //逆变 Func <int> ff1 = new Func <int>(() => 1); Func <object> ff2 = new Func <object>(() => ""); Func <string> ff3 = () => "ee"; ff2 = ff3; Action <int> ff4 = new Action <int>((i) => { }); Action <object> ff5 = new Action <object>((i) => { }); Action <string> ff6 = (s) => { }; ff6 = ff5; Console.ReadKey(); }
static void Main(string[] args) { List <object> listobject = new List <object>(); List <string> liststr = new List <string>(); //协变性指的是泛型类型参数可以从一个派生类隐式地转化为基类 listobject.AddRange(liststr); //成功 liststr.AddRange(listobject); //出错 ////协变性指的是泛型类型参数可以从一个基类隐式地转化为派生类 IComparer <object> objConparer = new TestComparer(); IComparer <string> stringComparer = new TestComparer(); liststr.Sort(objConparer); //正确 listobject.Sort(stringComparer); //出错 }
static void Main(string[] args) { // Variables var outputFilePath = @"C:\Users\preston-smithm\Documents\..Digital\Projects\Testing\Data Protection\Automated Testing\script\csv from ftp\201509220018-Geni-SitecoreDB-Constituent-001.csv"; var macroInputDirectory = @"C:\Users\preston-smithm\Documents\..Digital\Projects\Testing\Data Protection\Automated Testing\script\macro output"; // Grab Array of output report from CSV var outputdataTable = Helpers.GetDataTableFromCsvPath(outputFilePath); // Grab input array var inputDataTable = Helpers.BuildDataTableFromListOfFilenames(Helpers.GetFileNamesFromFilepath(macroInputDirectory)); // Foreach item in the output array, cross-reference the email addresss and ensure that the matrix is complete var comparer = new TestComparer(outputdataTable, inputDataTable); comparer.RunComparison(); }
public void ShouldSortByComparer(int capacity) { // Given var expectedArr = Enumerable.Range(0, capacity) .Select(x => new TestDto { Id = x, Name = x.ToString() }) .ToArray(); var arrayToSort = expectedArr.ToArray(); arrayToSort.Shuffle(); var comparer = new TestComparer(); // When GetSortByComparer(arrayToSort, comparer).Invoke(); // Then arrayToSort.ShouldBe(expectedArr); }
public async Task ExecuteAsync() { var testsFromAssembly = this.testAssembly.GetTestMethods(); Log.Information("Found {0} tests in {1}", testsFromAssembly.Count(), this.launchSettings.Arguments.AssemblyPath); var testsFromAzure = await this.testPlansController.GetAutomatedTestCasesAsync(); Log.Information("Found {0} tests in {1}", testsFromAzure.Count(), $"{this.launchSettings.Arguments.Organisation}/{this.launchSettings.Arguments.Project}"); var(notInAssembly, notInAzure) = TestComparer.Compare(testsFromAssembly, testsFromAzure.ToUITests()); var notInAssemblyCount = notInAssembly.Count(); var notInAzureCount = notInAzure.Count(); if (notInAssemblyCount == 0 && notInAzureCount == 0) { Log.Information("Your test assembly and Azure are in sync, so no action is required."); return; } if (notInAzureCount > 0) { Log.Information("{0} test(s) from your assembly are missing from Azure and will be uploaded", notInAzureCount); await this.testPlansController.UploadTestCasesAsync(notInAzure); } else { Log.Information("Azure already contains all the tests tha texists in your test assembly. skipped."); } if (notInAssemblyCount > 0) { Log.Information("{0} test(s) from Azure no longer exist in your test assembly and will be deleted from Azure", notInAssemblyCount); await this.testPlansController.DeleteTestCasesAsync(testsFromAzure.Where(x => notInAssembly.Any(y => y.Guid.Equals(Guid.Parse(x.Fields[WorkItemFields.AutomatedTestId].ToString()))))); } else { Log.Information("Azure does not contain anything that may have been removed from in your test assembly. skipped."); } }
public int GetIndexSearchItemWithincorrectArray(double[] array, double search) { var comparer = new TestComparer<double>(); return Search(array, search, comparer.SomeCompare); }
public void IsLessThanOrEqualTo_T_IComparable_succeeds_when_equal(int candidate) => Invoking(() => Ensure.That(() => candidate) .IsLessThanOrEqualTo(candidate, TestComparer <int> .AlwaysEqual())) .Should().NotThrow();
public void IsOrdered_Handles_custom_comparison2() { var al = new List<int>(); al.Add(2); al.Add(1); TestComparer comparer = new TestComparer(); Assert.That(al, Is.Ordered.Using(comparer)); Assert.That(comparer.Called, "TestComparer was not called"); }
public int GetIndexSearchItemWithIntegerArray(int[] array,int search) { var comparer=new TestComparer<int>(); return Search(array, search, comparer.SomeCompare); }
public void IsLessThan_Expression_IComparable_fails_when_equal(int candidate) => Invoking(() => Ensure.That(() => candidate) .IsLessThan(() => candidate, TestComparer <int> .AlwaysEqual())) .Should().Throw <GuardClauseNotMetException>() .WithMessage(nameof(candidate).ShouldBeLessThan(nameof(candidate)));
public void IsValidationFailingWhenItShould() { // Variables // output datatable var outputDataTable = new DataTable("output"); outputDataTable.Columns.Add("EmailAddress", typeof(string)); outputDataTable.Columns.Add(new DataColumn { ColumnName = "DataProtectionStatementCode1", DataType = typeof(string) }); outputDataTable.Columns.Add(new DataColumn { ColumnName = "DataProtectionStatementCode2", DataType = typeof(string) }); outputDataTable.Columns.Add(new DataColumn { ColumnName = "DataProtectionStatementCode3", DataType = typeof(string) }); outputDataTable.Columns.Add(new DataColumn { ColumnName = "DataProtectionStatementCode4", DataType = typeof(string) }); outputDataTable.Columns.Add(new DataColumn { ColumnName = "DataProtectionStatementCode5", DataType = typeof(string) }); DataRow newRow = outputDataTable.NewRow(); newRow["EmailAddress"] = "*****@*****.**"; newRow["DataProtectionStatementCode1"] = "ContactByPost"; newRow["DataProtectionStatementCode2"] = "ContactByPhone"; newRow["DataProtectionStatementCode3"] = "NoContactByEmail"; newRow["DataProtectionStatementCode4"] = "ContactByThirdParty"; newRow["DataProtectionStatementCode5"] = "NoContactByText"; outputDataTable.Rows.Add(newRow); // input data table var inputDataTable = new DataTable("input"); inputDataTable.Columns.Add(new DataColumn { ColumnName = "Email", DataType = typeof(string) }); inputDataTable.Columns.Add(new DataColumn { ColumnName = "one", DataType = typeof(string) }); inputDataTable.Columns.Add(new DataColumn { ColumnName = "two", DataType = typeof(string) }); inputDataTable.Columns.Add(new DataColumn { ColumnName = "three", DataType = typeof(string) }); inputDataTable.Columns.Add(new DataColumn { ColumnName = "four", DataType = typeof(string) }); inputDataTable.Columns.Add(new DataColumn { ColumnName = "five", DataType = typeof(string) }); newRow = inputDataTable.NewRow(); newRow["Email"] = "*****@*****.**"; newRow["two"] = "TAG POS = 1 TYPE = INPUT:CHECKBOX FORM = ID:frmMain ATTR = ID:main_0_pagecontent_0_form_E02D05D39F1649C4A29450649B2AAFBF_field_8F931E2FCE2D4FAAA9573A95D44B3B0Dlist_0 CONTENT = YES"; newRow["three"] = "TAG POS = 1 TYPE = INPUT:CHECKBOX FORM = ID:frmMain ATTR = ID:main_0_pagecontent_0_form_E02D05D39F1649C4A29450649B2AAFBF_field_8F931E2FCE2D4FAAA9573A95D44B3B0Dlist_2 CONTENT = YES"; newRow["four"] = ""; newRow["five"] = ""; inputDataTable.Rows.Add(newRow); // output headers (THESE CAN BE GRABBED FROM THE FILE var outputheaders = new List<string>(); outputheaders.Add("EmailAddress"); outputheaders.Add("DataProtectionStatementCode1"); outputheaders.Add("DataProtectionStatementCode2"); outputheaders.Add("DataProtectionStatementCode3"); outputheaders.Add("DataProtectionStatementCode4"); outputheaders.Add("DataProtectionStatementCode5"); var inputHeaders = new List<string>(); inputHeaders.Add("email"); inputHeaders.Add("one"); inputHeaders.Add("two"); inputHeaders.Add("three"); inputHeaders.Add("four"); inputHeaders.Add("five"); var validators = new List<Validator>(); // 'validators' are conditions that should not be, with the key being the expected output value, and the Value being the expected input validators.Add(new Validator("NoContactByText", "TAG POS = 1 TYPE = INPUT:CHECKBOX FORM = ID:frmMain ATTR = ID:main_0_pagecontent_0_form_E02D05D39F1649C4A29450649B2AAFBF_field_8F931E2FCE2D4FAAA9573A95D44B3B0Dlist_2 CONTENT = YES")); validators.Add(new Validator("ContactByPost", "TAG POS = 1 TYPE = INPUT:CHECKBOX FORM = ID:frmMain ATTR = ID:main_0_pagecontent_0_form_E02D05D39F1649C4A29450649B2AAFBF_field_8F931E2FCE2D4FAAA9573A95D44B3B0Dlist_3 CONTENT = YES")); validators.Add(new Validator("ContactByPhone", "TAG POS = 1 TYPE = INPUT:CHECKBOX FORM = ID:frmMain ATTR = ID:main_0_pagecontent_0_form_E02D05D39F1649C4A29450649B2AAFBF_field_8F931E2FCE2D4FAAA9573A95D44B3B0Dlist_1 CONTENT = YES")); validators.Add(new Validator("NoContactByEmail", "TAG POS = 1 TYPE = INPUT:CHECKBOX FORM = ID:frmMain ATTR = ID:main_0_pagecontent_0_form_E02D05D39F1649C4A29450649B2AAFBF_field_8F931E2FCE2D4FAAA9573A95D44B3B0Dlist_0 CONTENT = YES")); validators.Add(new Validator("ContactByThirdParty", "TAG POS = 1 TYPE = INPUT:CHECKBOX FORM = ID:frmMain ATTR = ID:main_0_pagecontent_0_form_E02D05D39F1649C4A29450649B2AAFBF_field_8F931E2FCE2D4FAAA9573A95D44B3B0Dlist_4 CONTENT = YES")); TestType test = new TestType(outputDataTable, inputDataTable, outputheaders, inputHeaders, validators); var classUnderTest = new TestComparer(test); var result = classUnderTest.RunComparison(); Assert.AreEqual(result, false); }