Example #1
0
        public AdminTests()
        {
            options = new DbContextOptionsBuilder <DrugstoreDbContext>()
                      .UseInMemoryDatabase(databaseName: "Drugstore_Admin").Options;

            var userStoreMock   = new Mock <IUserStore <SystemUser> >();
            var userManagerMock = new Mock <UserManager <SystemUser> >(userStoreMock.Object, null, null, null, null, null, null, null, null);
            var roleManagerMock = new Mock <RoleManager <IdentityRole> >(
                new Mock <IRoleStore <IdentityRole> >().Object,
                new IRoleValidator <IdentityRole> [0],
                new Mock <ILookupNormalizer>().Object,
                new Mock <IdentityErrorDescriber>().Object,
                new Mock <ILogger <RoleManager <IdentityRole> > >().Object);
            var passwordHasherMock = new Mock <IPasswordHasher <SystemUser> >();

            passwordHasherMock.Setup(p => p.HashPassword(It.IsAny <SystemUser>(), It.IsAny <string>()))
            .Returns("password");
            userManagerMock.Object.PasswordHasher = passwordHasherMock.Object;

            userManagerMock.Setup(u => u.CreateAsync(It.IsAny <SystemUser>()))
            .Returns(Task <IdentityResult> .FromResult(new IdentityResult()));

            userManagerMock.Setup(u => u.AddToRoleAsync(It.IsAny <SystemUser>(), It.IsAny <string>()))
            .Returns(Task <IdentityResult> .FromResult(new IdentityResult()));

            userManagerMock.Setup(u => u.FindByIdAsync(It.IsAny <string>()))
            .Returns(Task.FromResult <SystemUser>(new SystemUser()));

            userManagerMock.Setup(u => u.GetRolesAsync(It.IsAny <SystemUser>()))
            .Returns(Task.FromResult <IList <string> >(new string [] { "Admin" }));

            userManagerMock.Setup(u => u.DeleteAsync(It.IsAny <SystemUser>()))
            .Returns(Task.FromResult <IdentityResult>(new IdentityResult()));

            context = new DrugstoreDbContext(options);

            useCase = new AdminUseCase(userManagerMock.Object, roleManagerMock.Object, context);
        }
Example #2
0
 public AdminController(AdminUseCase adminUseCase, DrugstoreDbContext drugstore, UserManager <SystemUser> userManager)
 {
     this.adminUseCase = adminUseCase;
     this.drugstore    = drugstore;
     this.userManager  = userManager;
 }