Example #1
0
            public void GetRolesShouldReturnDistinctRoles(string userMail)
            {
                TokenBearerHelper.MockUserServices(out Cfg, out Pc, out Irs, out Ips);
                User          user    = Context.User.FirstOrDefault(u => u.Email == userMail);
                Role          role    = Context.Role.FirstOrDefault(r => r.Name == "Moderator");
                Queue <Event> evQueue = new Queue <Event>(Context.Event.Take(3).ToArray());

                while (!evQueue.IsNullOrEmpty())
                {
                    int id = evQueue.Dequeue().Id;
                    Context.TemporaryRoles.Add(
                        new TemporaryRole()
                    {
                        UserId = user.Id, EventId = id, RoleId = role.Id
                    }
                        );
                }
                Context.SaveChanges();

                var service = new UserServices(Context, Cfg.Object, Ips.Object, Irs.Object);
                var claims  = service.GetRoles(user.Id);

                Assert.NotNull(claims);
                Assert.NotEmpty(claims);
                Assert.Single(claims);
            }
Example #2
0
            public void GetRoleWithwrongValueShouldReturnNull()
            {
                TokenBearerHelper.MockUserServices(out Cfg, out Pc, out Irs, out Ips);
                SetIrsToSuccessReturn();
                UserServices service = new Mock <UserServices>(Context, Cfg.Object, Ips.Object, Irs.Object).Object;

                Role role = new Role();
                var  args = new Object[] { "unknown_value", role };
                var  m    = typeof(UserServices).GetMethod("GetRole", BindingFlags.Instance | BindingFlags.NonPublic);

                m.Invoke(service, args);
                role = args[1] as Role;

                Assert.Null(role);
            }
Example #3
0
            public void GetRoleWithNullShouldReturnForeigner()
            {
                TokenBearerHelper.MockUserServices(out Cfg, out Pc, out Irs, out Ips);
                SetIrsToSuccessReturn();
                UserServices service = new Mock <UserServices>(Context, Cfg.Object, Ips.Object, Irs.Object).Object;

                Role role = new Role();
                var  args = new Object[] { null, role };
                var  m    = typeof(UserServices).GetMethod("GetRole", BindingFlags.NonPublic | BindingFlags.Instance);

                m.Invoke(service, args);
                role = args[1] as Role;

                Assert.NotNull(role);
                Assert.Equal("Foreigner", role.Name);
            }
 public GetToken()
 {
     TokenBearerHelper.MockUserServices(out Configuration, out PlannerContext, out RoleServices,
                                        out PromotionServices);
 }