public void TestNullValue() { var sn = new SetSnapShot <object>(1); Assert.That(sn, Has.Count.EqualTo(0)); Assert.That(sn, Is.EquivalentTo(new object[0])); Assert.That(sn.Contains(null), Is.False); Assert.That(sn.TryGetValue(null, out _), Is.False); sn.Add(null); Assert.That(sn, Has.Count.EqualTo(1)); Assert.That(sn, Is.EquivalentTo(new object[] { null })); Assert.That(sn.TryGetValue(null, out var value), Is.True); Assert.That(sn.Contains(null), Is.True); Assert.That(value, Is.Null); Assert.That(sn.Remove(null), Is.True); Assert.That(sn, Has.Count.EqualTo(0)); Assert.That(sn, Is.EquivalentTo(new object[0])); sn.Add(null); Assert.That(sn, Has.Count.EqualTo(1)); sn.Clear(); Assert.That(sn, Has.Count.EqualTo(0)); Assert.That(sn, Is.EquivalentTo(new object[0])); }
public override Task <ICollection> GetOrphansAsync(object snapshot, string entityName, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { return(Task.FromCanceled <ICollection>(cancellationToken)); } try { var sn = new SetSnapShot <T>((IEnumerable <T>)snapshot); // TODO: Avoid duplicating shortcuts and array copy, by making base class GetOrphans() more flexible if (WrappedSet.Count == 0) { return(Task.FromResult <ICollection>(sn)); } if (((ICollection)sn).Count == 0) { return(Task.FromResult <ICollection>(sn)); } return(GetOrphansAsync(sn, WrappedSet.ToArray(), entityName, Session, cancellationToken)); } catch (Exception ex) { return(Task.FromException <ICollection>(ex)); } }
public void TestDuplicates() { var list = new List <string> { "test1", "test1", "test2" }; var sn = new SetSnapShot <string>(list); Assert.That(sn, Has.Count.EqualTo(2)); Assert.That(sn.TryGetValue("test1", out _), Is.True); Assert.That(sn.TryGetValue("test2", out _), Is.True); }
public override object GetSnapshot(ICollectionPersister persister) { var clonedSet = new SetSnapShot <T>(WrappedSet.Count); var enumerable = from object current in WrappedSet select persister.ElementType.DeepCopy(current, persister.Factory); foreach (var copied in enumerable) { clonedSet.Add((T)copied); } return(clonedSet); }
public void TestCopyTo() { var list = new List <string> { "test1", null, "test2" }; var sn = new SetSnapShot <string>(list); var array = new string[3]; sn.CopyTo(array, 0); Assert.That(list, Is.EquivalentTo(array)); }
public void TestInitialization() { var list = new List <string> { "test1", null, "test2" }; var sn = new SetSnapShot <string>(list); Assert.That(sn, Has.Count.EqualTo(list.Count)); Assert.That(sn, Is.EquivalentTo(list)); Assert.That(sn.TryGetValue("test1", out _), Is.True); Assert.That(sn.TryGetValue(null, out _), Is.True); }
public override ICollection GetSnapshot(ICollectionPersister persister) { var entityMode = Session.EntityMode; var clonedSet = new SetSnapShot <object>(set.Count); var enumerable = from object current in set select persister.ElementType.DeepCopy(current, entityMode, persister.Factory); foreach (var copied in enumerable) { clonedSet.Add(copied); } return(clonedSet); }
public override ICollection GetOrphans(object snapshot, string entityName) { var sn = new SetSnapShot <object>((IEnumerable <object>)snapshot); if (set.Count == 0) { return(sn); } if (((ICollection)sn).Count == 0) { return(sn); } return(GetOrphans(sn, set.ToArray(), entityName, Session)); }
public override ICollection GetOrphans(object snapshot, string entityName) { var sn = new SetSnapShot <T>((IEnumerable <T>)snapshot); // TODO: Avoid duplicating shortcuts and array copy, by making base class GetOrphans() more flexible if (WrappedSet.Count == 0) { return(sn); } if (((ICollection)sn).Count == 0) { return(sn); } return(GetOrphans(sn, WrappedSet.ToArray(), entityName, Session)); }
public void TestSerialization() { var list = new List <string> { "test1", null, "test2" }; var sn = new SetSnapShot <string>(list); sn = Deserialize <SetSnapShot <string> >(Serialize(sn)); Assert.That(sn, Has.Count.EqualTo(list.Count)); Assert.That(sn, Is.EquivalentTo(list)); Assert.That(sn.TryGetValue("test1", out var item1), Is.True); Assert.That(item1, Is.EqualTo("test1")); Assert.That(sn.TryGetValue(null, out var nullValue), Is.True); Assert.That(nullValue, Is.Null); }