예제 #1
0
        public void DiscordSocketConfigFactory_LogSeverityParsingTest(string input, LogSeverity expected)
        {
            var json   = $@"{{ ""LogLevel"" : ""{input}"" }}";
            var actual = DiscordSocketConfigFactory.FromJson(json).LogLevel;

            Assert.Equal(expected, actual);
        }
예제 #2
0
        public void ConfigDefaultTest()
        {
            const int  expectedMsgChacheSize       = 0;
            const bool expectedAlwaysDownloadUsers = false;

            var actual = DiscordSocketConfigFactory.GetDefault();

            Assert.Equal(expectedMsgChacheSize, actual.MessageCacheSize);
            Assert.Equal(expectedAlwaysDownloadUsers, actual.AlwaysDownloadUsers);
        }
예제 #3
0
        public void ConfigFromJson_DuplicateKeyTest()
        {
            const int expected = 100;

            var json = $@"{{ 
                ""MessageCacheSize"" : ""75"",
                ""AlwaysDownloadUsers"" : ""true"",
                ""MessageCacheSize"" : ""{expected}"",
            }}";

            var actual = DiscordSocketConfigFactory.FromJson(json);

            Assert.Equal(expected, actual.MessageCacheSize);
        }
예제 #4
0
        public void ConfigFromJson_InvalidJsonValuesTest()
        {
            const int  expectedMsgCacheSize        = 0;
            const bool expectedAlwaysDownloadUsers = false;

            var json = $@"{{ 
                ""MessageCacheSize"" : ""Hello, World!"",
                ""AlwaysDownloadUsers"" : ""Invalid Boolean""
            }}";

            var actual = DiscordSocketConfigFactory.FromJson(json);

            Assert.Equal(expectedMsgCacheSize, actual.MessageCacheSize);
            Assert.Equal(expectedAlwaysDownloadUsers, actual.AlwaysDownloadUsers);
        }
예제 #5
0
        public void ConfigFromJson_IgnoreExtraValuesTest()
        {
            const int  expectedMsgCacheSize        = 10;
            const bool expectedAlwaysDownloadUsers = true;

            var json = $@"{{ 
                ""ExtraProperty1"" : ""Value 1"",
                ""MessageCacheSize"" : ""{expectedMsgCacheSize}"",
                ""AlwaysDownloadUsers"" : ""{expectedAlwaysDownloadUsers}"",
                ""ExtraProperty2"" : ""Value 2""
            }}";

            var actual = DiscordSocketConfigFactory.FromJson(json);

            Assert.Equal(expectedMsgCacheSize, actual.MessageCacheSize);
            Assert.Equal(expectedAlwaysDownloadUsers, actual.AlwaysDownloadUsers);
        }
예제 #6
0
        public void ConfigFromJsonTest()
        {
            const int         expectedMsgCacheSize        = 10;
            const bool        expectedAlwaysDownloadUsers = true;
            const LogSeverity expectedLogSev = LogSeverity.Debug;

            var json = $@"{{ 
                ""MessageCacheSize"" : ""{expectedMsgCacheSize}"",
                ""AlwaysDownloadUsers"" : ""{expectedAlwaysDownloadUsers}"",
                ""LogLevel"" : ""Debug""
            }}";

            var actual = DiscordSocketConfigFactory.FromJson(json);

            Assert.Equal(expectedMsgCacheSize, actual.MessageCacheSize);
            Assert.Equal(expectedAlwaysDownloadUsers, actual.AlwaysDownloadUsers);
            Assert.Equal(expectedLogSev, actual.LogLevel);
        }
예제 #7
0
        public static void RegisterTypes()
        {
            _container = new UnityContainer();
            // _container.RegisterType<ILocalization, JsonLocalization>(new ContainerControlledLifetimeManager());
            // _container.RegisterType<IDataStorage, JsonLocalStorage>(new ContainerControlledLifetimeManager());
            // _container.RegisterType<AppConfig>(new ContainerControlledLifetimeManager());
            // _container.RegisterType<RpgRepository>(new ContainerControlledLifetimeManager());
            // _container.RegisterType<Discord.Connection>(new ContainerControlledLifetimeManager());
            // _container.RegisterType<VerificationProvider>(new ContainerControlledLifetimeManager());

            _container.RegisterSingleton <ILocalization, JsonLocalization>();
            _container.RegisterSingleton <IDataStorage, JsonLocalStorage>();
            _container.RegisterSingleton <AppConfig>();
            _container.RegisterSingleton <RpgRepository>();
            _container.RegisterSingleton <Discord.Connection>();
            _container.RegisterSingleton <VerificationProvider>();
            _container.RegisterSingleton <WaitingRoomService>();
            _container.RegisterSingleton <ProblemBoardService>();
            _container.RegisterSingleton <ProblemProvider>();
            _container.RegisterSingleton <CommandHandler>();
            _container.RegisterType <DiscordSocketConfig>(new InjectionFactory(c => DiscordSocketConfigFactory.GetDefault()));
            _container.RegisterSingleton <DiscordSocketClient>(new InjectionConstructor(typeof(DiscordSocketConfig)));
        }
예제 #8
0
        public void ConfigFromJson_InvalidJsonDoesNotThrowTest()
        {
            const string json = "Not a proper json string.";

            DiscordSocketConfigFactory.FromJson(json);
        }