Many thanks m.aliozkaya
This has resolved the issue. To help anyone else, this is the complete code segment for unit testing an app service that utilies SignalR:
var fakeDocumentHub = Substitute.For<IHubContext<DocumentHub>>();
LocalIocManager.IocContainer.Register(Component.For<IHubContext<DocumentHub>>().Instance(fakeDocumentHub).IsDefault());
var _documentsAppService = Resolve<IDocumentsAppService>();
Do this to get the service instance instead of using Dependency Injection in the unit test class itself.
Thanks again m.aliozkaya
Seems to be an issue when trying to write & run tests (in the .Test project), that access services that use a hub
I'm assuming the startup.cs from the MVC project does not get run when the tests run so how can we ensure these dependencies are registered within the .Test project in the same way they are within the .Mvc project like below:
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<AbpCommonHub>("/signalr");
endpoints.MapHub<ChatHub>("/signalr-chat");
endpoints.MapHub<AgendaHub>("/signalr-agenda");
endpoints.MapHub<MinuteHub>("/signalr-minute");
endpoints.MapHub<DocumentHub>("/signalr-document-conversion");
});
There appears to be no startup.cs file in the .Test project to try the same code. Trying to register the Hub in the same way as we register services in the test project:
public Security_Tests()
{
_documentHub = Resolve<IHubContext<DocumentHub>>();
_documentsAppService = Resolve<IDocumentsAppService>(); // Service that uses the DocumentHub
}
Results in:
Abp.AbpException : Can not register IHubContext`1. It should be a non-abstract class. If not, it should be registered before.
Many thanks
Hi,
using Microsoft.AspNetCore.SignalR;
namespace Congresso.Documents
{
public class DocumentHub : Hub
{
}
}
I did check the link to ensure that the necessary packages are also installed.
Hi,
Yes I already have it added in my startup. The other ones don't seem to be erroring.
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<AbpCommonHub>("/signalr");
endpoints.MapHub<ChatHub>("/signalr-chat");
endpoints.MapHub<AgendaHub>("/signalr-agenda");
endpoints.MapHub<MinuteHub>("/signalr-minute");
endpoints.MapHub<DocumentHub>("/signalr-document-conversion");
});
Hi,
I think you can directly use an if statement instead of combaning strings.
Could you give an example?
Yes both the Id of the parent and child match
Is there anything else we can do about the size of this file? It just seems to be a list of all our app services. The solution I have provided above allows it to be cached, however, it is still a very large file to be loading on initial load.
Thanks
We have resolved the issue by generating the file only once on application start. Saving it in the wwwroot and referencing that instead. This is allowing the file to be cached:
public void GenerateScripts()
{
var output = GetAll(new ApiProxyGenerationModel() { Minify = true, Type = "jquery" });
string fullFileLocation = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\Common\Scripts", "AbpServiceProxies.min.js");
using (FileStream fs = new System.IO.FileStream(fullFileLocation, FileMode.Create))
{
StreamWriter writer = new StreamWriter(fs);
writer.Write(_javaScriptMinifier.Minify(output.Content));
writer.Close();
}
Thank you to **apchenjun **for his solution on this thread: https://github.com/aspnetboilerplate/aspnetboilerplate/issues/5379
Hi ismcagdas, thanks for your reply.
It is 55mb when minified which is still crazy to be loading on every page load.
I can create a custom controller but how will this help with caching/load times?
Thanks Scott