Esempio n. 1
0
        internal async Task LoginAsync_InvalidAsync(Credentials credentials)
        {
            using (var context = Storage.CreateContext())
            {
                try
                {
                    var api = Storage.CreateGatewayController(context);

                    var response =
                        (
                            await api.LoginAsync(credentials) as JsonResult
                        ).Value as ExecutionResult <Identity>;

                    GenericChecks.CheckFail(response);

                    Assert.Null(response.Data);
                    Assert.Null(response.Data?.Token);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }
Esempio n. 2
0
        internal async Task GetProject_InValidAsync(string code)
        {
            using (var context = Storage.CreateContext())
            {
                try
                {
                    var api = Storage.CreatePublicController(context);

                    var response =
                        (
                            await api.GetProjectAsync(code) as JsonResult
                        ).Value as ExecutionResult <Project>;

                    GenericChecks.CheckFail(response);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }
Esempio n. 3
0
        internal async Task GetProjectsPreview_InValidAsync(Paging paging, ProjectSearch projectSearch)
        {
            using (var context = Storage.CreateContext())
            {
                try
                {
                    var api = Storage.CreatePublicController(context);


                    var response =
                        (
                            await api.GetProjectsPreviewAsync(paging, projectSearch) as JsonResult
                        ).Value as ExecutionResult <ProjectPreview[]>;
                    GenericChecks.CheckFail(response);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }
        internal async Task GetAccountAsync_InValidAsync(string sql, int id)
        {
            using (var context = Storage.CreateContext())
            {
                try
                {
                    var api = Storage.CreatePrivateController(context);
                    api.ControllerContext = await ControllerContextCreator.CreateValid(context, null);

                    Storage.RunSql(sql);

                    var getResult =
                        (
                            await api.GetAccountAsync(id) as JsonResult
                        ).Value as ExecutionResult <Account>;
                    GenericChecks.CheckFail(getResult);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }
        internal async Task AddAccountAsync_InValidAsync(Account account)
        {
            using (var context = Storage.CreateContext())
            {
                try
                {
                    var api = Storage.CreatePrivateController(context);
                    api.ControllerContext = await ControllerContextCreator.CreateValid(context, null);

                    var addResult =
                        (
                            await api.SaveAccountAsync(account) as JsonResult
                        ).Value as ExecutionResult <Account>;
                    GenericChecks.CheckFail(addResult);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }
        internal async Task DeleteAccountAsync_ValidAsync(string sql, Account account)
        {
            using (var context = Storage.CreateContext())
            {
                try
                {
                    var api = Storage.CreatePrivateController(context);
                    api.ControllerContext = await ControllerContextCreator.CreateValid(context, null);

                    Storage.RunSql(sql);

                    var delResult =
                        (
                            await api.DeleteAccountAsync(account) as JsonResult
                        ).Value as ExecutionResult <bool>;
                    GenericChecks.CheckSucceed(delResult);


                    var responseGet =
                        (
                            await api.GetAccountAsync(account.Id.Value) as JsonResult
                        ).Value as ExecutionResult <Account>;
                    GenericChecks.CheckFail(responseGet);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }
        internal void GetInformation_BadToken(string token)
        {
            using (var context = Storage.CreateContext())
            {
                try
                {
                    var api = Storage.CreatePrivateController(context);
                    api.ControllerContext = ControllerContextCreator.CreateInvalid(token);

                    var response =
                        (
                            api.GetInformationAsync() as JsonResult
                        ).Value as ExecutionResult <Information>;

                    GenericChecks.CheckFail(response);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }
        internal async Task GetCategory_InvalidAsync(int id)
        {
            using (var context = Storage.CreateContext())
            {
                try
                {
                    var api = Storage.CreatePublicController(context);

                    var response =
                        (
                            await api.GetCategoryAsync(id) as JsonResult
                        ).Value as ExecutionResult <Category>;

                    GenericChecks.CheckFail(response);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }
        internal async Task UpdateIntroduction_InvalidAsync(Introduction update)
        {
            using (var context = Storage.CreateContext())
            {
                try
                {
                    var api = Storage.CreatePrivateController(context);
                    api.ControllerContext = await ControllerContextCreator.CreateValid(context, null);

                    var updateResponse =
                        (
                            await api.SaveIntroductionAsync(update) as JsonResult
                        ).Value as ExecutionResult <Introduction>;

                    GenericChecks.CheckFail(updateResponse);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }
Esempio n. 10
0
        public async Task SafeExecuteAsync_Invalid()
        {
            var resultString = await _supervisor.SafeExecuteAsync <string>(() => throw new Exception("One"));

            GenericChecks.CheckFail(resultString);
            Assert.Equal("One", resultString.Error.Message);
            Assert.Null(resultString.Error.Detail);

            var result = await _supervisor.SafeExecuteAsync <int>(() => throw new Exception("Main", new Exception("Inner")));

            GenericChecks.CheckFail(result);

            Assert.Equal("Main", result.Error.Message);
            Assert.Equal("Inner", result.Error.Detail);
        }
Esempio n. 11
0
        public void SafeExecute_Invalid()
        {
            var resultString = _supervisor.SafeExecute <string>(() => throw new Exception("one"));

            GenericChecks.CheckFail(resultString);
            Assert.Equal("one", resultString.Error.Message);
            Assert.Null(resultString.Error.Detail);


            var resultInt = _supervisor.SafeExecute <int>(() => throw new Exception("one", new Exception("two")));

            GenericChecks.CheckFail(resultInt);
            Assert.Equal("one", resultInt.Error.Message);
            Assert.Equal("two", resultInt.Error.Detail);
        }
        internal async Task UpdateAcountAsync_InValidAsync(Account account)
        {
            using (var context = Storage.CreateContext())
            {
                try
                {
                    var auth     = Storage.CreateGatewayController(context);
                    var identity =
                        (
                            await auth.LoginAsync(new Credentials {
                        Login = "******", Password = "******"
                    }) as JsonResult
                        ).Value as ExecutionResult <Identity>;
                    GenericChecks.CheckSucceed(identity);

                    var api = Storage.CreatePrivateController(context);
                    api.ControllerContext = await ControllerContextCreator.CreateValid(context, null);

                    identity.Data.Account.Login = "******";

                    Storage.RunSql("INSERT INTO account (id, login, password, salt, role) VALUES (2, 'login', 'password', 'salt', 'role'); ");


                    var response =
                        (
                            await api.SaveAccountAsync(account) as JsonResult
                        ).Value as ExecutionResult <Account>;
                    GenericChecks.CheckFail(response);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }