public void ProjectController_TestCreateProject()
        {
            // Arrange
            projectController.ControllerContext.HttpContext.Session["UserID"] = 1;
            var projectToAdd = new Project {
                customerId = 2, userId = 1, name = "Elf Liberation", startDate = DateTime.Parse("2017-07-14"), expectedEndDate = DateTime.Parse("2018-08-14"), status = ProjectStatus.InProgress, customer = customerList.Where(c => c.customerId == 2).FirstOrDefault()
            };

            //Check
            var result1   = projectController.Index("") as ViewResult;
            var projects1 = (IEnumerable <Project>)result1.ViewData.Model;

            Assert.AreEqual(1, projects1.ToList().Count);
            Assert.AreEqual(UnitTestsHelper.ListContains(projects1, "Elf Liberation"), false);

            //Act
            projectController.Create(projectToAdd);
            var result = projectController.Index("") as ViewResult;

            //Assert
            var projects = (IEnumerable <Project>)result.ViewData.Model;

            Assert.AreEqual(2, projects.ToList().Count);
            Assert.AreEqual(UnitTestsHelper.ListContains(projects, "Elf Liberation"), true);
        }
Exemple #2
0
        public void Create_GoodWeather()
        {
            HttpContext.Current = MockHelper.FakeHttpContext("projects");

            _context.Users.Add(new UserEntity()
            {
                Name = "Bobby", Email = "*****@*****.**"
            });
            _context.Companies.Add(new CompanyEntity()
            {
                Name = "Some crazy company", Description = "That is the most crazy company"
            });

            var projectRequest = new ProjectRequest()
            {
                Name = "CrazyProject", Description = "The most crazy project you can find out there"
            };
            var res = _controller.Create(projectRequest) as OkNegotiatedContentResult <bool>;

            Assert.NotNull(res);
            Assert.IsTrue(res.Content);
            Assert.AreEqual(1, _context.Projects.ToList()[0].Id);
            Assert.AreEqual("CrazyProject", _context.Projects.ToList()[0].Name);
            Assert.AreEqual("The most crazy project you can find out there", _context.Projects.ToList()[0].Description);
        }
Exemple #3
0
        public void CreateTest()
        {
            var result = _controller.Create() as ViewResult;

            Assert.AreEqual("Create", result.ViewName);

            Project project = new Project {
                ProjectName = "UnitTest", Discription = "Test And Test"
            };
            var rr = _controller.Create(project) as RedirectToRouteResult;

            Assert.AreEqual(string.Empty, rr.RouteName);
        }
Exemple #4
0
        public void Admin_Can_View_Create_Project()
        {
            // Arrange
            var user = new Mock <IPrincipal>();

            user.SetupGet(x => x.Identity.IsAuthenticated).Returns(true);
            user.Setup(x => x.IsInRole("Admin")).Returns(true);

            var context = new Mock <HttpContextBase>();

            context.SetupGet(x => x.User).Returns(user.Object);

            var controller = new ProjectController();

            var controllerContextMock = new Mock <ControllerContext>();

            controllerContextMock.SetupGet(con => con.HttpContext)
            .Returns(context.Object);

            controller.ControllerContext = controllerContextMock.Object;

            // Act
            ViewResult result = controller.Create() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
Exemple #5
0
        public void CreateGetLoggedUserTest()
        {
            // Arrange
            ProjectController controller = ControllersMocks.GetControllerAsLoggedUser <ProjectController>();

            // Act
            JsonResult action = controller.Create() as JsonResult;

            // Assert
            Assert.IsNotNull(action);
        }
Exemple #6
0
        public void CreatePostNotLoggedUserTest()
        {
            // Arrange
            ProjectController controller = ControllersMocks.GetControllerAsNotLoggedUser <ProjectController>();

            // Act
            JsonResult action    = controller.Create(ModelsMocks.ProjectModelFirst) as JsonResult;
            var        forbidden = (TaskVlopper.Models.JsonHttpViewModel)action.Data;

            // Assert
            Assert.AreEqual(403, forbidden.HttpCode);
        }
Exemple #7
0
        public void Create_ReturnsView()
        {
            // Arrange
            var controller = new ProjectController(_repository.Object);

            // Act
            var result = (ViewResult)controller.Create();

            // Assert
            Assert.IsNotNull(result, "ViewResult is null");
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
Exemple #8
0
        public void DeletePostLoggedUserTest()
        {
            using (IUnityContainer container = UnityConfig.GetConfiguredContainer())
            {
                var repository = container.Resolve <IProjectRepository>();
                repository.RemoveAll();



                // Arrange
                ProjectController controller = ControllersMocks.GetControllerAsLoggedUser <ProjectController>();

                JsonResult actionCreate = controller.Create(ModelsMocks.ProjectModelFirst) as JsonResult;
                // Act
                JsonResult actionDelete = controller.Delete(repository.GetAll().First().ID, ModelsMocks.Form) as JsonResult;

                // Assert
                Assert.AreEqual(0, repository.GetAll().Count());
            }
        }
Exemple #9
0
        public async Task CreateRedirectsToIndexOnSuccess()
        {
            //Given
            var db         = GenerateInMemDbContext(nameof(CreateRedirectsToIndexOnSuccess));
            var cctx       = GenerateFakeControllerContext();
            var mapper     = GetMapper();
            var controller = new ProjectController(db, mapper);

            //When
            controller.ControllerContext = cctx;
            var user = new IdentityUser();

            user.Id    = USER_ID;
            user.Email = USER_NAME;
            var other = new IdentityUser();

            other.Id    = Guid.NewGuid().ToString();
            other.Email = "someone else";
            var model = new ProjectViewModel();

            model.Title            = "test project";
            model.CompletionStatus = CompletionStatus.InProgress;
            await db.Users.AddAsync(user);

            await db.SaveChangesAsync();

            //Then
            var obj = await controller.Create(model);

            var result = (obj) as RedirectToActionResult;

            result.Should().NotBeNull(because: "We expect a Redirect result, not a " + obj.GetType().Name);
            result.ActionName.Should().Be("Index");
            var projData = await db.Projects.FirstOrDefaultAsync();

            projData.Title.Should().Be(model.Title);
            projData.CompletionStatus.Should().Be((int)model.CompletionStatus);
            projData.UserId.Should().Be(USER_ID);
            projData.Created.Should().BeCloseTo(DateTime.UtcNow, 50);
            projData.Updated.Should().BeCloseTo(DateTime.UtcNow, 50);
        }
Exemple #10
0
        public async void Create_Errors()
        {
            ProjectControllerMockFacade mock = new ProjectControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiProjectResponseModel> >(new FluentValidation.Results.ValidationResult());
            var mockRecord   = new ApiProjectResponseModel();

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiProjectRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiProjectResponseModel> >(mockResponse.Object));
            ProjectController controller = new ProjectController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiProjectRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiProjectRequestModel>()));
        }
Exemple #11
0
        public void CreatePostLoggedUserTest()
        {
            using (IUnityContainer container = UnityConfig.GetConfiguredContainer())
            {
                var repository = container.Resolve <IProjectRepository>();
                repository.RemoveAll();

                // Arrange
                ProjectController controller = ControllersMocks.GetControllerAsLoggedUser <ProjectController>();


                // Act
                JsonResult action = controller.Create(ModelsMocks.ProjectModelFirst) as JsonResult;

                // Assert
                Assert.AreEqual(repository.GetAll().
                                Where(x => x.Deadline == ModelsMocks.ProjectModelFirst.Deadline &&
                                      x.Description == ModelsMocks.ProjectModelFirst.Description &&
                                      x.EstimatedTimeInHours == ModelsMocks.ProjectModelFirst.EstimatedTimeInHours &&
                                      x.Name == ModelsMocks.ProjectModelFirst.Name &&
                                      x.StartDate == ModelsMocks.ProjectModelFirst.StartDate)
                                .Count(), 1);
            }
        }
 public void CreateProjectCallsProjectServiceAdd()
 {
     controller.Create(projectViewModel);
     projectService.Verify(p => p.Add(It.Is <Project>(pr => pr.Id == projectViewModel.Id)));
 }
Exemple #13
0
 public Project Create(Project t)
 {
     return(projectController.Create(t));
 }