-
Notifications
You must be signed in to change notification settings - Fork 865
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c769e6
commit 3a5d395
Showing
3 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* http://www.zkea.net/ | ||
* Copyright (c) ZKEASOFT. All rights reserved. | ||
* http://www.zkea.net/licenses */ | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using ZKEACMS.Account; | ||
|
||
namespace ZKEACMS.Test.Account | ||
{ | ||
[TestClass] | ||
public class UserCenterLinkTest | ||
{ | ||
private readonly IServiceProvider _serviceProvider; | ||
public UserCenterLinkTest() | ||
{ | ||
var serviceCollection = new ServiceCollection(); | ||
serviceCollection.AddTransient<IUserCenterLinkService, UserCenterLinkService>(); | ||
|
||
serviceCollection.AddTransient(provider => | ||
{ | ||
var userCenterLinksProvider = new Mock<IUserCenterLinksProvider>(); | ||
userCenterLinksProvider.Setup(m => m.GetLinks()).Returns(new List<AdminMenu> | ||
{ | ||
new AdminMenu | ||
{ | ||
Title="Menu1" | ||
}, | ||
new AdminMenu | ||
{ | ||
Title="Menu2" | ||
} | ||
}); | ||
return userCenterLinksProvider.Object; | ||
}); | ||
serviceCollection.AddTransient(provider => | ||
{ | ||
var userCenterLinksProvider = new Mock<IUserCenterLinksProvider>(); | ||
userCenterLinksProvider.Setup(m => m.GetLinks()).Returns(new List<AdminMenu> | ||
{ | ||
new AdminMenu | ||
{ | ||
Title="Menu3" | ||
}, | ||
new AdminMenu | ||
{ | ||
Title="Menu4" | ||
} | ||
}); | ||
return userCenterLinksProvider.Object; | ||
}); | ||
_serviceProvider = serviceCollection.BuildServiceProvider(); | ||
} | ||
[TestMethod] | ||
public void TestGetLinks() | ||
{ | ||
var links = _serviceProvider.GetService<IUserCenterLinkService>().GetLinks(); | ||
Assert.IsTrue(links.Count() == 4); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* http://www.zkea.net/ | ||
* Copyright (c) ZKEASOFT. All rights reserved. | ||
* http://www.zkea.net/licenses */ | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using ZKEACMS.Event; | ||
|
||
namespace ZKEACMS.Test.Event | ||
{ | ||
[TestClass] | ||
public class EventTest | ||
{ | ||
private readonly IServiceProvider _serviceProvider; | ||
public EventTest() | ||
{ | ||
var serviceCollection = new ServiceCollection(); | ||
serviceCollection.AddTransient<IEventManager, EventManager>(); | ||
|
||
serviceCollection.RegistEvent<TestEventHandler>("Test"); | ||
_serviceProvider = serviceCollection.BuildServiceProvider(); | ||
} | ||
[TestMethod] | ||
public void TestTrigger() | ||
{ | ||
_serviceProvider.GetService<IEventManager>().Trigger("Test", new object()); | ||
_serviceProvider.GetService<IEventManager>().Trigger(new EventArg { Name = "Test" }, new object()); | ||
} | ||
} | ||
public class TestEventHandler : IEventHandler | ||
{ | ||
public void Handle(object entity, EventArg e) | ||
{ | ||
Assert.IsNotNull(entity); | ||
Assert.IsNotNull(e); | ||
Assert.IsTrue(e.Name == "Test"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters