-
-
Notifications
You must be signed in to change notification settings - Fork 0
#Refactor namespaces and enhance service locator tests #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
3caec7e
147a8c9
2f6ee46
f0b785d
1b75de7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| namespace vb2ae.ServiceLocator.MSDependencyInjection.Tests.Models | ||
| { | ||
| public class Cat : IPet | ||
| { | ||
| public string Speak() | ||
| { | ||
| return "Meow"; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| namespace vb2ae.ServiceLocator.MSDependencyInjection.Tests.Models | ||
| { | ||
| public class Dog : IPet | ||
| { | ||
| public string Speak() | ||
| { | ||
| return "Bark"; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| namespace vb2ae.ServiceLocator.MSDependencyInjection.Tests.Models | ||
| { | ||
| public interface ICar | ||
| { | ||
| string Name { get; set; } | ||
| } | ||
|
|
||
| public class Ford : ICar | ||
| { | ||
| public string Name { get; set; } = "Ford"; | ||
| } | ||
|
|
||
| public class Toyota : ICar | ||
| { | ||
| public string Name { get; set; } = "Toyota"; | ||
| } | ||
|
|
||
| public class Chevy : ICar | ||
| { | ||
| public string Name { get; set; } = "Chevy"; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace vb2ae.ServiceLocator.MSDependencyInjection.Tests.Models | ||
| { | ||
| public interface IPet | ||
| { | ||
| string Speak(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace vb2ae.ServiceLocator.MSDependencyInjection.Tests.Models | ||
| { | ||
| public interface IService | ||
| { | ||
| void DoSomething(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,100 @@ | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using vb2ae.ServiceLocator.MSDependencyInjection.Tests.Models; | ||
|
|
||
| namespace vb2ae.ServiceLocator.MSDependencyInjection.Tests | ||
| { | ||
| public class ServiceLocatorTests | ||
| public class MSDependencyInjectionServiceLocatorTests | ||
| { | ||
| private readonly IServiceProvider _serviceProvider; | ||
|
|
||
| public MSDependencyInjectionServiceLocatorTests(IServiceProvider serviceProvider) | ||
|
Check warning on line 10 in vb2ae.ServiceLocator.MSDependencyInjection.Tests/ServiceLocatorTests.cs
|
||
| { | ||
| _serviceProvider = serviceProvider; | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetAllInstances_Type_ReturnsInstances() | ||
| { | ||
|
Check notice on line 17 in vb2ae.ServiceLocator.MSDependencyInjection.Tests/ServiceLocatorTests.cs
|
||
|
|
||
| var result = CommonServiceLocator.ServiceLocator.Current.GetAllInstances(typeof(IService)); | ||
|
|
||
| Assert.Single(result); | ||
| } | ||
| [Fact] | ||
| public void GetAllInstances_Type_ReturnsInstancesWhenKeyIsUsed() | ||
| { | ||
|
Check notice on line 25 in vb2ae.ServiceLocator.MSDependencyInjection.Tests/ServiceLocatorTests.cs
|
||
|
|
||
vb2ae marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| var result = CommonServiceLocator.ServiceLocator.Current.GetAllInstances(typeof(IPet)); | ||
|
|
||
| Assert.Equal(2, result.Count()); | ||
| } | ||
| [Fact] | ||
| public void GetAllInstances_Generic_ReturnsInstances() | ||
| { | ||
| var result = CommonServiceLocator.ServiceLocator.Current.GetAllInstances<ICar>(); | ||
|
|
||
| Assert.Equal(3, result.Count()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetAllInstances_Generic_ReturnsInstancesWithKey() | ||
| { | ||
| var result = CommonServiceLocator.ServiceLocator.Current.GetAllInstances<IPet>(); | ||
|
|
||
| Assert.Equal(2, result.Count()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetInstance_Type_ReturnsInstance() | ||
| { | ||
| var serviceType = typeof(IService); | ||
|
|
||
| var result = CommonServiceLocator.ServiceLocator.Current.GetInstance(serviceType); | ||
|
|
||
| Assert.True(result is ServiceImpl); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetInstance_Type_WithKey() | ||
| { | ||
| var serviceType = typeof(IPet); | ||
| var key = "Cat"; | ||
|
|
||
| Assert.True(CommonServiceLocator.ServiceLocator.Current.GetInstance(serviceType, key) is Cat); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetInstance_Generic_ReturnsInstance() | ||
| { | ||
| var result = CommonServiceLocator.ServiceLocator.Current.GetInstance<IService>(); | ||
|
|
||
| Assert.True(result is IService); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetInstance_Generic_WithKey() | ||
| { | ||
| var key = "Dog"; | ||
|
|
||
| Assert.True(CommonServiceLocator.ServiceLocator.Current.GetInstance<IPet>(key) is Dog); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetService_Generic_ReturnsService() | ||
| { | ||
| var result = CommonServiceLocator.ServiceLocator.Current.GetService<IService>(); | ||
|
|
||
| Assert.True(result is IService); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void VerifyServiceLocatorCanLoadClass() | ||
| public void GetService_Type_ReturnsService() | ||
| { | ||
| var service = CommonServiceLocator.ServiceLocator.Current.GetInstance<IService>(); | ||
| Assert.NotNull(service); | ||
| var serviceType = typeof(IService); | ||
|
|
||
| var result = CommonServiceLocator.ServiceLocator.Current.GetService(serviceType); | ||
|
|
||
| Assert.True(result is IService); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.