Skip to content
Snippets Groups Projects
Commit 03cf9e3d authored by Tobias's avatar Tobias
Browse files

Readded GetComponents to Provider

parent a5cc8ead
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ namespace ControlComponents.Core ...@@ -8,6 +8,7 @@ namespace ControlComponents.Core
public interface IControlComponentProvider public interface IControlComponentProvider
{ {
T GetComponent<T>(string id) where T : IControlComponent; T GetComponent<T>(string id) where T : IControlComponent;
IEnumerable<T> GetComponents<T>();
} }
// TODO there can be also providers to search the network and create network cc to access the real one (factory) // TODO there can be also providers to search the network and create network cc to access the real one (factory)
...@@ -26,5 +27,10 @@ namespace ControlComponents.Core ...@@ -26,5 +27,10 @@ namespace ControlComponents.Core
throw new InvalidOperationException($"Cannot cast {id} to {typeof(T)}", e); throw new InvalidOperationException($"Cannot cast {id} to {typeof(T)}", e);
} }
} }
public IEnumerable<T> GetComponents<T>()
{
return this.Values.Where(c => c is T).Select(c => (T)c);
}
} }
} }
\ No newline at end of file
using System; using System;
using System.Collections.ObjectModel; using System.Linq;
using System.Threading.Tasks;
using AutoFixture.NUnit3; using AutoFixture.NUnit3;
using FluentAssertions; using FluentAssertions;
using Moq;
using NUnit.Framework; using NUnit.Framework;
namespace ControlComponents.Core.Tests namespace ControlComponents.Core.Tests
...@@ -29,5 +27,16 @@ namespace ControlComponents.Core.Tests ...@@ -29,5 +27,16 @@ namespace ControlComponents.Core.Tests
act.Should().Throw<InvalidOperationException>(); act.Should().Throw<InvalidOperationException>();
} }
[Test, AutoData]
public void Given_TypeAvailable_When_GetComponents_Then_ReturnComponents(ControlComponentProvider provider, ControlComponent cc)
{
provider.Add(cc.ComponentName, cc);
var c = provider.GetComponents<ControlComponent>();
c.Count().Should().Be(1);
c.First().ComponentName.Should().Be(cc.ComponentName);
}
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment