Exemple #1
0
        private Mock <NotesController> GetNoteController(Mock <DefaultContext> db, User user)
        {
            var httpContext = MockHelper.GetHttpContextWithUserId(user.Id);
            var userManager = MockHelper.GetUserManagerWithUser(db.Object);

            userManager.Setup(um => um.GetUserAsync(It.Is <ClaimsPrincipal>(t => true))).ReturnsAsync(user);

            var signInManager = new Mock <SignInManager <User> >(userManager.Object,
                                                                 new HttpContextAccessor {
                HttpContext = httpContext.Object
            },
                                                                 new Mock <IUserClaimsPrincipalFactory <User> >().Object, null, null, null
                                                                 );

            Func <object, JsonResult> toJson = (data) => {
                return(new JsonResult(data));
            };

            var manager        = new CryptographManager();
            var modelsFactory  = new ModelsFactory();
            var outputFactory  = new OutputFactory(manager);
            var notesManager   = new NotesManager(db.Object, manager, modelsFactory, userManager.Object);
            var notesValidator = new NotesViewModelValidator(db.Object, manager, modelsFactory);

            var ctrlNotes = new Mock <NotesController>(userManager.Object, outputFactory, notesManager, notesValidator);

            ctrlNotes.Setup(ctrl => ctrl.Json(It.IsAny <object>())).Returns(toJson);

            ctrlNotes.Object.ControllerContext = new ControllerContext()
            {
                HttpContext = httpContext.Object
            };

            return(ctrlNotes);
        }
Exemple #2
0
 public NotesController(UserManager <User> userManager, IOutputFactory outputFactory, INotesManager notesMng, NotesViewModelValidator notesValidator)
 {
     _userManager    = userManager;
     _outputFactory  = outputFactory;
     _notesMng       = notesMng;
     _notesValidator = notesValidator;
 }