Skip to content

Commit

Permalink
FbParameterCollection.Clear does not reset Parent for FbParameter fix…
Browse files Browse the repository at this point in the history
… (DNET-635).
  • Loading branch information
cincuranet committed Sep 30, 2015
1 parent 37692da commit 42ccc97
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
Expand Up @@ -160,7 +160,7 @@ public FbParameter Add(FbParameter value)
{
EnsureFbParameterAddOrInsert(value);

value.Parent = this;
AttachParameter(value);
_parameters.Add(value);
return value;
}
Expand Down Expand Up @@ -228,7 +228,7 @@ public void Insert(int index, FbParameter value)
{
EnsureFbParameterAddOrInsert(value);

value.Parent = this;
AttachParameter(value);
_parameters.Insert(index, value);
}

Expand All @@ -246,7 +246,7 @@ public void Remove(FbParameter value)
throw new ArgumentException("The parameter does not exist in the collection.");
}

value.Parent = null;
ReleaseParameter(value);
}

public override void Remove(object value)
Expand All @@ -265,7 +265,7 @@ public override void RemoveAt(int index)

FbParameter parameter = this[index];
_parameters.RemoveAt(index);
parameter.Parent = null;
ReleaseParameter(parameter);
}

public override void RemoveAt(string parameterName)
Expand All @@ -285,7 +285,12 @@ public override void CopyTo(Array array, int index)

public override void Clear()
{
var parameters = _parameters.ToArray();
_parameters.Clear();
foreach (var parameter in parameters)
{
ReleaseParameter(parameter);
}
}

public override IEnumerator GetEnumerator()
Expand Down Expand Up @@ -383,6 +388,16 @@ private void EnsureFbParameterAddOrInsert(FbParameter value)
}
}

private void AttachParameter(FbParameter parameter)
{
parameter.Parent = this;
}

private void ReleaseParameter(FbParameter parameter)
{
parameter.Parent = null;
}

#endregion
}
}
Expand Up @@ -108,7 +108,7 @@ public void CheckFbParameterParentPropertyInvariant()
{
var collection = new FbParameterCollection();
var parameter = collection.Add("Name", FbDbType.Array);
Assert.AreSame(collection, parameter.Parent);
Assert.AreEqual(collection, parameter.Parent);
Assert.Throws<ArgumentException>(() => collection.Add(parameter));
Assert.Throws<ArgumentException>(() => collection.AddRange(new FbParameter[] { parameter }));

Expand All @@ -118,10 +118,20 @@ public void CheckFbParameterParentPropertyInvariant()
Assert.Throws<ArgumentException>(() => collection.Remove(parameter));

collection.Insert(0, parameter);
Assert.AreSame(collection, parameter.Parent);
Assert.AreEqual(collection, parameter.Parent);
Assert.Throws<ArgumentException>(() => collection.Insert(0, parameter));
}

[Test]
public void DNET635_ResetsParentOnClear()
{
var collection = new FbParameterCollection();
var parameter = collection.Add("test", 0);
Assert.IsNotNull(parameter.Parent);
collection.Clear();
Assert.IsNull(parameter.Parent);
}

#endregion
}
}

0 comments on commit 42ccc97

Please sign in to comment.