public async void GoalCreatePostForOrgAdminWithValidModelStateReturnsRedirectToAction()
        {
            const int campaignId = 123;
            // Arrange
            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(mock => mock.SendAsync(It.IsAny <CampaignSummaryQuery>()))
            .ReturnsAsync(new CampaignSummaryViewModel {
                Id = campaignId, OrganizationId = OrgAdminOrgId
            })
            .Verifiable();

            var goalController = new GoalController(mockMediator.Object);

            var mockContext = MockControllerContextWithUser(OrgAdmin(OrgAdminOrgId));

            goalController.ControllerContext = mockContext.Object;

            var vm = new GoalEditViewModel {
                GoalType = GoalType.Text, TextualGoal = "Aim to please"
            };

            // Act
            var result = await goalController.Create(campaignId, vm) as RedirectToActionResult;


            // Assert
            Assert.NotNull(result);
            Assert.Equal("Details", result.ActionName);
            Assert.Equal("Campaign", result.ControllerName);
            Assert.Equal("admin", result.RouteValues["area"]);
            Assert.Equal(campaignId, result.RouteValues["id"]);

            mockMediator.Verify(mock => mock.SendAsync(It.IsAny <GoalEditCommand>()), Times.Once);
        }
Exemple #2
0
        public async Task Test_Create_Creates_Goal()
        {
            controller.ControllerContext = new MockControllerContext().ControllerContext.Object;

            var goal = new Goal {
                PlayerId = 1, ManagerId = 1, GameWeekId = 1
            };

            await controller.Create(goal);

            context.MockGoals.Verify(x => x.Add(It.Is <Goal>(t => t == goal)));
        }
Exemple #3
0
        public async Task Create_Should_Add_New_Goal()
        {
            var expectedViewResultName  = "Index";
            var expectedRepositoryCount = 4;

            var newGoal = new ToDoGoal {
                Id = 0, Title = "new test goal", IsDone = false
            };

            var result = await goalController.Create(newGoal);

            var viewResult = Assert.IsType <RedirectToActionResult>(result);
            var allGoals   = await repository.GetAllGoals();

            var goalsCount = allGoals.Count;

            Assert.Equal(expectedViewResultName, viewResult.ActionName);
            Assert.Equal(expectedRepositoryCount, goalsCount);
        }
        public void CannotCreateWithMissingValues()
        {
            Mock <IGenericService <Goal> > goalServiceMock = new Mock <IGenericService <Goal> >();

            Goal goal = new Goal()
            {
                Id          = 100,
                Bloom       = null,
                Description = @"Je begrijpt de basismechanismen voor access control, zodanig dat je in eigen woorden kunt uitleggen wat de betekenis is in de context van software security. "
            };

            ClaimsPrincipal identity = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.NameIdentifier, "123")
            }));

            goalServiceMock.Setup(m => m.Insert(It.IsAny <Goal>())).Returns((Goal model) =>
            {
                if (!string.IsNullOrWhiteSpace(model.Bloom) && !string.IsNullOrWhiteSpace(model.Description))
                {
                    return(1);
                }

                return(0);
            });

            GoalController controller = new GoalController(goalServiceMock.Object)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = new DefaultHttpContext()
                    {
                        User = identity
                    }
                }
            };

            ViewResult result = controller.Create(goal) as ViewResult;

            Assert.NotNull(result);
            Assert.NotNull(result.Model);
            Assert.True(string.IsNullOrEmpty(result.ViewName) || result.ViewName == "Edit");
        }
        public void ShouldCreateCorrectly()
        {
            Mock <IGenericService <Goal> > goalMock = new Mock <IGenericService <Goal> >();

            Goal goal = new Goal()
            {
                Id          = 100,
                Bloom       = "Understand",
                Description = @"Je begrijpt de basismechanismen voor access control, zodanig dat je in eigen woorden kunt uitleggen wat de betekenis is in de context van software security. "
            };

            ClaimsPrincipal identity = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.NameIdentifier, "123")
            }));

            goalMock.Setup(m => m.Insert(It.IsAny <Goal>())).Returns((Goal model) =>
            {
                if (!string.IsNullOrWhiteSpace(model.Bloom) && !string.IsNullOrWhiteSpace(model.Description))
                {
                    return(1);
                }

                return(0);
            });

            GoalController controller = new GoalController(goalMock.Object)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = new DefaultHttpContext()
                    {
                        User = identity
                    }
                }
            };

            RedirectToActionResult result = controller.Create(goal) as RedirectToActionResult;

            Assert.Equal("Index", result?.ActionName);
        }
        public async void TestGoalCreateForWrongOrgAdminReturns401()
        {
            // Arrange
            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(mock => mock.SendAsync(It.IsAny <CampaignSummaryQuery>()))
            .ReturnsAsync(new CampaignSummaryViewModel())
            .Verifiable();

            var goalController = new GoalController(mockMediator.Object);

            var mockContext = MockControllerContextWithUser(OrgAdmin(654));

            goalController.ControllerContext = mockContext.Object;

            // Act
            var result = await goalController.Create(123);

            // Assert
            Assert.IsType <UnauthorizedResult>(result);
        }