Commit 2ec03549 authored by Mark van Renswoude's avatar Mark van Renswoude

Added support and test for deleting bindings

parent e0720682
......@@ -63,6 +63,24 @@ namespace RabbitMetaQueue.Tests.Infrastructure
}
[Test]
public void DeleteBinding()
{
definedTopology.AddExchange1();
definedTopology.AddQueue1();
existingTopology.AddExchange1();
existingTopology
.AddQueue1()
.BindToExchange1("mock.key");
TestCompare(new List<string>
{
{ "db:q1:e1:mock.key" }
});
}
[Test]
public void NothingChanged()
{
......@@ -81,7 +99,7 @@ namespace RabbitMetaQueue.Tests.Infrastructure
{
existingTopology.AddExchange1();
TestCompare(new List<string>()
TestCompare(new List<string>
{
{ "de:e1" }
});
......@@ -93,7 +111,7 @@ namespace RabbitMetaQueue.Tests.Infrastructure
{
existingTopology.AddQueue1();
TestCompare(new List<string>()
TestCompare(new List<string>
{
{ "dq:q1" }
});
......
......@@ -117,7 +117,8 @@ namespace RabbitMetaQueue.Domain
CreateBinding(queue, binding);
}
// ToDo removed bindings
foreach (var binding in existingQueue.Bindings.Except(queue.Bindings, new BindingComparer()))
DeleteBinding(existingQueue, binding);
}
}
......@@ -148,6 +149,13 @@ namespace RabbitMetaQueue.Domain
}
}
private void DeleteBinding(Queue queue, Binding binding)
{
if (AllowDelete)
topologyWriter.DeleteBinding(queue, binding);
}
private static bool SameExchange(Exchange exchange, Exchange existingExchange)
{
......@@ -207,4 +215,19 @@ namespace RabbitMetaQueue.Domain
return obj.Name.GetHashCode();
}
}
class BindingComparer : IEqualityComparer<Binding>
{
public bool Equals(Binding x, Binding y)
{
return (String.Compare(x.Exchange, y.Exchange, StringComparison.Ordinal) == 0) &&
(String.Compare(x.RoutingKey, y.RoutingKey, StringComparison.Ordinal) == 0);
}
public int GetHashCode(Binding obj)
{
return (obj.Exchange + obj.RoutingKey).GetHashCode();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment