private static Mock<IMediator> MockMediatorSkillDeleteQueryNullModel(out SkillController controller)
 {
     var mockMediator = new Mock<IMediator>();
     mockMediator.Setup(mock => mock.SendAsync(It.IsAny<SkillDeleteQuery>())).Returns(() => Task.FromResult<SkillDeleteViewModel>(null)).Verifiable();
     controller = new SkillController(mockMediator.Object);
     return mockMediator;
 }
        private static Mock<IMediator> MockMediatorSkillEditQuery(out SkillController controller, SkillEditViewModel model = null)
        {
            if (model == null) model = new SkillEditViewModel { Id = 1, Name = "Name", Description = "Description" };

            var mockMediator = new Mock<IMediator>();
            mockMediator.Setup(mock => mock.SendAsync(It.IsAny<SkillEditQuery>())).Returns(() => Task.FromResult(model)).Verifiable();
            mockMediator.Setup(mock => mock.SendAsync(It.IsAny<SkillListQuery>())).Returns(() => Task.FromResult(SummaryListItems()))
                .Verifiable();
            mockMediator.Setup(mock => mock.SendAsync(It.IsAny<OrganizationSelectListQuery>()))
                .Returns(() => Task.FromResult<IEnumerable<SelectListItem>>(new List<SelectListItem> { new SelectListItem { Text = "Item 1", Value = "1" } }))
                .Verifiable();
            controller = new SkillController(mockMediator.Object);
            return mockMediator;
        }
        private static Mock<IMediator> MockMediatorSkillDeleteQuery(out SkillController controller, SkillDeleteViewModel model = null)
        {
            if (model == null) model = new SkillDeleteViewModel {  HierarchicalName = "Name" };

            var mockMediator = new Mock<IMediator>();
            mockMediator.Setup(mock => mock.SendAsync(It.IsAny<SkillDeleteQuery>())).Returns(() => Task.FromResult(model)).Verifiable();
            controller = new SkillController(mockMediator.Object);
            return mockMediator;
        }
 private static Mock<IMediator> MockMediatorSkillListQuery(out SkillController controller)
 {
     var mockMediator = new Mock<IMediator>();
     mockMediator.Setup(mock => mock.SendAsync(It.IsAny<SkillListQuery>()))
         .Returns(() => Task.FromResult(SummaryListItems()))
         .Verifiable();
     mockMediator.Setup(mock => mock.SendAsync(It.IsAny<OrganizationNameQuery>()))
         .Returns(() => Task.FromResult(OrgName))
         .Verifiable();
     controller = new SkillController(mockMediator.Object);
     return mockMediator;
 }
 private static Mock<IMediator> MockMediatorSkillCreateQuery(out SkillController controller)
 {
     var mockMediator = new Mock<IMediator>();
     mockMediator.Setup(mock => mock.SendAsync(It.IsAny<SkillListQuery>())).Returns(() => Task.FromResult(SummaryListItems()))
         .Verifiable();
     mockMediator.Setup(mock => mock.SendAsync(It.IsAny<OrganizationSelectListQuery>()))
         .Returns(() => Task.FromResult<IEnumerable<SelectListItem>>(new List<SelectListItem> { new SelectListItem { Text = "Item 1", Value = "1" } }))
     .Verifiable();
     controller = new SkillController(mockMediator.Object);
     return mockMediator;
 }
 public void IndexHasHttpGetAttribute()
 {
     SkillController controller = new SkillController(null);
     var attribute = controller.GetAttributesOn(x => x.Index()).OfType<HttpGetAttribute>().SingleOrDefault();
     Assert.NotNull(attribute);
 }
        public async Task SkillEditGet_ReturnsEmptyParentSelection_WhenNoValidSkillsReturnedByListQuery()
        {
            // Arrange
            var mockMediator = new Mock<IMediator>();
            mockMediator.Setup(mock => mock.SendAsync(It.IsAny<SkillEditQuery>())).ReturnsAsync(EditSkillModel());
            mockMediator.Setup(mock => mock.SendAsync(It.IsAny<SkillListQuery>())).ReturnsAsync(new List<SkillSummaryViewModel>());

            var sut = new SkillController(mockMediator.Object);
            var mockContext = MockControllerContextWithUser(SiteAdmin());
            sut.ControllerContext = mockContext.Object;

            // Act
            var result = await sut.Edit(1);

            // Assert
            var viewResult = Assert.IsType<ViewResult>(result);
            var model = viewResult.Model as SkillEditViewModel;

            model.ParentSelection.ShouldBeEmpty();
        }
 public void DeleteConfirmedHasValidateAntiForgeryTokenAttribute()
 {
     SkillController controller = new SkillController(null);
     var attribute = controller.GetAttributesOn(x => x.DeleteConfirmed(It.IsAny<SkillDeleteViewModel>())).OfType<ValidateAntiForgeryTokenAttribute>().SingleOrDefault();
     Assert.NotNull(attribute);
 }
 public void DeleteConfirmedHasActionNameAttributeWithCorrerctActionName()
 {
     SkillController controller = new SkillController(null);
     var attribute = controller.GetAttributesOn(x => x.DeleteConfirmed(It.IsAny<SkillDeleteViewModel>())).OfType<ActionNameAttribute>().SingleOrDefault();
     Assert.NotNull(attribute);
     Assert.Equal(attribute.Name, "Delete");
 }
 public void DeleteHasHttpGetAttribute()
 {
     SkillController controller = new SkillController(null);
     var attribute = controller.GetAttributesOn(x => x.Delete(It.IsAny<int>())).OfType<HttpGetAttribute>().SingleOrDefault();
     Assert.NotNull(attribute);
 }
 public void EditPostHasValidateAntiForgeryTokenttrbitue()
 {
     SkillController controller = new SkillController(null);
     var attribute = controller.GetAttributesOn(x => x.Edit(It.IsAny<SkillEditViewModel>())).OfType<ValidateAntiForgeryTokenAttribute>().SingleOrDefault();
     Assert.NotNull(attribute);
 }
 public void CreatePostHasHttpPostAttribute()
 {
     SkillController controller = new SkillController(null);
     var attribute = controller.GetAttributesOn(x => x.Create(It.IsAny<SkillEditViewModel>())).OfType<HttpPostAttribute>().SingleOrDefault();
     Assert.NotNull(attribute);
 }