本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# List.Clear方法的具体用法?C# List.Clear怎么用?C# List.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.Clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InvalidSpotTest
public void InvalidSpotTest()
{
var spotBusiness = new SpotBusiness();
IList<ValidationResult> validationErrorResults = new List<ValidationResult>();
const bool NotValid = false;
bool isValidActual;
// Check validation of a seemly normal location.
var noName = new Spot(new GeoPoint { Lat = 0.0, Lon = 0.0 }, null);
// check validation
validationErrorResults.Clear();
isValidActual = spotBusiness.Validate(noName, validationErrorResults);
Assert.AreEqual(NotValid, isValidActual, "no name generic location");
// Check validation of a seemly normal location.
var noLocation = new Spot(null, "Spot");
// check validation
validationErrorResults.Clear();
isValidActual = spotBusiness.Validate(noLocation, validationErrorResults);
Assert.AreEqual(NotValid, isValidActual, "no location generic location");
spotBusiness.Dispose();
}
示例2: CollectionPropertyDependencyTest
public void CollectionPropertyDependencyTest()
{
List<string> property_notifications = new List<string>();
Model m = new Model();
m.Items.Add(new Item() { Prop = 42 });
m.Items.Add(new Item() { Prop = 23 });
m.Items.Add(new Item() { Prop = 17 });
ViewModel vm = new ViewModel(m);
m.PropertyChanged += (sender, args) => property_notifications.Add("Model:" + args.PropertyName);
vm.PropertyChanged += (sender, args) => property_notifications.Add("ViewModel:" + args.PropertyName);
var item = new Item() { Prop = 1 };
item.PropertyChanged += (sender, args) => property_notifications.Add("Item:" + args.PropertyName);
m.Items.Add(item);
Assert.AreEqual(1, property_notifications.Count);
Assert.IsTrue(property_notifications.Contains("ViewModel:Items"));
property_notifications.Clear();
item.Prop = 42;
Assert.AreEqual(3, property_notifications.Count);
Assert.IsTrue(property_notifications.Contains("Item:Prop"));
Assert.IsTrue(property_notifications.Contains("ViewModel:Items")); // Called by Item.Prop changed
Assert.IsTrue(property_notifications.Contains("ViewModel:Items")); // Called by ItemViewModel.PropSquared
property_notifications.Clear();
m.Items.Remove(item);
Assert.AreEqual(1, property_notifications.Count);
Assert.IsTrue(property_notifications.Contains("ViewModel:Items"));
}
示例3: ExternalCollectionDependencyTest
public void ExternalCollectionDependencyTest()
{
var changed_properties = new List<string>();
var base_obj = new ExternalCollectionDependencyBaseObject();
var obj = new ExternalCollectionDependencyObject(base_obj);
obj.PropertyChanged += (sender, args) => changed_properties.Add(args.PropertyName);
base_obj.BaseProp1.Add(42);
Assert.AreEqual(1, changed_properties.Count, "1 property changed event expected");
Assert.IsTrue(changed_properties.Contains("Prop1"), "Prop1 property changed event expected");
changed_properties.Clear();
base_obj = new ExternalCollectionDependencyBaseObject();
obj.BaseObject = base_obj;
base_obj.BaseProp1.Add(42);
Assert.AreEqual(2, changed_properties.Count, "2 property changed events expected");
Assert.IsTrue(changed_properties.Contains("BaseObject"), "BaseObject property changed event expected");
Assert.IsTrue(changed_properties.Contains("Prop1"), "Prop1 property changed event expected");
changed_properties.Clear();
base_obj.BaseProp1 = new ObservableCollection<int>();
base_obj.BaseProp1.Add(42);
Assert.AreEqual(1, changed_properties.Count, "1 property changed event expected");
Assert.IsTrue(changed_properties.Contains("Prop1"), "Prop1 property changed event expected");
}
示例4: XliffElement_AddChildElementsToList
public void XliffElement_AddChildElementsToList()
{
TestXliffElement element;
List<ElementInfo> list;
List<XliffElement> children;
element = new TestXliffElement();
children = new List<XliffElement>();
Console.WriteLine("Test with null.");
list = null;
element.CallAddChildElementsToList(null, ref list);
Assert.IsNull(list, "List is incorrect.");
Console.WriteLine("Test with empty enumeration.");
list = null;
element.CallAddChildElementsToList(new XliffElement[] { }, ref list);
Assert.IsNull(list, "List is incorrect.");
Console.WriteLine("Test with invalid enumeration.");
children.Add(new Target());
list = null;
try
{
element.CallAddChildElementsToList(children, ref list);
Assert.Fail("Expected KeyNotFoundException to be thrown.");
}
catch (KeyNotFoundException)
{
}
Console.WriteLine("Test with valid enumeration.");
children.Clear();
children.Add(new File());
children.Add(new File());
children.Add(new Source());
list = null;
element.CallAddChildElementsToList(children, ref list);
Assert.AreEqual(3, list.Count, "List count is incorrect.");
Assert.AreEqual(ElementNames.File, list[0].LocalName, "LocalName[0] is incorrect.");
Assert.AreEqual(ElementNames.File, list[1].LocalName, "LocalName[1] is incorrect.");
Assert.AreEqual(ElementNames.Source, list[2].LocalName, "LocalName[2] is incorrect.");
Assert.AreEqual(children[0], list[0].Element, "Element[0] is incorrect.");
Assert.AreEqual(children[1], list[1].Element, "Element[1] is incorrect.");
Assert.AreEqual(children[2], list[2].Element, "Element[2] is incorrect.");
Console.WriteLine("Test with full list.");
list = new List<ElementInfo>();
list.Add(new ElementInfo(new XmlNameInfo("name"), new TestXliffElement()));
children.Clear();
children.Add(new File());
element.CallAddChildElementsToList(children, ref list);
Assert.AreEqual(2, list.Count, "List count is incorrect.");
Assert.AreEqual("name", list[0].LocalName, "LocalName[0] is incorrect.");
Assert.AreEqual(ElementNames.File, list[1].LocalName, "Key[1] is incorrect.");
Assert.AreEqual(children[0], list[1].Element, "Value[1] is incorrect.");
}
示例5: Cube
private Mesh3D Cube()
{
Mesh3D m = new Mesh3D();
Vertex3D v0 = m.AddVertex(new Vertex3D(-1, -1, 1));
Vertex3D v1 = m.AddVertex(new Vertex3D(1, -1, 1));
Vertex3D v2 = m.AddVertex(new Vertex3D(1, 1, 1));
Vertex3D v3 = m.AddVertex(new Vertex3D(-1, 1, 1));
Vertex3D v4 = m.AddVertex(new Vertex3D(-1, -1, -1));
Vertex3D v5 = m.AddVertex(new Vertex3D(1, -1, -1));
Vertex3D v6 = m.AddVertex(new Vertex3D(1, 1, -1));
Vertex3D v7 = m.AddVertex(new Vertex3D(-1, 1, -1));
List<Vertex3D> list = new List<Vertex3D>();
list.Add(v0);
list.Add(v1);
list.Add(v2);
list.Add(v3);
m.CreatePolygon(list);
list.Clear();
list.Add(v7);
list.Add(v6);
list.Add(v5);
list.Add(v4);
m.CreatePolygon(list);
list.Clear();
list.Add(v1);
list.Add(v0);
list.Add(v4);
list.Add(v5);
m.CreatePolygon(list);
list.Clear();
list.Add(v2);
list.Add(v1);
list.Add(v5);
list.Add(v6);
m.CreatePolygon(list);
list.Clear();
list.Add(v3);
list.Add(v2);
list.Add(v6);
list.Add(v7);
m.CreatePolygon(list);
list.Clear();
list.Add(v0);
list.Add(v3);
list.Add(v7);
list.Add(v4);
m.CreatePolygon(list);
return m;
}
示例6: Test_That_Default_Encrpytion_Can_Be_Restored_And_That_Algorithms_Are_Applied_Correctly
public void Test_That_Default_Encrpytion_Can_Be_Restored_And_That_Algorithms_Are_Applied_Correctly()
{
// Arrange
var serializableObject = new SerializableClass { Field = "Test_That_Default_Encrpytion_Can_Be_Restored_And_That_Algorithms_Are_Applied_Correctly" };
var streamWithEncryption = new List<byte>();
var streamWithDefaultEncryption = new List<byte>();
var streamWithOverriddenEncryption = new List<byte>();
var streamWithRestoredDefaultEncryption = new List<byte>();
var dataContractSerializer = new DataContractSerializer(serializableObject.GetType());
var serializerEncryptor = new DataContractSerializerEncrpytor(dataContractSerializer);
// Setup a mock stream
var mockStream = new Mock<Stream>();
mockStream.SetupAllProperties();
mockStream.Setup(stream => stream.Write(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>()))
.Callback(
(byte[] buffer, int offset, int count) =>
streamWithEncryption.AddRange(buffer));
mockStream.SetupGet(stream => stream.CanWrite).Returns(true);
// Act
// Setup default encrpytion output
serializerEncryptor.WriteObjectEncrypted(mockStream.Object, serializableObject);
streamWithDefaultEncryption.AddRange(streamWithEncryption);
// Change and apply encrpytion
serializerEncryptor.OverrideEncryption(
new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 },
new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 },
new DESCryptoServiceProvider());
streamWithEncryption.Clear();
serializerEncryptor.WriteObjectEncrypted(mockStream.Object, serializableObject);
streamWithOverriddenEncryption.AddRange(streamWithEncryption);
// Now change the encrpytion back
serializerEncryptor.RestoreDefaultEncryption();
streamWithEncryption.Clear();
serializerEncryptor.WriteObjectEncrypted(mockStream.Object, serializableObject);
streamWithRestoredDefaultEncryption.AddRange(streamWithEncryption);
// Assert
// Our stream with default encrpytion should equal our stream with restored encryption
Assert.IsTrue(streamWithDefaultEncryption.SequenceEqual(streamWithRestoredDefaultEncryption));
// Both default and restored encryption schemes should be differed from the overriden one.
Assert.IsFalse(streamWithDefaultEncryption.SequenceEqual(streamWithOverriddenEncryption));
Assert.IsFalse(streamWithRestoredDefaultEncryption.SequenceEqual(streamWithOverriddenEncryption));
}
示例7: VerifyAddRemoveCollectionEvents
/// <summary>
/// Verifies that the expected collection events are raised from the <see cref="ValidationResultCollection"/>
/// for validation results with the specified member names.
/// </summary>
/// <param name="validationResultMemberNames">
/// The array of member names to create validation results for that will be
/// added and removed from the collection.
/// </param>
/// <param name="errorsChangedMemberNames">The array of member names to expect errors changed events for.</param>
private static void VerifyAddRemoveCollectionEvents(string[] validationResultMemberNames, string[] errorsChangedMemberNames)
{
int collectionChangedCount = 0;
int hasErrorsChangedCount = 0;
List<string> propertyErrorsChangedList = new List<string>();
Action collectionChanged = () => ++collectionChangedCount;
Action hasErrorsChanged = () => ++hasErrorsChangedCount;
Action<string> propertyErrorsChanged = propertyName => propertyErrorsChangedList.Add(propertyName);
ValidationResultCollection collection = new TestValidationResultCollection(collectionChanged, hasErrorsChanged, propertyErrorsChanged);
ValidationResult vr1 = new ValidationResult("Error 1", validationResultMemberNames);
collection.Add(vr1);
Assert.AreEqual<int>(1, collectionChangedCount, "CollectionChanged count for first add");
Assert.AreEqual<int>(1, hasErrorsChangedCount, "HasErrorsChanged count for first add");
Assert.IsTrue(propertyErrorsChangedList.OrderBy(s => s).SequenceEqual(errorsChangedMemberNames.OrderBy(s => s)), "propertyErrorsChangedList for first add");
collectionChangedCount = 0;
hasErrorsChangedCount = 0;
propertyErrorsChangedList.Clear();
ValidationResult vr2 = new ValidationResult("Error 2", validationResultMemberNames);
collection.Add(vr2);
Assert.AreEqual<int>(1, collectionChangedCount, "CollectionChanged count for second add");
Assert.AreEqual<int>(0, hasErrorsChangedCount, "HasErrorsChanged count for second add");
Assert.IsTrue(propertyErrorsChangedList.OrderBy(s => s).SequenceEqual(errorsChangedMemberNames.OrderBy(s => s)), "propertyErrorsChangedList for second add");
collectionChangedCount = 0;
hasErrorsChangedCount = 0;
propertyErrorsChangedList.Clear();
collection.Remove(vr1);
Assert.AreEqual<int>(1, collectionChangedCount, "CollectionChanged count for first remove");
Assert.AreEqual<int>(0, hasErrorsChangedCount, "HasErrorsChanged count for first remove");
Assert.IsTrue(propertyErrorsChangedList.OrderBy(s => s).SequenceEqual(errorsChangedMemberNames.OrderBy(s => s)), "propertyErrorsChangedList for first remove");
collectionChangedCount = 0;
hasErrorsChangedCount = 0;
propertyErrorsChangedList.Clear();
collection.Remove(vr2);
Assert.AreEqual<int>(1, collectionChangedCount, "CollectionChanged count for second remove");
Assert.AreEqual<int>(1, hasErrorsChangedCount, "HasErrorsChanged count for second remove");
Assert.IsTrue(propertyErrorsChangedList.OrderBy(s => s).SequenceEqual(errorsChangedMemberNames.OrderBy(s => s)), "propertyErrorsChangedList for second remove");
}
示例8: MatrixFrameworkStyleEnumeratorTestFrameworkSet
public void MatrixFrameworkStyleEnumeratorTestFrameworkSet()
{
var matrix = new MatrixRotation.Matrix<int>(7, 6);
var i = 1;
for (int r = 0; r < matrix.RowCount; r++)
{
for (int c = 0; c < matrix.ColumnCount; c++)
{
matrix[r, c] = i;
i += 1;
}
}
var listOfElements = new List<int>();
var positionEnumerator = new MatrixRotation.PositionOnMatrixFramewokStyleEnumerator(matrix.RowCount, matrix.ColumnCount, 0);
while (positionEnumerator.MoveNext())
{
listOfElements.Add(matrix[positionEnumerator.Current.Row, positionEnumerator.Current.Column]);
}
Assert.AreEqual(
@"1 2 3 4 5 6 12 18 24 30 36 42 41 40 39 38 37 31 25 19 13 7", string.Join(" ", listOfElements));
listOfElements.Clear();
var positionEnumerator1 = new MatrixRotation.PositionOnMatrixFramewokStyleEnumerator(matrix.RowCount, matrix.ColumnCount, 1);
while (positionEnumerator1.MoveNext())
{
listOfElements.Add(matrix[positionEnumerator1.Current.Row, positionEnumerator1.Current.Column]);
}
Assert.AreEqual(
@"8 9 10 11 17 23 29 35 34 33 32 26 20 14", string.Join(" ", listOfElements));
listOfElements.Clear();
var positionEnumerator2 = new MatrixRotation.PositionOnMatrixFramewokStyleEnumerator(matrix.RowCount, matrix.ColumnCount, 2);
while (positionEnumerator2.MoveNext())
{
listOfElements.Add(matrix[positionEnumerator2.Current.Row, positionEnumerator2.Current.Column]);
}
Assert.AreEqual(
@"15 16 22 28 27 21", string.Join(" ", listOfElements));
}
示例9: MultipleModelsDependenciesTest
public void MultipleModelsDependenciesTest()
{
List<string> property_notifications = new List<string>();
ModelA ma = new ModelA() { PropA = 1 };
ModelB mb = new ModelB() { PropB = 2 };
ViewModel vm = new ViewModel(ma, mb);
int current_total;
ma.PropertyChanged += (sender, args) => property_notifications.Add("ModelA:" + args.PropertyName);
mb.PropertyChanged += (sender, args) => property_notifications.Add("ModelB:" + args.PropertyName);
vm.PropertyChanged += (sender, args) => property_notifications.Add("ViewModel:" + args.PropertyName);
ma.PropA = 2;
Assert.AreEqual(2, property_notifications.Count);
Assert.IsTrue(property_notifications.Contains("ModelA:PropA"));
Assert.IsTrue(property_notifications.Contains("ViewModel:Total"));
property_notifications.Clear();
mb.PropB = 40;
Assert.AreEqual(2, property_notifications.Count);
Assert.IsTrue(property_notifications.Contains("ModelB:PropB"));
Assert.IsTrue(property_notifications.Contains("ViewModel:Total"));
var total_property = TypeDescriptor.GetProperties(vm)["Total"];
var total = total_property.GetValue(vm);
Assert.AreEqual(42, total);
}
示例10: CheckCEValues
public void CheckCEValues(string filePath, int ceCount)
{
List<string> ceValues = new List<string>();
string[] lines = File.ReadAllLines(filePath);
string precursor = lines[0].Split(TextUtil.SEPARATOR_CSV)[0];
foreach (var line in lines)
{
var columns = line.Split(TextUtil.SEPARATOR_CSV);
var ce = columns[2];
var secondPrecursor = columns[0];
// Different CE values for each precursor ion, repeated for each
// product ion of the precursor.
if (precursor != secondPrecursor)
{
Assert.IsTrue(ceValues.Count == ceCount);
ceValues.Clear();
precursor = secondPrecursor;
}
// Only add once per precursor
if (!ceValues.Contains(ce))
ceValues.Add(ce);
}
// Check last precusor set.
Assert.IsTrue(ceValues.Count == ceCount);
}
示例11: addAllVerticalPointsToListTest
public void addAllVerticalPointsToListTest()
{
List<Point> list = new List<Point>();
List<Point> listExpected = new List<Point>();
int miny = 0;
int maxy = 4;
int x = 1;
listExpected.Add(new Point(x, 0));
listExpected.Add(new Point(x, 1));
listExpected.Add(new Point(x, 2));
listExpected.Add(new Point(x, 3));
listExpected.Add(new Point(x, 4));
ArraySpaceUtilities.addAllVerticalPointsToList(ref list, miny, maxy, x, true);
Assert.AreEqual(listExpected.Count, list.Count);
Point[] listasarray = list.ToArray();
Point[] expectedlistasarray = listExpected.ToArray();
for (int i = 0; i < listasarray.Length; i++)
{
Assert.AreEqual(true, listasarray[i].Equals(expectedlistasarray[i]));
}
listExpected.Reverse();
list.Clear();
ArraySpaceUtilities.addAllVerticalPointsToList(ref list, miny, maxy, x, false);
Assert.AreEqual(listExpected.Count, list.Count);
listasarray = list.ToArray();
expectedlistasarray = listExpected.ToArray();
for (int i = 0; i < listasarray.Length; i++)
{
Assert.AreEqual(true, listasarray[i].Equals(expectedlistasarray[i]));
}
}
示例12: LocateNeighbours
public void LocateNeighbours()
{
var db = new LocalityQueryProximityDatabase<object>(Vector3.Zero, new Vector3(10, 10, 10), new Vector3(2, 2, 2));
Dictionary<object, Vector3> positionLookup = new Dictionary<object, Vector3>();
var xyz000 = CreateToken(db, new Vector3(0, 0, 0), positionLookup);
var xyz100 = CreateToken(db, new Vector3(1, 0, 0), positionLookup);
CreateToken(db, new Vector3(3, 0, 0), positionLookup);
var list = new List<object>();
xyz000.FindNeighbors(Vector3.Zero, 2, list);
Assert.AreEqual(2, list.Count);
Assert.AreEqual(1, list.Count(a => positionLookup[a] == new Vector3(0, 0, 0)));
Assert.AreEqual(1, list.Count(a => positionLookup[a] == new Vector3(1, 0, 0)));
//Check tokens handle being disposed twice
xyz000.Dispose();
xyz000.Dispose();
list.Clear();
xyz100.FindNeighbors(Vector3.Zero, 1.5f, list);
Assert.AreEqual(1, list.Count);
Assert.AreEqual(new Vector3(1, 0, 0), positionLookup[list[0]]);
}
示例13: BasicOperations
public static async Task BasicOperations(IOdin clive)
{
await clive.Put("foo", "bar");
Assert.AreEqual("bar", await clive.Get("foo"));
await clive.Put("foo", "baz");
Assert.AreEqual("baz", await clive.Get("foo"));
await clive.Delete("foo");
Assert.AreEqual(null, await clive.Get("foo"));
await clive.Delete("foo");
var tasks = new List<Task>();
for (var i = 0; i < 100; i++)
{
tasks.Add(clive.Put(i.ToString().PadLeft(4, '0'), i.ToString()));
}
await Task.WhenAll(tasks);
tasks.Clear();
var items = (await clive.Search()).ToArray();
Assert.AreEqual(100, items.Length);
Assert.AreEqual("0000", items[0].Key);
Assert.AreEqual("0099", items[99].Key);
items = (await clive.Search(start: "0001", end: "0010")).ToArray();
Assert.AreEqual(10, items.Length);
Assert.AreEqual("0001", items[0].Key);
Assert.AreEqual("0010", items[9].Key);
for (var i = 0; i < 100; i++)
{
tasks.Add(clive.Delete(i.ToString()));
}
}
示例14: LocateNeighbours
public void LocateNeighbours()
{
var db = new BruteForceProximityDatabase<object>();
Dictionary<object, Vector3> positionLookup = new Dictionary<object, Vector3>();
var x0y0z0 = CreateToken(db, new Vector3(0, 0, 0), positionLookup);
var x1y0z0 = CreateToken(db, new Vector3(1, 0, 0), positionLookup);
var x3y0z0 = CreateToken(db, new Vector3(3, 0, 0), positionLookup);
var list = new List<object>();
x0y0z0.FindNeighbors(Vector3.Zero, 2, list);
Assert.AreEqual(2, list.Count);
Assert.AreEqual(new Vector3(0, 0, 0), positionLookup[list[0]]);
Assert.AreEqual(new Vector3(1, 0, 0), positionLookup[list[1]]);
//Check tokens handle being disposed twice
x1y0z0.Dispose();
x1y0z0.Dispose();
//Check tokens handle being collected after being disposed
GC.Collect();
GC.WaitForPendingFinalizers();
list.Clear();
x0y0z0.FindNeighbors(Vector3.Zero, 2, list);
Assert.AreEqual(1, list.Count);
Assert.AreEqual(new Vector3(0, 0, 0), positionLookup[list[0]]);
}
示例15: WhenModelIsSet_IsValidIsUpdated
public void WhenModelIsSet_IsValidIsUpdated()
{
var vm = new SchedulerViewModel();
var model = new SchedulerDescriptorEditMock();
var propertiesChanged = new List<string>();
model.MakeValid();
vm.PropertyChanged += (o, e) => propertiesChanged.Add(e.PropertyName);
// Act.
vm.Model = model;
Assert.IsTrue(vm.IsValid);
Assert.IsTrue(propertiesChanged.Any(p => p == "IsValid"));
model = new SchedulerDescriptorEditMock();
model.MakeInvalid();
propertiesChanged.Clear();
// Act.
vm.Model = model;
Assert.IsFalse(vm.IsValid);
Assert.IsTrue(propertiesChanged.Any(p => p == "IsValid"));
}