示例#1
0
        public async Task LoginCodeTest(string appKey, string userName, string password, string device, bool exception, Type exceptionType = null)
        {
            var userRep      = UserRepositoryMock.CreateRepository();
            var tokenRep     = TokenRepositoryMock.CreateRepository();
            var tokenCreator = TokenCreatorMock.Create();

            try
            {
                await Login.Execute(tokenRep, userRep, tokenCreator, appKey, userName, password, device);

                Assert.IsFalse(exception);
            }
            catch (Exception ex)
            {
                Assert.IsTrue((exception) && (exceptionType.FullName == ex.GetType().FullName));
            }
        }
示例#2
0
        public async Task LoginFlowTest(string appKey = "", string userName = "", string password = "", string device = "", bool callGetByKeyToAppCount = false, bool callCreateToken = false, bool callTokenCreator = false)
        {
            var userRep      = UserRepositoryMock.CreateRepository();
            var tokenRep     = TokenRepositoryMock.CreateRepository();
            var tokenCreator = TokenCreatorMock.Create();

            try
            {
                await Login.Execute(tokenRep, userRep, tokenCreator, appKey, userName, password, device);

                Assert.AreEqual(userRep.GetByKeyToAppCount, callGetByKeyToAppCount ? 1 : 0);
                Assert.AreEqual(tokenRep.CreateCount, callCreateToken ? 1 : 0);
                Assert.AreEqual(tokenCreator.CreateCount, callTokenCreator ? 1 : 0);
            }
            catch
            {
                Assert.AreEqual(userRep.GetByKeyToAppCount, callGetByKeyToAppCount ? 1 : 0);
                Assert.AreEqual(tokenRep.CreateCount, callCreateToken ? 1 : 0);
                Assert.AreEqual(tokenCreator.CreateCount, callTokenCreator ? 1 : 0);
            }
        }
示例#3
0
        public async Task LoginInvalidParametersTest(bool isTokenRepNull, bool isUserRepNull, bool isTokenCreatorNull, string key = "", string userName = "", string password = "", string device = "")
        {
            var tokenRep     = isTokenRepNull ? null : TokenRepositoryMock.CreateRepository();
            var userRep      = isUserRepNull ? null : UserRepositoryMock.CreateRepository();
            var tokenCreator = isTokenCreatorNull ? null : TokenCreatorMock.Create();

            try
            {
                await Login.Execute(tokenRep, userRep, tokenCreator, key, userName, password, device);

                Assert.Fail();
            }
            catch (Exception ex)
            {
                if (isTokenRepNull || isUserRepNull || isTokenCreatorNull)
                {
                    Assert.AreEqual(ex.GetType(), typeof(ArgumentNullException));
                }
                else
                {
                    Assert.AreEqual(ex.GetType(), typeof(ArgumentException));
                }
            }
        }