Ejemplo n.º 1
0
        public async Task GetAuthorization_InvalidCodeFails_ThrowsHTTPException()
        {
            const string InValidCode = "ThisIsNotACode";
            const int    userId      = 1;

            using (TwitchIntegration twitchIntegration = new TwitchIntegration(new FakeBrothershipUnitOfWork(), new TwitchClientFake()))
            {
                await twitchIntegration.AuthorizeTwitch(userId, InValidCode);
            }
        }
Ejemplo n.º 2
0
        public async Task IsUserLive_LiveUser_ReturnsTrue()
        {
            const int userId = 1;

            var twitchClient = new TwitchClientFake
            {
                IsStreamLiveReturnValue = true
            };

            using (TwitchIntegration twitchIntegration = new TwitchIntegration(new FakeBrothershipUnitOfWork(), twitchClient))
            {
                bool isUserLive = await twitchIntegration.IsUserLive(userId);

                Assert.IsTrue(isUserLive);
            }
        }
        public async Task IsUserLive_NotLiveUser_ReturnsFalse()
        {
            const int userId = 1;

            var twitchClient = new TwitchClientFake
            {
                IsStreamLiveReturnValue = false
            };

            using (TwitchIntegration twitchIntegration = new TwitchIntegration(new BrothershipUnitOfWork(DataContextCreator.CreateTestContext()),
                                                                               twitchClient))
            {
                bool isUserLive = await twitchIntegration.IsUserLive(userId);

                Assert.IsFalse(isUserLive);
            }
        }
        public async Task GetAuthorization_InvalidCodeIsNotInserted_IntegrationNotInDB()
        {
            using (var unitOfWork = new BrothershipUnitOfWork(DataContextCreator.CreateTestContext()))
            {
                const string InValidCode    = "ThisIsNotACode";
                const int    expectedUserId = 2;

                using (TwitchIntegration twitchIntegration = new TwitchIntegration(unitOfWork, new TwitchClientFake()))
                {
                    await twitchIntegration.AuthorizeTwitch(expectedUserId, InValidCode);

                    var userIntegration = unitOfWork.UserIntegrations.GetById(expectedUserId, (int)IntegrationType.IntegrationTypes.Twitch);

                    Assert.IsNull(userIntegration);
                }
            }
        }
Ejemplo n.º 5
0
        protected override void Initialize()
        {
            base.Initialize();

            integrations.Add(new DiscordIntegration());
            integrations.Add(new SteamIntegration());
            integrations.Add(twitchIntegration = new TwitchIntegration());

            foreach (var i in integrations)
            {
                i.Init();
            }

            AssetsLoaded += () => {
                foreach (var i in integrations)
                {
                    i.PostInit();
                }
            };
        }
Ejemplo n.º 6
0
        public async Task GetAuthorization_SuccessfullAthorization_IntegrationIsInserted()
        {
            using (var unitOfWork = new FakeBrothershipUnitOfWork())
            {
                const string validCode        = "ThisIsACode";
                const int    expectedUserId   = 2;
                const string expectedToken    = "ThisIsAToken";
                const string expectedUserName = "******";

                using (TwitchIntegration twitchIntegration = new TwitchIntegration(unitOfWork, new TwitchClientFake()))
                {
                    await twitchIntegration.AuthorizeTwitch(expectedUserId, validCode);

                    var userIntegration = unitOfWork.UserIntegrations.GetById(expectedUserId, (int)IntegrationType.IntegrationTypes.Twitch);

                    Assert.AreEqual((int)IntegrationType.IntegrationTypes.Twitch, userIntegration.IntegrationTypeID);
                    Assert.AreEqual(expectedUserId, userIntegration.UserID);
                    Assert.AreEqual(expectedToken, userIntegration.Token);
                    Assert.AreEqual(expectedUserName, userIntegration.UserName);
                }
            }
        }
        public async Task DeAuthorize_IsSucessfull_NoIntegrationInDB()
        {
            using (var unitOfWork = new BrothershipUnitOfWork(DataContextCreator.CreateTestContext()))
            {
                const int expectedUserId = 2;
                unitOfWork.UserIntegrations.Add(new UserIntegration
                {
                    IntegrationTypeID = (int)IntegrationType.IntegrationTypes.Twitch,
                    Token             = "token",
                    UserName          = "******",
                    UserID            = expectedUserId,
                });
                unitOfWork.Commit();

                using (TwitchIntegration twitchIntegration = new TwitchIntegration(unitOfWork, new TwitchClientFake()))
                {
                    await twitchIntegration.DeAuthorizeTwitch(expectedUserId);

                    var userIntegration = unitOfWork.UserIntegrations.GetById(expectedUserId, (int)IntegrationType.IntegrationTypes.Twitch);

                    Assert.IsNull(userIntegration);
                }
            }
        }