public void RuntimeDetectsAllClientPacketProcessors() { ContainerBuilder containerBuilder = new ContainerBuilder(); ClientAutoFacRegistrar clientDependencyRegistrar = new ClientAutoFacRegistrar(); NitroxServiceLocator.InitializeDependencyContainer(clientDependencyRegistrar); NitroxServiceLocator.BeginNewLifetimeScope(); // Check if every PacketProcessor has been detected: typeof(Multiplayer).Assembly.GetTypes() .Where(p => typeof(PacketProcessor).IsAssignableFrom(p) && p.IsClass && !p.IsAbstract) .ToList() .ForEach(processor => { try { Assert.IsTrue(NitroxServiceLocator.LocateOptionalService(processor.BaseType).IsPresent(), $"{processor} has not been discovered by the runtime code!"); } catch (Autofac.Core.DependencyResolutionException ex) { if (ex.InnerException.GetType() != typeof(System.Security.SecurityException)) { throw ex; } } } ); }
public void AllPacketsAreHandled() { World world = new World(); ContainerBuilder serverContainerBuilder = new ContainerBuilder(); ServerAutoFacRegistrar serverDependencyRegistrar = new ServerAutoFacRegistrar(); serverDependencyRegistrar.RegisterDependencies(serverContainerBuilder); IContainer serverDependencyContainer = serverContainerBuilder.Build(ContainerBuildOptions.IgnoreStartableComponents); List <Type> packetTypes = typeof(DefaultServerPacketProcessor).Assembly.GetTypes() .Where(p => typeof(PacketProcessor).IsAssignableFrom(p) && p.IsClass && !p.IsAbstract) .ToList(); ContainerBuilder containerBuilder = new ContainerBuilder(); ClientAutoFacRegistrar clientDependencyRegistrar = new ClientAutoFacRegistrar(); clientDependencyRegistrar.RegisterDependencies(containerBuilder); IContainer clientDependencyContainer = containerBuilder.Build(ContainerBuildOptions.IgnoreStartableComponents); typeof(Packet).Assembly.GetTypes() .Where(p => typeof(Packet).IsAssignableFrom(p) && p.IsClass && !p.IsAbstract) .ToList() .ForEach(packet => { Type clientPacketProcessorType = typeof(ClientPacketProcessor <>); Type clientProcessorType = clientPacketProcessorType.MakeGenericType(packet); Console.WriteLine("Checking handler for packet {0}...", packet); Assert.IsTrue(packetTypes.Contains(packet) || clientDependencyContainer.Resolve(clientProcessorType) != null, $"Runtime has not detected a handler for {packet}!"); } ); }
public void AllPacketsAreHandled() { World world = new World(); ContainerBuilder serverContainerBuilder = new ContainerBuilder(); ServerAutoFacRegistrar serverDependencyRegistrar = new ServerAutoFacRegistrar(); NitroxServiceLocator.InitializeDependencyContainer(serverDependencyRegistrar); NitroxServiceLocator.BeginNewLifetimeScope(); List <Type> packetTypes = typeof(DefaultServerPacketProcessor).Assembly.GetTypes() .Where(p => typeof(PacketProcessor).IsAssignableFrom(p) && p.IsClass && !p.IsAbstract) .ToList(); ContainerBuilder containerBuilder = new ContainerBuilder(); ClientAutoFacRegistrar clientDependencyRegistrar = new ClientAutoFacRegistrar(); NitroxServiceLocator.InitializeDependencyContainer(clientDependencyRegistrar); NitroxServiceLocator.BeginNewLifetimeScope(); typeof(Packet).Assembly.GetTypes() .Where(p => typeof(Packet).IsAssignableFrom(p) && p.IsClass && !p.IsAbstract) .ToList() .ForEach(packet => { Type clientPacketProcessorType = typeof(ClientPacketProcessor <>); Type clientProcessorType = clientPacketProcessorType.MakeGenericType(packet); Console.WriteLine("Checking handler for packet {0}...", packet); Assert.IsTrue(packetTypes.Contains(packet) || NitroxServiceLocator.LocateOptionalService(clientProcessorType).IsPresent(), $"Runtime has not detected a handler for {packet}!"); } ); }
public void RuntimeDetectsAllClientPacketProcessors() { ContainerBuilder containerBuilder = new ContainerBuilder(); ClientAutoFacRegistrar clientDependencyRegistrar = new ClientAutoFacRegistrar(); clientDependencyRegistrar.RegisterDependencies(containerBuilder); IContainer clientDependencyContainer = containerBuilder.Build(ContainerBuildOptions.IgnoreStartableComponents); // Check if every PacketProcessor has been detected: typeof(Multiplayer).Assembly.GetTypes() .Where(p => typeof(PacketProcessor).IsAssignableFrom(p) && p.IsClass && !p.IsAbstract) .ToList() .ForEach(processor => Assert.IsTrue(clientDependencyContainer.Resolve(processor.BaseType) != null, $"{processor} has not been discovered by the runtime code!") ); }