예제 #1
0
        public async Task Should_Get_Tenant_ById()
        {
            var context    = Helpers.GetTenantContext();
            var tenantList = new List <Tenant>
            {
                new Tenant
                {
                    Id       = "test",
                    HostName = "test.decidehub.com"
                },
                new Tenant
                {
                    Id       = "test2",
                    HostName = "test2.decidehub.com"
                }
            };

            context.Tenants.AddRange(tenantList);
            context.SaveChanges();
            var tenantRepository = new EntityTenantRepository(context);
            var getTenant        = await tenantRepository.GetTenant("test");

            Assert.NotNull(getTenant);
            Assert.Equal("test", getTenant.Id);
        }
예제 #2
0
        public async Task Should_Get_TenantWithIgnoredQueries()
        {
            var context    = Helpers.GetTenantContext();
            var tenantList = new List <Tenant>
            {
                new Tenant
                {
                    Id       = "test",
                    HostName = "test.decidehub.com"
                },
                new Tenant
                {
                    Id       = "test2",
                    HostName = "test2.decidehub.com"
                },
                new Tenant
                {
                    Id       = "test3",
                    HostName = "test2.decidehub.com",
                    InActive = true
                }
            };

            context.Tenants.AddRange(tenantList);
            context.SaveChanges();
            var tenantRepository = new EntityTenantRepository(context);
            var tenant           = await tenantRepository.GetTenantWithIgnoredQueries("test3");

            Assert.True(tenant.InActive);
        }
예제 #3
0
        public PollJobServiceTests()
        {
            _context          = Helpers.GetContext("test");
            _tenantsDbContext = Helpers.GetTenantContext();
            IPollRepository         pollRepository = new EntityPollRepository(_context, _tenantsDbContext);
            IUserRepository         userRepository = new EntityUserRepository(_context, null);
            IUserService            userService    = new UserService(userRepository, null);
            IAsyncRepository <Vote> voteRepository = new EfRepository <Vote>(_context);
            var voteService = new VoteService(voteRepository, userService);
            ITenantRepository          tenantRepository  = new EntityTenantRepository(_tenantsDbContext);
            IAsyncRepository <Setting> settingRepository = new EfRepository <Setting>(_context);
            ISettingService            settingService    = new SettingService(settingRepository);
            ITenantService             tenantService     = new TenantService(tenantRepository, settingService, null);
            var policyService   = new PolicyService(new EfRepository <Policy>(_context));
            var emailSenderMock = new Mock <IEmailSender>();

            emailSenderMock.Setup(serv =>
                                  serv.SendEmailAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()));
            var genericServiceMock = new Mock <IGenericService>();

            genericServiceMock.Setup(serv => serv.GetBaseUrl(It.IsAny <string>()))
            .Returns(Task.FromResult("decidehub.com"));
            IPollService pollService = new PollService(pollRepository, settingService, userService, tenantService,
                                                       voteService, emailSenderMock.Object, genericServiceMock.Object);

            _pollJobService = new PollJobService(pollService, userService, voteService, settingService, pollRepository,
                                                 tenantService, policyService);
        }
예제 #4
0
        public ApiPollControllerTests()
        {
            _context     = Helpers.GetContext("test");
            _currentUser = new ApplicationUser
            {
                Email          = "*****@*****.**",
                FirstName      = "test",
                LastName       = "Test",
                CreatedAt      = DateTime.UtcNow,
                SecurityStamp  = new Guid().ToString(),
                EmailConfirmed = true,
                Id             = 1.ToString(),
                IsDeleted      = false,
                UserDetail     = new UserDetail {
                    AuthorityPercent = 30, LanguagePreference = "tr"
                }
            };
            _context.Users.Add(_currentUser);
            _context.SaveChanges();
            var                        tenantsDbContext  = Helpers.GetTenantContext();
            IPollRepository            pollRepository    = new EntityPollRepository(_context, tenantsDbContext);
            IAsyncRepository <Setting> settingRepository = new EfRepository <Setting>(_context);
            ISettingService            settingService    = new SettingService(settingRepository);
            IUserRepository            userRepository    = new EntityUserRepository(_context, null);
            IUserService               userService       = new UserService(userRepository, null);
            ITenantRepository          tenantRepository  = new EntityTenantRepository(tenantsDbContext);
            IAsyncRepository <Vote>    voteRepository    = new EfRepository <Vote>(_context);
            var                        voteService       = new VoteService(voteRepository, userService);
            ITenantService             tenantService     = new TenantService(tenantRepository, settingService, null);
            IPollService               pollService       = new PollService(pollRepository, settingService, userService, tenantService,
                                                                           voteService, null, null);
            var mapper             = Helpers.GetMapper();
            var tenantProviderMock = new Mock <ITenantProvider>();

            tenantProviderMock.Setup(serv => serv.GetTenantId()).Returns("test");
            _pollLocalizerMock = new Mock <IStringLocalizer <ApiPollController> >();
            IPollApiViewModelService pollApiViewModelService = new PollApiViewModelService(tenantProviderMock.Object,
                                                                                           pollService, mapper, voteService, userService, settingService);
            var genericServiceMock = new Mock <IGenericService>();

            genericServiceMock.Setup(serv => serv.GetBaseUrl(null)).Returns(Task.FromResult("decidehub.com"));
            _controller = new ApiPollController(pollService, mapper, userService, pollApiViewModelService,
                                                _pollLocalizerMock.Object, voteService, genericServiceMock.Object, tenantProviderMock.Object);
            var user = new ClaimsPrincipal(new ClaimsIdentity(new[]
            {
                new Claim(ClaimTypes.PrimarySid, "1")
            }));

            _controller.ControllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext {
                    User = user
                }
            };
        }
        public TenantServiceTests()
        {
            _context          = Helpers.GetContext("test");
            _tenantsDbContext = Helpers.GetTenantContext();
            ITenantRepository                  tenantRepository  = new EntityTenantRepository(_tenantsDbContext);
            IAsyncRepository <Setting>         settingRepository = new EfRepository <Setting>(_context);
            ISettingService                    settingService    = new SettingService(settingRepository);
            IAsyncRepository <ApplicationRole> roleRepository    = new EfRepository <ApplicationRole>(_context);
            IRoleService roleService = new RoleService(roleRepository);

            _tenantService = new TenantService(tenantRepository, settingService, roleService);
        }
예제 #6
0
        public async Task Should_Add_Tenant()
        {
            var context          = Helpers.GetTenantContext();
            var tenantRepository = new EntityTenantRepository(context);
            var tenant           = new Tenant
            {
                Id       = "test",
                HostName = "test.decidehub.com"
            };
            await tenantRepository.AddTenant(tenant);

            var tenants = context.Tenants;

            Assert.True(tenants.Count() > 0);
        }
예제 #7
0
        public async Task Should_Delete_Tenant()
        {
            var context          = Helpers.GetTenantContext();
            var tenantRepository = new EntityTenantRepository(context);
            var tenant           = new Tenant
            {
                Id       = "test",
                HostName = "test.decidehub.com"
            };

            context.Tenants.Add(tenant);
            context.SaveChanges();
            await tenantRepository.DeleteTenant(tenant.Id);

            var getTenant = context.Tenants.FirstOrDefault(x => x.Id == tenant.Id);

            Assert.Null(getTenant);
        }
        public PollApiViewModelServiceTests()
        {
            var tenantProviderMock = new Mock <ITenantProvider>();

            tenantProviderMock.Setup(serv => serv.GetTenantId()).Returns("test");
            _context = Helpers.GetContext("test");
            var tenantsDbContext = Helpers.GetTenantContext();
            ITenantRepository          tenantRepository  = new EntityTenantRepository(tenantsDbContext);
            IAsyncRepository <Setting> settingRepository = new EfRepository <Setting>(_context);
            IPollRepository            pollRepository    = new EntityPollRepository(_context, tenantsDbContext);
            ISettingService            settingService    = new SettingService(settingRepository);
            ITenantService             tenantService     = new TenantService(tenantRepository, settingService, null);
            IUserRepository            userRepository    = new EntityUserRepository(_context, null);
            IUserService            userService          = new UserService(userRepository, null);
            IAsyncRepository <Vote> voteRepository       = new EfRepository <Vote>(_context);
            var          voteService = new VoteService(voteRepository, userService);
            IPollService pollService = new PollService(pollRepository, settingService, userService, tenantService,
                                                       voteService, null, null);
            var mapper = Helpers.GetMapper();

            _pollApiViewModelService = new PollApiViewModelService(tenantProviderMock.Object, pollService, mapper,
                                                                   voteService, userService, settingService);
        }
예제 #9
0
        public ApiAccountControllerTests()
        {
            _context = Helpers.GetContext("test");
            var tenantsDbContext = Helpers.GetTenantContext();

            _userManager = new Mock <FakeUserManager>();
            ITenantRepository                  tenantRepository  = new EntityTenantRepository(tenantsDbContext);
            IAsyncRepository <Setting>         settingRepository = new EfRepository <Setting>(_context);
            ISettingService                    settingService    = new SettingService(settingRepository);
            IAsyncRepository <ApplicationRole> roleRepository    = new EfRepository <ApplicationRole>(_context);
            var            roleService   = new RoleService(roleRepository);
            ITenantService tenantService = new TenantService(tenantRepository, settingService, roleService);

            var userList = new List <ApplicationUser>();

            _userManager.Setup(x => x.Users).Returns(userList.AsQueryable());
            _userManager.Setup(x => x.CreateAsync(It.IsAny <ApplicationUser>(), It.IsAny <string>()))
            .Callback(
                (ApplicationUser usr, string pass) =>
            {
                usr.Id = "2";
                userList.Add(usr);
            })
            .ReturnsAsync(IdentityResult.Success);
            var userRepository = new EntityUserRepository(_context, _userManager.Object);
            var userService    = new UserService(userRepository, null);
            var emailSender    = new Mock <IEmailSender>();
            var configMock     = new Mock <IConfiguration>();

            _accountLocalizerMock = new Mock <IStringLocalizer <ApiAccountController> >();
            var tenantProviderMock = new Mock <ITenantProvider>();

            tenantProviderMock.Setup(serv => serv.GetTenantId()).Returns("test");

            _controller = new ApiAccountController(tenantService, userService, _userManager.Object, emailSender.Object,
                                                   configMock.Object, _accountLocalizerMock.Object, tenantProviderMock.Object);
            var currentUser = new ApplicationUser
            {
                Email          = "*****@*****.**",
                FirstName      = "test",
                LastName       = "Test",
                CreatedAt      = DateTime.UtcNow,
                SecurityStamp  = new Guid().ToString(),
                EmailConfirmed = true,
                Id             = "1",
                IsDeleted      = false,
                UserDetail     = new UserDetail
                {
                    InitialAuthorityPercent = 0, AuthorityPercent = 30, LanguagePreference = "tr"
                }
            };

            _context.Users.Add(currentUser);
            _context.SaveChanges();
            tenantsDbContext.Tenants.Add(new Tenant
            {
                Id       = "test",
                HostName = "test.decidehub.com",
                Lang     = "tr"
            });
            tenantsDbContext.SaveChanges();
        }
예제 #10
0
        public UserControllerTests()
        {
            _context     = Helpers.GetContext("test");
            _currentUser = new ApplicationUser
            {
                Email          = "*****@*****.**",
                FirstName      = "test",
                LastName       = "Test",
                CreatedAt      = DateTime.UtcNow,
                SecurityStamp  = new Guid().ToString(),
                EmailConfirmed = true,
                Id             = 1.ToString(),
                IsDeleted      = false,
                UserDetail     = new UserDetail {
                    AuthorityPercent = 30, LanguagePreference = "tr"
                }
            };
            _context.Roles.Add(new ApplicationRole {
                Id = 1.ToString(), Name = "Admin"
            });
            _context.UserRoles.Add(new IdentityUserRole <string> {
                RoleId = 1.ToString(), UserId = 1.ToString()
            });
            _context.Users.Add(_currentUser);
            _context.SaveChanges();
            _tenantsDbContext  = Helpers.GetTenantContext();
            _pollLocalizerMock = new Mock <IStringLocalizer <UserController> >();
            _userManager       = new Mock <FakeUserManager>();
            var userList = new List <ApplicationUser> {
                _currentUser
            };

            _userManager.Setup(x => x.Users).Returns(userList.AsQueryable());
            _userManager.Setup(x => x.FindByEmailAsync(It.IsAny <string>()))
            .ReturnsAsync((string x) => userList.FirstOrDefault(a => a.Email == x));
            _userManager.Setup(x => x.CreateAsync(It.IsAny <ApplicationUser>()))
            .Callback((ApplicationUser usr) => userList.Add(usr)).ReturnsAsync(IdentityResult.Success);
            _userManager.Setup(x => x.UpdateAsync(It.IsAny <ApplicationUser>()))
            .Callback((ApplicationUser usr) => userList[userList.FindIndex(x => x.Id == usr.Id)] = usr)
            .ReturnsAsync(IdentityResult.Success);
            _userManager.Setup(x => x.GeneratePasswordResetTokenAsync(It.IsAny <ApplicationUser>()))
            .ReturnsAsync(new Guid().ToString());
            var userRepository     = new EntityUserRepository(_context, _userManager.Object);
            var userService        = new UserService(userRepository, null);
            var tenantProviderMock = new Mock <ITenantProvider>();

            tenantProviderMock.Setup(serv => serv.GetTenantId()).Returns("test");
            var mapper = Helpers.GetMapper();
            var userApiViewModelService = new UserApiViewModelService(userService, mapper, tenantProviderMock.Object);
            ITenantRepository          tenantRepository  = new EntityTenantRepository(_tenantsDbContext);
            IAsyncRepository <Setting> settingRepository = new EfRepository <Setting>(_context);
            ISettingService            settingService    = new SettingService(settingRepository);
            ITenantService             tenantService     = new TenantService(tenantRepository, settingService, null);
            var emailSenderMock = new Mock <IEmailSender>();

            _configMock = new Mock <IConfiguration>();

            _controller = new UserController(userApiViewModelService, _userManager.Object, userService, tenantService,
                                             emailSenderMock.Object, _configMock.Object, _pollLocalizerMock.Object);
            var user = new ClaimsPrincipal(new ClaimsIdentity(new[]
            {
                new Claim(ClaimTypes.PrimarySid, _currentUser.Id)
            }));

            _controller.ControllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext {
                    User = user
                }
            };
        }