Exemplo n.º 1
0
        public void Constructor_CreatesController()
        {
            var boardRepo  = Mock.Of <IBoardRepository>();
            var controller = new BoardsController(boardRepo);

            Assert.NotNull(controller);
        }
        public void IndexViewResultNotNull()
        {
            BoardsController controller = new BoardsController();

            ViewResult result = controller.Index() as ViewResult;

            Assert.IsNotNull(result);
        }
        public void IndexViewEqualIndexCshtml()
        {
            BoardsController controller = new BoardsController();

            ViewResult result = controller.Index() as ViewResult;

            Assert.AreEqual("Index", result.ViewName);
        }
        public void IndexStringInViewbag()
        {
            BoardsController controller = new BoardsController();

            ViewResult result = controller.Create() as ViewResult;

            Assert.AreEqual("Hello world!", result.ViewBag.Message);
        }
Exemplo n.º 5
0
        public void GetAll_DoesLookupThroughRepository()
        {
            var boardRepo  = new Mock <IBoardRepository>();
            var controller = new BoardsController(boardRepo.Object);

            controller.GetAll();

            boardRepo.Verify(x => x.GetAll(), Times.Once);
        }
Exemplo n.º 6
0
        public void Find_ZeroId_ThrowsOutOfRangeException()
        {
            var boardRepo  = Mock.Of <IBoardRepository>();
            var controller = new BoardsController(boardRepo);

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                controller.Find(0);
            });
        }
Exemplo n.º 7
0
        public void Add_ValidBoardRecord()
        {
            var   boardRepo  = new Mock <IBoardRepository>();
            var   controller = new BoardsController(boardRepo.Object);
            Board board      = new Board(4, DateTime.Now, "Board #4");

            controller.Add(board);

            boardRepo.Verify(x => x.Add(board), Times.Once);
        }
Exemplo n.º 8
0
        public void Delete_InvalidId_ThrowArgumentException()
        {
            var boardRepo  = Mock.Of <IBoardRepository>();
            var controller = new BoardsController(boardRepo);

            Assert.Throws <ArgumentException>(() =>
            {
                controller.Delete(6);
            });
        }
        public void Delete_NoExist()
        {
            var boardRepo = new Mock <IBoardRepository>();

            boardRepo.Setup(x => x.Delete(It.IsAny <Board>())).Returns(true);
            var controller = new BoardsController(boardRepo.Object);

            Assert.Throws <ArgumentException>(() =>
            {
                controller.Delete(0);
            });
        }
Exemplo n.º 10
0
        public void Find_ValidId_DoesLookupThroughRepository()
        {
            var boardRepo = new Mock <IBoardRepository>();

            boardRepo.Setup(x => x.Find(It.IsAny <int>())).Returns(new Board());

            var controller = new BoardsController(boardRepo.Object);

            controller.Find(1);

            boardRepo.Verify(x => x.Find(1), Times.Once);
        }
Exemplo n.º 11
0
        public void Add_InvalidPostIt_MissingText()
        {
            var boardRepo = new Mock <IBoardRepository>();

            boardRepo.Setup(x => x.Find(It.IsAny <int>())).Returns(new Board());

            var controller = new BoardsController(boardRepo.Object);

            Assert.Throws <ArgumentException>(() =>
            {
                controller.AddPostIt(1, new PostIt());
            });
        }
Exemplo n.º 12
0
        public void Delete_ValidId_VerifyExpectedMethodsInvokecOnlyOnce()
        {
            var boardRepo = new Mock <IBoardRepository>();

            boardRepo.Setup(x => x.Find(It.IsAny <int>())).Returns(new Board());
            boardRepo.Setup(x => x.Delete(It.IsAny <int>())).Returns(true);

            var controller = new BoardsController(boardRepo.Object);

            controller.Delete(3);

            boardRepo.Verify(x => x.Find(3), Times.Once);
            boardRepo.Verify(x => x.Delete(3), Times.Once);
        }
Exemplo n.º 13
0
        public void Post_ZeroId_ThrowsOutOfRangeException()
        {
            var boardRepo  = Mock.Of <IBoardRepository>();
            var controller = new BoardsController(boardRepo);
            var board      = new Board()
            {
                Id = 0, Name = "Name #0"
            };

            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                controller.Post(board);
            });
        }
        public void Add_Board()
        {
            var boardRepo = new Mock <IBoardRepository>();

            boardRepo.Setup(x => x.Add(It.IsAny <Board>())).Returns(true);
            var controller = new BoardsController(boardRepo.Object);
            var board      = new Board();

            board.Id   = 4;
            board.Name = "UnitTest";
            controller.Add(board);

            boardRepo.Verify(x => x.Add(board), Times.Once);
        }
Exemplo n.º 15
0
        public void Post_EmptyName_ThrowsArgumentNullException()
        {
            var boardRepo  = Mock.Of <IBoardRepository>();
            var controller = new BoardsController(boardRepo);
            var board      = new Board()
            {
                Id = 1, Name = ""
            };

            Assert.Throws <ArgumentNullException>(() =>
            {
                controller.Post(board);
            });
        }
Exemplo n.º 16
0
        public void Test()
        {
            FormCollection collection = new FormCollection();

            IUser user = Main.Registation(Email0);

            // доски
            BoardsController  boardsController = Base.GetController <BoardsController>();
            PartialViewResult result           = boardsController.List(null);
            IBoard            board            = (result.Model as List <IBoard>).First();

            // статусы
            TasksStatusesController statusesController = Base.GetController <TasksStatusesController>();

            result = statusesController.List(board.Id);
            List <ITasksStatus> statuses = result.Model as List <ITasksStatus>;

            // проекты
            ProjectsController projectsController = Base.GetController <ProjectsController>();

            result = projectsController.List(board.Id);
            List <IProject> projects = result.Model as List <IProject>;

            result = boardsController.EditColorList(board.Id);
            List <IBoardsColor> colors = result.Model as List <IBoardsColor>;

            KanbanController kanbanController = Base.GetController <KanbanController>();

            collection["task-id"]          = null;
            collection["task-statusid"]    = statuses.First().Id.ToString();
            collection["task-userid"]      = user.Id.ToString();
            collection["task-name"]        = "Тестовая задача";
            collection["task-description"] = "Описание тестовой задачи";

            collection["task-projectsid"] = projects.First().Id.ToString();
            collection["task-colorid"]    = colors.First().Id.ToString();

            for (int i = 0; i < 100; i++)
            {
                kanbanController.TaskPopup(board.Id, null, collection);
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();
            statusesController.Archive(board.Id, statuses.First().Id);
            sw.Stop();
            Trace.WriteLine("Time: " + sw.ElapsedMilliseconds.ToString());
        }
Exemplo n.º 17
0
        public void Get_PostIts_BoardNotFound()
        {
            //var board = new Board();

            var boardRepo = new Mock <IBoardRepository>();
            //boardRepo.Setup(x => x.Find(It.IsAny<int>())).Returns(new Board()
            //{
            //    PostIts = new List<PostIt>() { new PostIt(), new PostIt() }
            //});

            var controller = new BoardsController(boardRepo.Object);
            var results    = controller.GetPins(1);

            Assert.AreEqual(results.Count, 0);
        }
Exemplo n.º 18
0
        public void Post_DuplicateId_ThrowsException()
        {
            var boardRepo = new Mock <IBoardRepository>();

            boardRepo.Setup(x => x.Add(It.IsAny <Board>())).Returns(false);

            var controller = new BoardsController(boardRepo.Object);
            var board      = new Board()
            {
                Id = 3, Name = "Name #3"
            };

            Assert.Throws <Exception>(() =>
            {
                controller.Post(board);
            });
        }
Exemplo n.º 19
0
        public void Post_ValidId_DoesLookupThroughRepository()
        {
            var boardRepo = new Mock <IBoardRepository>();

            //boardRepo.Setup(x => x.Find(It.IsAny<int>())).Returns(new Board());
            boardRepo.Setup(x => x.Add(It.IsAny <Board>())).Returns(true);

            var board = new Board()
            {
                Id = 3, Name = "Name #3"
            };

            var controller = new BoardsController(boardRepo.Object);

            controller.Post(board);

            boardRepo.Verify(x => x.Add(board), Times.Once);
        }
Exemplo n.º 20
0
        public async void Test1()
        {
            //var configuration = new ConfigurationBuilder()
            //    .SetBasePath(Directory.GetCurrentDirectory() + "\\..\\..\\..\\..")
            //    .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            //    .Build();

            var options = new DbContextOptionsBuilder <JunSpaContext>()
                          .UseSqlServer("Server=tcp:junspadbserver.database.windows.net,1433;Initial Catalog=JunSpaDb;Persist Security Info=False;User ID=jun;Password=Qwer1234;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;")
                          .Options;

            using (var context = new JunSpaContext(options))
            {
                var vc          = new BoardsController(context);
                var okObjResult = (OkObjectResult)await vc.List();

                var boards = (List <Board>)okObjResult.Value;
                Assert.Equal(boards.Count, 3);
            }
        }
Exemplo n.º 21
0
        public void CanGetBoards()
        {
            // Arrange
            var controller = new BoardsController(new MemoryStorage(), null, null, null);

            // Act
            var response = controller.GetAsync().Result;

            // Assert
            var versionResult = (OkObjectResult)response;
            var boards        = (IEnumerable <Board>)versionResult.Value;

            Assert.Equal(1, boards.Count());
            Assert.Equal(3, boards.First().Bots.Count());
            Assert.Equal(8, boards.First().Diamonds.Count());

            /**
             * Induce game object generation
             */
        }
Exemplo n.º 22
0
        public void BoardTest()
        {
            ViewResult            result;
            RedirectToRouteResult redirectToRouteResult;
            BoardsController      boardsController = Base.GetController <BoardsController>();

            Main.Registation(Email0, out result, out redirectToRouteResult, null);
            boardsController.Create();

            FormCollection collection = new FormCollection();

            collection["name"] = "test";
            RedirectToRouteResult routeResult = boardsController.Create(collection) as RedirectToRouteResult;
            int boardId = (int)routeResult.RouteValues["id"];

            boardsController = Base.GetController <BoardsController>();
            boardsController.Delete(boardId);
            var board = boardsController.Utility.Boards.Get(boardId);

            Assert.IsNull(board);
        }
Exemplo n.º 23
0
        public void Add_ValidPostIt()
        {
            var boardRepo = new Mock <IBoardRepository>();

            var board = new Board()
            {
                Id = 1, Name = "Test"
            };

            boardRepo.Setup(x => x.Find(It.IsAny <int>())).Returns(board);
            boardRepo.Setup(x => x.FindPostIt(It.IsAny <Board>(), It.Is <int>(pid => pid == 1))).Returns(new PostIt());

            var controller = new BoardsController(boardRepo.Object);

            var p = new PostIt {
                Text = "Sample"
            };

            controller.AddPostIt(1, p);

            boardRepo.Verify(x => x.FindPostIt(board, 2), Times.Once);
        }
Exemplo n.º 24
0
        public void Delete_PostIt_DoesLookupThroughRepository()
        {
            var boardRepo = new Mock <IBoardRepository>();

            var board = new Board()
            {
                Id = 1, Name = "Sample"
            };

            boardRepo.Setup(x => x.Find(It.IsAny <int>())).Returns(new Board());
            boardRepo.Setup(x => x.FindPostIt(It.IsAny <Board>(), It.Is <int>(i => i == 1))).Returns(
                new PostIt()
            {
                Id = 1, Text = "Sample"
            }
                );

            var controller = new BoardsController(boardRepo.Object);

            controller.DeletePostIt(1, 1);


            boardRepo.Verify(x => x.FindPostIt(board, 1), Times.Never);
        }
Exemplo n.º 25
0
        public void OrganizationTest()
        {
            FormCollection        collection = new FormCollection();
            ViewResult            result;
            RedirectToRouteResult redirectToRouteResult;

            OrganizationController organizationController = Base.GetController <OrganizationController>();
            PartialViewResult      partialViewResult      = organizationController.Edit(null);

            List <ITariff> tariffs = partialViewResult.ViewData.Get <List <ITariff> >("tariffs");

            Assert.IsNotNull(tariffs);
            ITariff freeTariff = tariffs.Single(x => x.IsFree());

            Assert.IsNotNull(freeTariff);
            Main.Registation(Email0);

            // создали тестовую организацию
            collection.Clear();
            organizationController = Base.GetController <OrganizationController>();
            collection.Add("Name", "test");
            collection.Add("TariffId", freeTariff.Id.ToString());
            partialViewResult = organizationController.Edit(null, collection);
            IOrganization organization = ((List <EmployeeSettings>)partialViewResult.Model).Single().Organization;

            Assert.IsNotNull(organization);
            int organizationId = organization.Id;

            #region Приглашения

            InviteController inviteController = Base.GetController <InviteController>();

            // через мыло незареганного
            collection.Clear();
            collection.Add("Email", Email3);
            inviteController.NewInvite(organizationId, collection);
            List <IUsersInvite> invites = inviteController.Utility.Invites.GetInvites(organizationId);
            IUsersInvite        invite  = invites.FirstOrDefault(x => x.EMail.ToUpper() == Email3.ToUpper());
            Assert.IsNotNull(invite);
            Main.Registation(Email3, out result, out redirectToRouteResult, invite.InviteCode);
            ViewResultBase   resultBase = organizationController.EmployeeList(organizationId);
            EmployeeSettings emeil3User = (resultBase.Model as List <EmployeeSettings>).FirstOrDefault(x => x.User.EMail.ToUpper() == Email3.ToUpper());
            Assert.IsNotNull(emeil3User);
            collection.Clear();
            collection.Add("delete", "true");
            organizationController.EmployeeEdit(organizationId, emeil3User.User.Id, collection);

            // через мыло зареганного
            inviteController.Dispose();
            inviteController = Base.GetController <InviteController>();
            collection.Clear();
            collection.Add("Email", Email3);
            inviteController.NewInvite(organizationId, collection);
            invites = organizationController.Utility.Invites.GetInvites(organizationId);
            invite  = invites.FirstOrDefault(x => x.EMail.ToUpper() == Email3.ToUpper());
            Assert.IsNotNull(invite);
            Base.GetController <AdminController>().ClearCache();
            resultBase = organizationController.EmployeeList(organizationId);
            emeil3User = (resultBase.Model as List <EmployeeSettings>).FirstOrDefault(x => x.User.EMail.ToUpper() == Email3.ToUpper());
            Assert.IsNotNull(emeil3User);
            var userController = Base.GetController <UserController>();
            userController.Login(null, Email3, Email3, true, null);
            inviteController.AcceptInvite(organizationId);
            emeil3User = (resultBase.Model as List <EmployeeSettings>).FirstOrDefault(x => x.User.EMail.ToUpper() == Email3.ToUpper());
            Assert.IsTrue(emeil3User.Settings.UserRole == (int)EmployeeRole.Employee);

            // через ссылку незареганного пользователя
            userController.Dispose();
            userController = Base.GetController <UserController>();
            userController.SignOut();
            redirectToRouteResult = (RedirectToRouteResult)userController.Invite(organization.InviteCode);
            Assert.IsTrue(redirectToRouteResult.RouteValues["action"].ToString() == "Register");
            collection.Clear();
            Main.Registation(Email4, out result, out redirectToRouteResult, organization.InviteCode);
            resultBase = inviteController.List();
            var           organizations = (IEnumerable <IOrganization>)resultBase.Model;
            IOrganization first         = organizations.FirstOrDefault();
            Assert.IsTrue(first != null && first.Id == organizationId);
            inviteController.AcceptInvite(first.Id);
            resultBase = organizationController.EmployeeList(organizationId);
            EmployeeSettings emeil4User = ((List <EmployeeSettings>)resultBase.Model).FirstOrDefault(x => x.User.EMail.ToUpper() == Email4.ToUpper());
            Assert.IsNotNull(emeil4User);
            collection.Clear();
            collection.Add("delete", "true");
            organizationController.EmployeeEdit(organizationId, emeil4User.User.Id, collection);

            // через ссылку зареганного пользователя
            userController.Dispose();
            userController        = Base.GetController <UserController>();
            redirectToRouteResult = (RedirectToRouteResult)userController.Invite(organization.InviteCode);
            Assert.IsTrue(redirectToRouteResult.RouteValues["action"].ToString() == "Index");
            collection.Clear();
            inviteController.Dispose();
            inviteController = Base.GetController <InviteController>();
            resultBase       = inviteController.List();
            organizations    = (IEnumerable <IOrganization>)resultBase.Model;
            first            = organizations.FirstOrDefault();
            Assert.IsTrue(first != null && first.Id == organizationId);
            inviteController.AcceptInvite(first.Id);
            resultBase = organizationController.EmployeeList(organizationId);
            emeil4User = (resultBase.Model as List <EmployeeSettings>).FirstOrDefault(x => x.User.EMail.ToUpper() == Email4.ToUpper());
            Assert.IsNotNull(emeil4User);

            #endregion

            #region Удаление

            userController.Dispose();
            userController = Base.GetController <UserController>();
            userController.Login(null, Email3, Email3, true, null);

            BoardsController boardsController = Base.GetController <BoardsController>();
            collection.Clear();
            collection.Add("name", "t1");
            collection.Add("OrganizationId", organizationId.ToString());
            boardsController.Create(collection);

            collection.Clear();
            collection.Add("name", "t2");
            collection.Add("OrganizationId", organizationId.ToString());
            boardsController.Create(collection);

            collection.Clear();
            organizationController = Base.GetController <OrganizationController>();
            organizationController.Delete(organizationId);

            boardsController  = Base.GetController <BoardsController>();
            partialViewResult = boardsController.List(null);
            Assert.IsFalse((partialViewResult.Model as List <IBoard>).Single().OrganizationId.HasValue);            // остается только личная доска

            #endregion
        }
Exemplo n.º 26
0
        public void CanGenerateObjects()
        {
            var testGenerators = new List <IGameObjectGenerator>()
            {
                new TeleporterGenerator() as IGameObjectGenerator
            };
            var storage   = new MemoryStorage();
            var testBoard = new Board
            {
                Id          = "2",
                Height      = 10,
                Width       = 10,
                GameObjects = new List <BaseGameObject> {
                },
                Bots        = new List <BoardBot> {
                    new BoardBot {
                        Name     = "Jane Jet",
                        Base     = new Position(6, 2),
                        Position = new Position(8, 0),
                        Score    = 5,
                        Diamonds = 0,
                    },
                    new BoardBot {
                        Name     = "indrif",
                        Base     = new Position(5, 8),
                        Position = new Position(0, 0),
                        Score    = 2,
                        Diamonds = 2,
                    },
                },
                Diamonds = new List <DiamondPosition>
                {
                }
            };

            storage.UpdateBoardAsync(testBoard).Wait();
            var generatorService = new GameObjectGeneratorService();

            Assert.NotEmpty(generatorService.getCurrentObjectGenerators());
            var controller = new BoardsController(storage,
                                                  null,
                                                  new DiamondGeneratorService()
                                                  , generatorService);
            //GameObject related tests here. TODO: Break out into separate test-cases.
            var boardResult = controller.GetBoardAsync("2").Result as OkObjectResult;
            var board       = boardResult?.Value as Board;

            Assert.NotEmpty(board.GameObjects);
            Assert.Equal(2,
                         board.GameObjects.Where(go =>
                                                 go.Name.Equals("Teleporter")).Count()
                         );
            Assert.Equal(1,
                         board.GameObjects.Where(go =>
                                                 go.Name.Equals("DiamondButton")).Count()
                         );
            Assert.False(
                board.GameObjects.Where(go =>
                                        go.Name.Equals("DiamondButton")).First().IsBlocking
                );
            List <DiamondPosition> oldDiamonds = new List <DiamondPosition>(board.Diamonds);

            board.GameObjects.Where(go =>
                                    go.Name.Equals("DiamondButton")).First().PerformInteraction(board, board.Bots.First(), Direction.North, new DiamondGeneratorService());
            Assert.False(oldDiamonds.SequenceEqual(board.Diamonds));
            Console.WriteLine("Regeneration in the nation!");
        }
Exemplo n.º 27
0
        public void MainTest()
        {
            ViewResult            result;
            RedirectToRouteResult redirectToRouteResult;
            FormCollection        collection = new FormCollection();

            #region  егистрация/Атовризация

            IUser user0 = Registation(Email0);
            IUser user2 = Registation(Email2, out result, out redirectToRouteResult, null);
            IUser user1 = Registation(Email1, out result, out redirectToRouteResult, null);

            #endregion

            #region Создание доски
            BoardsController boardsController = Base.GetController <BoardsController>();
            collection.Clear();
            collection.Add("name", "test");
            collection.Add("description", "description");
            redirectToRouteResult = (RedirectToRouteResult)boardsController.Create(collection);
            int boardId = redirectToRouteResult.RouteValues["Id"].To <int>();
            var board   = boardsController.Utility.Boards.Get(boardId);
            Assert.IsNotNull(board);
            #endregion

            #region Проверяем статусы

            TasksStatusesController    tasksStatusesController = Base.GetController <TasksStatusesController>();
            PartialViewResult          resultBase = tasksStatusesController.List(boardId);
            IEnumerable <ITasksStatus> statuses   = (IEnumerable <ITasksStatus>)resultBase.Model;
            Assert.AreEqual(statuses.First().Name, "Беклог");

            tasksStatusesController = Base.GetController <TasksStatusesController>();
            resultBase = tasksStatusesController.Edit(boardId,
                                                      new TimezStatus
            {
                Name    = "test",
                BoardId = boardId
            });

            statuses = (IEnumerable <ITasksStatus>)resultBase.Model;
            Assert.AreEqual(statuses.ElementAt(statuses.Count() - 1).Name, "test");

            #endregion

            #region проверяем задачи

            var user            = boardsController.Utility.Users.Get(Email1);
            var boardStatusList = boardsController.Utility.Statuses.GetByBoard(board.Id);

            // получаем доску
            var boardData = (ViewResultBase)boardsController.Edit(boardId);
            Assert.IsInstanceOfType(boardData.Model, typeof(IBoard));
            ProjectsController     projectController = Base.GetController <ProjectsController>();
            IEnumerable <IProject> projs             = (IEnumerable <IProject>)projectController.List(boardId).Model;
            Assert.IsNotNull(projs);

            // получаем цвета доски
            var boardColor = (ViewResultBase)boardsController.EditColorList(boardId);
            Assert.IsInstanceOfType(boardColor.ViewData.Model, typeof(IEnumerable <IBoardsColor>));
            IEnumerable <IBoardsColor> boardColors = boardColor.ViewData.Model as IEnumerable <IBoardsColor>;

            // Создание задачи
            collection.Clear();
            collection["task-id"]          = null;
            collection["task-statusid"]    = boardStatusList[0].Id.ToString();
            collection["task-userid"]      = user.Id.ToString();
            collection["task-name"]        = "Тестовая задача";
            collection["task-description"] = "Описание тестовой задачи";

            collection["task-projectsid"] = projs.First().Id.ToString();
            collection["task-colorid"]    = boardColors.First().Id.ToString(CultureInfo.InvariantCulture);

            // проверяем создание
            KanbanController kanbanController = Base.GetController <KanbanController>();
            ViewResultBase   taskData         = (ViewResultBase)kanbanController.TaskPopup(boardId, null, collection);
            ITask            task             = CheckTask(taskData);
            Assert.IsTrue(task.CreatorUserId == kanbanController.Utility.Authentication.UserId);

            // архивирование
            collection["task-name"] = "Тестовая задача2";
            taskData = (ViewResultBase)kanbanController.TaskPopup(boardId, null, collection);
            ITask task2 = CheckTask(taskData);
            kanbanController.ToArchive(boardId, task2.Id);
            TasksController tasksController = Base.GetController <TasksController>();
            taskData = tasksController.Details(boardId, task2.Id, true);
            Assert.IsTrue((taskData.Model as ITask).Id == task2.Id);
            Assert.IsTrue((bool)taskData.ViewData["isArchive"]);

            // обновляем задачу
            collection.Clear();
            collection["task-id"] = task.Id.ToString();
            ITasksStatus planningStatus = boardStatusList.First(x => x.PlanningRequired);
            collection["task-statusid"]    = planningStatus.Id.ToString();
            collection["task-userid"]      = user.Id.ToString();
            collection["task-name"]        = "Тестовая задачаю. Обновление";
            collection["task-description"] = "Описание тестовой задачи. Обновление";
            collection["task-projectsid"]  = projs.First().Id.ToString();
            collection["task-colorid"]     = boardColors.ToList()[1].Id.ToString();
            kanbanController.Dispose();
            kanbanController = Base.GetController <KanbanController>();
            var json = (JsonResult)kanbanController.TaskPopup(boardId, task.Id, collection);
            Assert.IsTrue((json.Data as JsonMessage).Message == new PlanningTimeRequered(planningStatus).Message);


            // проверяем изменение цвета
            kanbanController = Base.GetController <KanbanController>();
            var color = kanbanController.SetColor(task.Id, boardColors.ToList()[0].Id, boardId);
            Assert.AreNotEqual(color, "");

            // проверям установку времени
            kanbanController = Base.GetController <KanbanController>();
            collection.Clear();
            collection["task-forsed-count"] = "true";
            collection["task-forsed-time"]  = "false";
#pragma warning disable 168
            JsonResult planningTime = (JsonResult)kanbanController.SetPlanningTime(boardId, task.Id, 180, task.TaskStatusId, collection);
#pragma warning restore 168

            // проверяем обновление статуса
            kanbanController = Base.GetController <KanbanController>();
            collection.Clear();
            collection["task-forsed-count"] = "true";
            collection["task-forsed-time"]  = "false";
            kanbanController.UpdateStatus(boardId, task.Id, boardStatusList[0].Id, collection);

            // проверяем исполнителя
            kanbanController = Base.GetController <KanbanController>();
            user             = kanbanController.Utility.Users.Get(Email2);
            kanbanController.SetExecutor(task.BoardId, task.Id, user.Id);

            // проверяем проект
            // сначала создадим проект
            projectController.Dispose();
            projectController = Base.GetController <ProjectsController>();
            collection.Clear();
            string projectName = "тестовый проект " + DateTime.Now.Ticks.ToString();
            collection["Name"] = projectName;
            var projectData = (ViewResultBase)projectController.Edit(boardId, null, collection);
            // проверяем создание проекта
            Assert.IsInstanceOfType(projectData.ViewData.Model, typeof(IEnumerable <IProject>));
            var projects = projectData.ViewData.Model as IEnumerable <IProject>;
            var project  = projects.SingleOrDefault(p => p.Name == projectName);
            Assert.IsNotNull(project);

            // изменяем проект
            kanbanController = Base.GetController <KanbanController>();
            kanbanController.SetProject(task.BoardId, task.Id, project.Id);

            // переназначение
            ParticipantController participantController = Base.GetController <ParticipantController>();
            collection.Clear();
            collection["participant-id"] = user1.Id.ToString();
            participantController.Tasks(boardId, user0.Id, collection);
            collection["participant-id"] = user2.Id.ToString();
            participantController.Tasks(boardId, user0.Id, collection);
            // удаление
            kanbanController = Base.GetController <KanbanController>();
            kanbanController.DeleteTask(task2.Id, task2.BoardId);
            kanbanController.DeleteTask(task.Id, task.BoardId);

            // проверяем удаление
            kanbanController = Base.GetController <KanbanController>();
            kanbanController.Index(boardId);
            kanbanController = Base.GetController <KanbanController>();
            collection.Clear();
            PartialViewResult kanban = kanbanController.Kanban(boardId, collection);
            Assert.IsInstanceOfType(kanban.ViewData["Tasks"], typeof(IEnumerable <ITask>));
            IEnumerable <ITask> boardTasks = kanban.ViewData["Tasks"] as IEnumerable <ITask>;
            ITask deletedTask = boardTasks.FirstOrDefault(t => t.Id == task.Id);
            Assert.IsNull(deletedTask);

            // Проверка попадания в журнал ошибок и предупреждений
            var logController = Base.GetController <LogController>();
            var logData       = (ViewResultBase)logController.Items(boardId, null);

            Assert.IsInstanceOfType(logData.ViewData.Model, typeof(IEnumerable <IEventHistory>));
            var logs        = logData.ViewData.Model as IEnumerable <IEventHistory>;
            var boardEvents = logs.Where(p => p.BoardId == boardId);
            Assert.AreNotEqual(boardEvents.Count(), 0);

            Assert.AreNotEqual(boardEvents.Count(e => (e.EventType & EventType.CreateTask) == EventType.CreateTask), 0);
            Assert.AreNotEqual(boardEvents.Count(e => (e.EventType & EventType.Delete) == EventType.Delete), 0);
            Assert.AreNotEqual(boardEvents.Count(e => (e.EventType & EventType.Update) == EventType.Update), 0);
            Assert.AreNotEqual(boardEvents.Count(e => (e.EventType & EventType.TaskColorChanged) == EventType.TaskColorChanged), 0);
            Assert.AreNotEqual(boardEvents.Count(e => (e.EventType & EventType.TaskAssigned) == EventType.TaskAssigned), 0);
            Assert.AreNotEqual(boardEvents.Count(e => (e.EventType & EventType.ProjectChanged) == EventType.ProjectChanged), 0);
            Assert.AreNotEqual(boardEvents.Count(e => (e.EventType & EventType.PlaningTimeChanged) == EventType.PlaningTimeChanged), 0);


            #endregion

            #region Удаление досок
            boardsController.Dispose();
            boardsController = Base.GetController <BoardsController>();
            PartialViewResult partialResult = boardsController.List(null);
            Assert.IsInstanceOfType(partialResult.Model, typeof(List <IBoard>));
            foreach (IBoard item in partialResult.Model as List <IBoard> )
            {
                boardsController = Base.GetController <BoardsController>();
                boardsController.Delete(item.Id);
                try
                {
                    board = boardsController.Utility.Boards.Get(item.Id);
                    Assert.IsNull(board);
                }
                catch (Exception ex)
                {
                    Assert.IsInstanceOfType(ex, typeof(AccessDeniedException));
                }
            }
            #endregion

            boardsController.Utility.Users.Delete(Email1);
            Assert.IsNull(boardsController.Utility.Users.Get(Email1));
        }
Exemplo n.º 28
0
 public Tests()
 {
     controller = new BoardsController();
 }