Ejemplo n.º 1
0
        public AuthenticationService(ILogger <AuthenticationService> logger, MicroContainer container)
        {
            _logger    = logger ?? throw new ArgumentNullException(nameof(logger));
            _container = container ?? throw new ArgumentNullException(nameof(container));

            ReloadUsers();
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public RustApiExtension(ExtensionManager manager) : base(manager)
        {
            Container = new MicroContainer()
                        .AddSingle(this)
                        .AddRustApiServices();

            _logger = Container.Get <ILogger <RustApiExtension> >();
        }
Ejemplo n.º 3
0
        public void AddGetTest_InterfaceOnly_ArgumentException()
        {
            // arrange
            var container = new MicroContainer();

            // act & assert
            Assert.Throws <ArgumentException>(() => container.Add <ITestService>());
        }
Ejemplo n.º 4
0
        public void AddGetTest_ByImplementation_NotFound()
        {
            // arrange
            var container = new MicroContainer();

            // act & assert
            container.Add <TestService>();
            Assert.Throws <KeyNotFoundException>(() => container.Get <ITestService>());
        }
Ejemplo n.º 5
0
        public void AddGetTest_SingleInstance_NotFound()
        {
            // arrange
            var container = new MicroContainer();

            // act & assert
            container.AddSingle <TestService>(new TestService());
            Assert.Throws <KeyNotFoundException>(() => container.Get <ITestService>());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Build default list of users.
        /// </summary>
        /// <param name="container">Services container.</param>
        /// <returns></returns>
        private static List <ApiUserInfo> BuildDefaultUsersList(MicroContainer container)
        {
            var result = new List <ApiUserInfo>
            {
                new ApiUserInfo("admin", Guid.NewGuid().ToString(), new List <string> {
                    AdminPermission
                }),
            };

            return(result);
        }
Ejemplo n.º 7
0
        public static MicroContainer AddHookRoutes(this MicroContainer container)
        {
            container.AddSingle <IHookRoute, HookRoute>();
            var apiRoutes = container.Get <IApiRoutes>();

            apiRoutes.AddRoute <ApiHookRequest>(
                "hook",
                args => container.Get <IHookRoute>().OnCallHook(args.User, args.Data));

            return(container);
        }
Ejemplo n.º 8
0
        public void InjectionTest_Default_NotFound()
        {
            // arrange
            var container = new MicroContainer();

            // act & assert
            container.Add <TestDepService>();

            var ex = Assert.Throws <KeyNotFoundException>(() => container.Get <TestDepService>());

            Assert.Contains(typeof(ITestService).FullName, ex.Message);
        }
Ejemplo n.º 9
0
        public void AddGetTest_ByImplementation_Found()
        {
            // arrange
            var container = new MicroContainer();

            // act
            container.Add <TestService>();
            var result = container.Get <TestService>();

            // assert
            Assert.NotNull(result);
            Assert.Equal(TestService.DefaultValue, result.Value);
        }
Ejemplo n.º 10
0
        public void AddGet_WithGeneric_Predefined()
        {
            // arrange
            var container = new MicroContainer();

            // act
            container.Add <IWithGeneric <string>, WithGeneric <string> >();
            var s1 = container.Get <IWithGeneric <string> >();

            // assert
            Assert.Equal(typeof(string), s1.GenericType);
            Assert.Throws <KeyNotFoundException>(() => container.Get <IWithGeneric <int> >());
        }
Ejemplo n.º 11
0
        public void AddGet_WithGeneric_Expected()
        {
            // arrange
            var container = new MicroContainer();

            // act
            container.Add(typeof(IWithGeneric <>), typeof(WithGeneric <>));
            var s1 = container.Get <IWithGeneric <string> >();
            var s2 = container.Get <IWithGeneric <int> >();

            // assert
            Assert.Equal(typeof(string), s1.GenericType);
            Assert.Equal(typeof(int), s2.GenericType);
        }
Ejemplo n.º 12
0
        public static MicroContainer AddSystemRoutes(this MicroContainer container)
        {
            container.AddSingle <ICommandRoute, CommandRoute>();
            var apiRoutes = container.Get <IApiRoutes>();

            apiRoutes
            .AddRoute("system/ping", args => container.Get <ISystemRoute>().OnPing(), true)
            .AddRoute("system/test/debug", args => container.Get <ISystemRoute>().OnTestDebug(), true)
            .AddRoute("system/test/info", args => container.Get <ISystemRoute>().OnTestInfo(), true)
            .AddRoute("system/test/warning", args => container.Get <ISystemRoute>().OnTestWarning(), true)
            .AddRoute("system/test/error", args => container.Get <ISystemRoute>().OnTestError(), true)
            .AddRoute("system/user", args => container.Get <ISystemRoute>().OnUserInfo(args.User));

            return(container);
        }
Ejemplo n.º 13
0
        public void InjectionTest_Default_Found()
        {
            // arrange
            var container = new MicroContainer();

            // act
            container.Add <TestDepService>();
            container.Add <ITestService, TestService>();

            var result = container.Get <TestDepService>();

            // assert
            Assert.NotNull(result);
            Assert.NotNull(result.SomeServiceInstance);
            Assert.Equal(TestService.DefaultValue, result.SomeServiceInstance.Value);
        }
Ejemplo n.º 14
0
        public void AddOptions_Default_Expected()
        {
            RustApiExtension.OxideHelper = Substitute.For <IOxideHelper>();
            RustApiExtension.OxideHelper.GetInstanceDirectory().Returns(Directory.GetCurrentDirectory());

            // arrange
            var container = new MicroContainer();

            // act
            container.LoadApiOptions();
            var options = container.Get <RustApiOptions>();

            // asserts
            Assert.NotNull(options);
            Assert.Equal("http://*:28017", options.Endpoint);
            Assert.Equal(true, options.LogToFile);
            Assert.Equal(MinimumLogLevel.Debug, options.LogLevel);
        }
Ejemplo n.º 15
0
        private IContainer RegisterRules(XmlElement configNode)
        {
            var rules = configNode.ChildNodes.OfType <XmlElement>()
                        .Where(nd => nd.NodeType == XmlNodeType.Element && nd.Name.Equals("rule"));
            var provider      = new MicroContainer("rules", "");
            var ruleInstances = new List <IRule>();

            foreach (var xRule in rules)
            {
                var ruleType     = XmlActivator.GetType(xRule);
                var ruleProvider = CreateSingleNodeContainer(xRule, "rule");
                ruleInstances.Add(XmlActivator.CreateInstance(ruleType, xRule, new[] { ruleProvider }) as IRule);
            }

            provider.Register(typeof(IEnumerable <IRule>), () => ruleInstances, true);

            return(provider);
        }
Ejemplo n.º 16
0
        public void AddGetTest_Single_Found()
        {
            // arrange
            var container     = new MicroContainer();
            var expectedValue = 101;

            // act
            container.AddSingle <ITestService, TestService>();
            var service = container.Get <ITestService>();

            ((TestService)service).Value = expectedValue;

            var result = container.Get <ITestService>();

            // assert
            Assert.NotNull(service);
            Assert.Equal(expectedValue, result.Value);
        }