internal async Task UpdatePasswordAsync_ValidAsync()
        {
            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.Password = "******";

                    var updated =
                        (
                            await api.SaveAccountAsync(identity.Data.Account) as JsonResult
                        ).Value as ExecutionResult <Account>;
                    GenericChecks.CheckSucceed(updated);


                    var responseGet =
                        (
                            await api.GetAccountAsync(identity.Data.Account.Id.Value) as JsonResult
                        ).Value as ExecutionResult <Account>;
                    GenericChecks.CheckSucceed(responseGet);

                    Compare(responseGet.Data, identity.Data.Account, 1);

                    var newIdentity =
                        (
                            await auth.LoginAsync
                            (
                                new Credentials {
                        Login = "******", Password = identity.Data.Account.Password
                    }
                            ) as JsonResult
                        ).Value as ExecutionResult <Identity>;
                    GenericChecks.CheckSucceed(identity);

                    Compare(newIdentity.Data.Account, identity.Data.Account, 1);
                }
                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 async Task GetAccountsAsyncPaging_ValidAsync(string sql, Paging paging, Account[] expected)
        {
            using (var context = Storage.CreateContext())
            {
                try
                {
                    var api = Storage.CreatePrivateController(context);
                    api.ControllerContext = await ControllerContextCreator.CreateValid(context, null);

                    Storage.RunSql(sql);

                    var response =
                        (
                            await api.GetAccountsAsync(paging) as JsonResult
                        ).Value as ExecutionResult <Account[]>;
                    GenericChecks.CheckSucceed(response);

                    foreach (var item in expected)
                    {
                        var actual = response.Data.FirstOrDefault(x => x.Id == item.Id);

                        Compare(actual, item);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }
        internal async Task GetAccountAsync_ValidAsync(string sql, Account expected)
        {
            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(expected.Id.Value) as JsonResult
                        ).Value as ExecutionResult <Account>;
                    GenericChecks.CheckSucceed(getResult);
                    Compare(getResult.Data, expected);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }
Пример #5
0
        internal async Task GetProjectsPreview_ValidAsync(string sql, Paging paging, ProjectSearch projectSearch, ProjectPreview[] expectedProjects)
        {
            using (var context = Storage.CreateContext())
            {
                try
                {
                    Storage.RunSql(sql);

                    var api = Storage.CreatePublicController(context);


                    var response =
                        (
                            await api.GetProjectsPreviewAsync(paging, projectSearch) as JsonResult
                        ).Value as ExecutionResult <ProjectPreview[]>;

                    GenericChecks.CheckSucceed(response);
                    Assert.Equal(expectedProjects.Length, response.Data.Length);

                    foreach (var item in expectedProjects)
                    {
                        var actual = response.Data.SingleOrDefault(x => x.Code == item.Code);
                        Compare(item, actual);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }
        internal async Task AddAccountAsync_ValidAsync(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.CheckSucceed(addResult);
                    Compare(addResult.Data, account);


                    var getResult =
                        (
                            await api.GetAccountAsync(addResult.Data.Id.Value) as JsonResult
                        ).Value as ExecutionResult <Account>;
                    GenericChecks.CheckSucceed(getResult);
                    Compare(getResult.Data, account);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }
        internal async Task GetEverythingCategoryAsync(Category expected)
        {
            using (var context = Storage.CreateContext())
            {
                try
                {
                    var api = Storage.CreatePublicController(context);

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

                    GenericChecks.CheckSucceed(response);
                    Compare(expected, response.Data);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }
        internal async Task GetRolesAsync_ValidAsync(string[] expectedRoles)
        {
            using (var context = Storage.CreateContext())
            {
                try
                {
                    var api = Storage.CreatePrivateController(context);
                    api.ControllerContext = await ControllerContextCreator.CreateValid(context, null);

                    var response =
                        (
                            api.GetRoles() as JsonResult
                        ).Value as ExecutionResult <List <string> >;

                    GenericChecks.CheckSucceed(response);

                    Assert.Equal(expectedRoles.Length, response.Data.Count);

                    foreach (var item in expectedRoles)
                    {
                        var actural = response.Data.First(x => x == item);
                        Assert.Equal(item, actural);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }
        internal async Task GetCategoriesAsync(Category[] expectedCategories)
        {
            using (var context = Storage.CreateContext())
            {
                try
                {
                    var api      = Storage.CreatePublicController(context);
                    var response =
                        (
                            await api.GetCategoriesAsync() as JsonResult
                        ).Value as ExecutionResult <Category[]>;

                    GenericChecks.CheckSucceed(response);

                    foreach (var expected in expectedCategories)
                    {
                        var actual = response.Data.FirstOrDefault(x => x.Id == expected.Id);
                        Compare(expected, actual);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }
Пример #10
0
        public async Task SafeExecuteAsync_Valid(string value)
        {
            var result = await _supervisor.SafeExecuteAsync(() => Task.FromResult(value));

            GenericChecks.CheckSucceed(result);
            Assert.Equal(value, result.Data);
        }
Пример #11
0
        public void SafeExecute_Valid(int value)
        {
            var result = _supervisor.SafeExecute(() => { return(value); });

            GenericChecks.CheckSucceed(result);
            Assert.Equal(value, result.Data);
        }
Пример #12
0
        internal async Task GetProject_ValidAsync(Project expected)
        {
            using (var context = Storage.CreateContext())
            {
                try
                {
                    var api = Storage.CreatePublicController(context);

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

                    GenericChecks.CheckSucceed(response);
                    Compare(expected, response.Data);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }
        internal async Task CountAsync_ValidAsync(string[] sql)
        {
            using (var context = Storage.CreateContext())
            {
                try
                {
                    var api = Storage.CreatePrivateController(context);
                    api.ControllerContext = await ControllerContextCreator.CreateValid(context, null);

                    Storage.RunSql(sql);

                    var response =
                        (
                            await api.CountAccountAsync() as JsonResult
                        ).Value as ExecutionResult <int>;
                    GenericChecks.CheckSucceed(response);

                    Assert.Equal(sql.Length + 1, response.Data);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }
        internal async Task GetInformationAsync()
        {
            using (var context = Storage.CreateContext())
            {
                try
                {
                    var apiAuth  = Storage.CreateGatewayController(context);
                    var identity =
                        (
                            await apiAuth.LoginAsync
                            (
                                new Credentials {
                        Login = "******", Password = "******"
                    }
                            ) as JsonResult
                        ).Value as ExecutionResult <Identity>;

                    GenericChecks.CheckSucceed(identity);

                    var httpContext = new DefaultHttpContext();
                    httpContext.Request.Headers["Authorization"] = identity.Data.Token;
                    var controllerContext = new ControllerContext()
                    {
                        HttpContext = httpContext,
                    };

                    var api = Storage.CreatePrivateController(context);
                    api.ControllerContext = controllerContext;


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

                    GenericChecks.CheckSucceed(response);

                    Assert.Equal(identity.Data.Account.Role, response.Data.Role);
                    Assert.Equal(identity.Data.Account.Login, response.Data.Login);
                    Assert.NotNull(response.Data.ApiVersion);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }
Пример #15
0
        internal void Ping_Test()
        {
            using (var context = Storage.CreateContext())
            {
                var api = Storage.CreatePublicController(context);

                var response =
                    (
                        api.Ping() as JsonResult
                    ).Value as ExecutionResult <string>;

                GenericChecks.CheckSucceed(response);

                Assert.Equal("pong", response.Data);
            }
        }
        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();
                }
            }
        }
        internal async Task UpdateIntroduction_ValidAsync(Introduction update, Introduction expected)
        {
            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.CheckSucceed(updateResponse);
                    Compare(updateResponse.Data, expected);
                    Assert.Equal(expected.PosterUrl, updateResponse.Data.PosterUrl);


                    var apiPublic   = Storage.CreatePublicController(context);
                    var getResponse =
                        (
                            await apiPublic.GetIntroductionAsync() as JsonResult
                        ).Value as ExecutionResult <Introduction>;

                    GenericChecks.CheckSucceed(getResponse);
                    Compare(getResponse.Data, expected);
                    Assert.Equal(expected.PosterUrl, getResponse.Data.PosterUrl);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }
Пример #18
0
        internal async Task LoginAsync_Valid_EmptyAsync(string login, string password)
        {
            using (var context = Storage.CreateContext())
            {
                try
                {
                    var api = Storage.CreateGatewayController(context);

                    var response =
                        (
                            await api.LoginAsync(new Credentials {
                        Login = login, Password = password
                    }) as JsonResult
                        ).Value as ExecutionResult <Identity>;

                    GenericChecks.CheckSucceed(response);

                    Assert.NotNull(response.Data.Account);
                    Assert.NotNull(response.Data.Token);
                    Assert.Equal
                    (
                        Storage.CreateConfiguration().GetSection("Token:LifeTime").Get <int>(),
                        response.Data.TokenLifeTimeMinutes
                    );
                    Compare(DefaultAccount, response.Data.Account);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }
        internal async Task UpdateIntroduction_AddFile_ValidAsync()
        {
            using (var context = Storage.CreateContext())
            {
                try
                {
                    var update = new Introduction
                    {
                        Content           = "The service is on-line. Congratulations.",
                        Title             = "Hello",
                        PosterDescription = "des",
                        PosterUrl         = @"Files/untitled.png",
                        Version           = 0
                    };

                    var stream       = File.OpenRead(update.PosterUrl);
                    var ffcollection = new FormFileCollection
                    {
                        new FormFile(stream, 0, stream.Length, "introduction[posterToUpload]", "untitled.png")
                    };

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


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

                    GenericChecks.CheckSucceed(updateResponse);

                    Assert.NotNull(updateResponse.Data.PosterUrl);

                    var config    = Storage.CreateConfiguration();
                    var pathStart = config["Endpoint"] + config["Location:StaticFilesRequestPath"];

                    Assert.StartsWith(pathStart, updateResponse.Data.PosterUrl);

                    var storagePath = config.GetSection("Location:FileStorage").Get <string>();
                    var fileExists  = File.Exists(Path.Combine(storagePath, Path.GetFileName(updateResponse.Data.PosterUrl)));
                    Assert.True(fileExists);

                    var apiPublic   = Storage.CreatePublicController(context);
                    var getResponse =
                        (
                            await apiPublic.GetIntroductionAsync() as JsonResult
                        ).Value as ExecutionResult <Introduction>;

                    GenericChecks.CheckSucceed(getResponse);
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.FlushData();
                }
            }
        }