2018-07-09 19:57:08 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Claunia.PropertyList;
|
2017-03-16 23:37:42 +01:00
|
|
|
|
using Xunit;
|
2016-05-22 16:05:33 +02:00
|
|
|
|
|
2025-08-07 22:31:12 +01:00
|
|
|
|
namespace plistcil.test;
|
|
|
|
|
|
|
|
|
|
|
|
public class NSArrayTests
|
2016-05-22 16:05:33 +02:00
|
|
|
|
{
|
2025-08-07 22:31:12 +01:00
|
|
|
|
/// <summary>Tests the addition of a .NET object to the NSArray</summary>
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void AddAndContainsObjectTest()
|
2016-05-22 16:05:33 +02:00
|
|
|
|
{
|
2025-08-07 22:31:12 +01:00
|
|
|
|
var array = new NSArray
|
2016-05-22 16:05:33 +02:00
|
|
|
|
{
|
2025-08-07 22:31:12 +01:00
|
|
|
|
1
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Assert.True(array.Contains(1));
|
|
|
|
|
|
Assert.False(array.Contains(2));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>Tests the <see cref="NSArray.GetEnumerator" /> method.</summary>
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void EnumeratorTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
var array = new NSArray
|
2018-07-09 19:57:08 +01:00
|
|
|
|
{
|
2025-08-07 22:31:12 +01:00
|
|
|
|
0,
|
|
|
|
|
|
1
|
|
|
|
|
|
};
|
2018-07-09 19:57:08 +01:00
|
|
|
|
|
2025-08-07 22:31:12 +01:00
|
|
|
|
using IEnumerator<NSObject> enumerator = array.GetEnumerator();
|
2018-07-09 19:57:08 +01:00
|
|
|
|
|
2025-08-07 22:31:12 +01:00
|
|
|
|
Assert.Null(enumerator.Current);
|
2018-07-09 19:57:08 +01:00
|
|
|
|
|
2025-08-07 22:31:12 +01:00
|
|
|
|
Assert.True(enumerator.MoveNext());
|
|
|
|
|
|
Assert.Equal(new NSNumber(0), enumerator.Current);
|
2018-07-09 19:57:08 +01:00
|
|
|
|
|
2025-08-07 22:31:12 +01:00
|
|
|
|
Assert.True(enumerator.MoveNext());
|
|
|
|
|
|
Assert.Equal(new NSNumber(1), enumerator.Current);
|
2018-07-09 19:57:08 +01:00
|
|
|
|
|
2025-08-07 22:31:12 +01:00
|
|
|
|
Assert.False(enumerator.MoveNext());
|
|
|
|
|
|
}
|
2018-07-09 19:57:08 +01:00
|
|
|
|
|
2025-08-07 22:31:12 +01:00
|
|
|
|
/// <summary>Tests the <see cref="NSArray.IndexOf(object)" /> method for .NET objects.</summary>
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void IndexOfTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
var array = new NSArray
|
2016-05-22 16:05:33 +02:00
|
|
|
|
{
|
2025-08-07 22:31:12 +01:00
|
|
|
|
1,
|
|
|
|
|
|
"test"
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal(0, array.IndexOf(1));
|
|
|
|
|
|
Assert.Equal(1, array.IndexOf("test"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>Tests the <see cref="NSArray.Insert(int, object)" /> method for a .NET object.</summary>
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void InsertTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
var array = new NSArray
|
2016-05-22 16:05:33 +02:00
|
|
|
|
{
|
2025-08-07 22:31:12 +01:00
|
|
|
|
0,
|
|
|
|
|
|
1,
|
|
|
|
|
|
2
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
array.Insert(1, "test");
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal(4, array.Count);
|
|
|
|
|
|
Assert.Equal("test", array[1].ToObject());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>Tests the <see cref="NSArray.Remove(object)" /> method for a .NET object.</summary>
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void RemoveTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
var array = new NSArray
|
2016-05-22 16:05:33 +02:00
|
|
|
|
{
|
2025-08-07 22:31:12 +01:00
|
|
|
|
0
|
|
|
|
|
|
};
|
2021-04-30 13:06:04 +01:00
|
|
|
|
|
2025-08-07 22:31:12 +01:00
|
|
|
|
Assert.False(array.Remove((object)1));
|
|
|
|
|
|
Assert.True(array.Remove((object)0));
|
2016-05-22 16:05:33 +02:00
|
|
|
|
|
2025-08-07 22:31:12 +01:00
|
|
|
|
Assert.Empty(array);
|
2016-05-22 16:05:33 +02:00
|
|
|
|
}
|
2018-07-09 19:57:08 +01:00
|
|
|
|
}
|