CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ServiceProviderInvocationTests.cs
Go to the documentation of this file.
1
8//using System;
9//using System.Collections.Generic;
10//using System.Linq;
11//using System.Text;
12//using System.Threading.Tasks;
13//using Csla;
14//using Csla.Reflection;
15//using Microsoft.Extensions.DependencyInjection;
16//#if !NUNIT
17//using Microsoft.VisualStudio.TestTools.UnitTesting;
18//#else
19//using NUnit.Framework;
20//using TestClass = NUnit.Framework.TestFixtureAttribute;
21//using TestInitialize = NUnit.Framework.SetUpAttribute;
22//using TestCleanup = NUnit.Framework.TearDownAttribute;
23//using TestMethod = NUnit.Framework.TestAttribute;
24//#endif
25
26//namespace Csla.Test.DataPortal
27//{
28// [TestClass]
29// public class ServiceProviderInvocationTests
30// {
31// [TestInitialize]
32// public void Initialize()
33// {
34// Csla.ApplicationContext.DefaultServiceProvider = null;
35// Csla.ApplicationContext.CurrentServiceProvider = null;
36// }
37
38// [TestMethod]
39// public async Task NoServiceProvider()
40// {
41// var obj = new TestMethods();
42// var method = new ServiceProviderMethodInfo { MethodInfo = obj.GetType().GetMethod("Method1") };
43// Assert.IsNotNull(method, "needed method");
44// await Assert.ThrowsExceptionAsync<NullReferenceException>(async () => await ServiceProviderMethodCaller.CallMethodTryAsync(obj, method, new object[] { 123 }));
45// }
46
47// [TestMethod]
48// public async Task WithServiceProvider()
49// {
50// IServiceCollection services = new ServiceCollection();
51// services.AddSingleton<ISpeak, Dog>();
52// Csla.ApplicationContext.DefaultServiceProvider = services.BuildServiceProvider();
53
54// var obj = new TestMethods();
55// var method = new ServiceProviderMethodInfo { MethodInfo = obj.GetType().GetMethod("GetSpeech") };
56// Assert.IsNotNull(method, "needed method");
57// var result = (string)await ServiceProviderMethodCaller.CallMethodTryAsync(obj, method, new object[] { 123 });
58// Assert.AreEqual("Bark", result);
59// }
60// }
61
62// public interface ISpeak
63// {
64// string Speak();
65// }
66
67// public class Dog : ISpeak
68// {
69// public string Speak()
70// {
71// return "Bark";
72// }
73// }
74
75// public class TestMethods
76// {
77// public bool Method1(int id, [Inject] ISpeak speaker)
78// {
79// return speaker == null;
80// }
81
82// public string GetSpeech(int id, [Inject] ISpeak speaker)
83// {
84// return speaker.Speak();
85// }
86// }
87//}