Beispiel #1
0
        private Role SetUpData()
        {
            Role model = ObjectsFactory.CreateRole(0);

            foreach (String controller in new[] { nameof(Accounts), nameof(Roles) })
            {
                foreach (String action in new[] { nameof(Roles.Create), nameof(Accounts.Details) })
                {
                    model.Permissions.Add(new RolePermission
                    {
                        Permission = new Permission
                        {
                            Area       = controller == nameof(Roles) ? nameof(Area.Administration) : "",
                            Controller = controller,
                            Action     = action
                        }
                    });
                }
            }

            context.Drop().Add(model);
            context.SaveChanges();

            return(model);
        }
Beispiel #2
0
        public void OnResourceExecuted_Exception_Rollbacks()
        {
            ActionContext           action  = new(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
            ResourceExecutedContext context = new(action, Array.Empty <IFilterMetadata>());

            using DbContext currentContext = TestingContext.Create();
            using DbContext testingContext = TestingContext.Create();
            Role role = ObjectsFactory.CreateRole(0);

            context.Exception = new Exception();

            testingContext.Drop();

            TransactionFilter filter = new(testingContext);

            testingContext.Add(role);
            testingContext.SaveChanges();

            Assert.Empty(currentContext.Set <Role>());
            Assert.Single(testingContext.Set <Role>());

            filter.OnResourceExecuted(context);

            Assert.Empty(currentContext.Set <Role>());
            Assert.Empty(testingContext.Set <Role>());
        }
        private Role SetUpData()
        {
            Role role = ObjectsFactory.CreateRole();

            foreach (String controller in new[] { "Roles", "Profile" })
            {
                foreach (String action in new[] { "Edit", "Delete" })
                {
                    role.Permissions.Add(new RolePermission
                    {
                        Permission = new Permission
                        {
                            Area       = controller == "Roles" ? "Administration" : null,
                            Controller = controller,
                            Action     = action
                        }
                    });
                }
            }

            context.Add(role);
            context.SaveChanges();

            return(role);
        }
        private Role SetUpData()
        {
            Role role = ObjectsFactory.CreateRole(0);

            foreach (String controller in new[] { "TestController1", "TestController2" })
            {
                foreach (String action in new[] { "Action1", "Action2" })
                {
                    role.Permissions.Add(new RolePermission
                    {
                        Permission = new Permission
                        {
                            Area       = controller == "TestController1" ? "TestingArea" : "",
                            Controller = controller,
                            Action     = action
                        }
                    });
                }
            }

            context.Drop().Add(role);
            context.SaveChanges();

            return(role);
        }
Beispiel #5
0
        public RoleValidatorTests()
        {
            context   = new TestingContext();
            validator = new RoleValidator(new UnitOfWork(context));

            context.Add(role = ObjectsFactory.CreateRole());
            context.SaveChanges();
        }
        public UnitOfWorkTests()
        {
            context    = TestingContext.Create();
            model      = ObjectsFactory.CreateRole(0);
            unitOfWork = new UnitOfWork(context);

            context.Drop();
        }
Beispiel #7
0
        public QueryTests()
        {
            context = TestingContext.Create();
            select  = new Query <Role>(context.Set <Role>(), TestingContext.Mapper.ConfigurationProvider);

            context.Drop().Add(ObjectsFactory.CreateRole(0));
            context.SaveChanges();
        }
Beispiel #8
0
        public QueryTests()
        {
            context = TestingContext.Create();
            select  = new Query <Role>(context.Set <Role>());

            context.Drop().Add(ObjectsFactory.CreateRole(0));
            context.SaveChanges();
        }
Beispiel #9
0
        public RoleValidatorTests()
        {
            context   = TestingContext.Create();
            validator = new RoleValidator(new UnitOfWork(TestingContext.Create(), TestingContext.Mapper));

            context.Drop().Add(role = ObjectsFactory.CreateRole(0));
            context.SaveChanges();
        }
        public AuditedUnitOfWorkTests()
        {
            context    = TestingContext.Create();
            model      = ObjectsFactory.CreateRole(0);
            unitOfWork = new AuditedUnitOfWork(context, 1);

            context.Drop().Add(model);
            context.SaveChanges();
        }
Beispiel #11
0
        public void MapRoles_Role_RoleView()
        {
            Role     expected = ObjectsFactory.CreateRole();
            RoleView actual   = Mapper.Map <RoleView>(expected);

            Assert.Equal(expected.CreationDate, actual.CreationDate);
            Assert.Equal(expected.Title, actual.Title);
            Assert.Equal(expected.Id, actual.Id);
            Assert.NotNull(actual.Permissions);
        }
Beispiel #12
0
        public LoggableEntityTests()
        {
            using (context = TestingContext.Create())
            {
                context.Drop().Add(model = ObjectsFactory.CreateRole(0));
                context.SaveChanges();
            }

            context = TestingContext.Create();
            entry = context.Entry<AModel>(model);
        }
Beispiel #13
0
        public void Map_Role_RoleView()
        {
            Role     expected = ObjectsFactory.CreateRole(0);
            RoleView actual   = TestingContext.Mapper.Map <RoleView>(expected);

            Assert.Equal(expected.CreationDate, actual.CreationDate);
            Assert.Empty(actual.Permissions.SelectedIds);
            Assert.Equal(expected.Title, actual.Title);
            Assert.Empty(actual.Permissions.Nodes);
            Assert.Equal(expected.Id, actual.Id);
        }
        public void DeleteRange_Models()
        {
            IEnumerable <Role> models = new[] { ObjectsFactory.CreateRole(2), ObjectsFactory.CreateRole(3) };

            context.AddRange(models);
            context.SaveChanges();

            unitOfWork.DeleteRange(models);
            unitOfWork.Commit();

            Assert.Empty(context.Set <Role>());
        }
        public void Commit_DoesNotChangeTrackingBehaviour(Boolean detectChanges)
        {
            context.ChangeTracker.AutoDetectChangesEnabled = detectChanges;

            unitOfWork.Insert(ObjectsFactory.CreateRole(1));
            unitOfWork.Commit();

            Boolean actual   = context.ChangeTracker.AutoDetectChangesEnabled;
            Boolean expected = detectChanges;

            Assert.Equal(expected, actual);
        }
        public void InsertRange_AddsModelsToDbSet()
        {
            IEnumerable <Role> roles          = new[] { ObjectsFactory.CreateRole(2), ObjectsFactory.CreateRole(3) };
            DbContext          testingContext = Substitute.For <DbContext>();

            unitOfWork.Dispose();

            unitOfWork = new UnitOfWork(testingContext);
            unitOfWork.InsertRange(roles);

            foreach (Role role in roles)
            {
                testingContext.Received().Add(role);
            }
        }
        public void Commit_AddedAudit()
        {
            context.Dispose();
            unitOfWork.Dispose();
            context    = TestingContext.Create();
            unitOfWork = new AuditedUnitOfWork(context, 1);
            unitOfWork.Insert(ObjectsFactory.CreateRole(1));

            LoggableEntity expected = new(context.ChangeTracker.Entries <AModel>().Single());

            unitOfWork.Commit();

            AuditLog actual = Assert.Single(unitOfWork.Select <AuditLog>());

            Assert.Equal(expected.ToString(), actual.Changes);
            Assert.Equal(expected.Name, actual.EntityName);
            Assert.Equal(expected.Action, actual.Action);
            Assert.Equal(expected.Id(), actual.EntityId);
            Assert.Equal(1, actual.AccountId);
        }
Beispiel #18
0
        public void Seed_RemovesUnusedPermissions()
        {
            Role role = ObjectsFactory.CreateRole(0);

            role.Permissions.Add(new RolePermission
            {
                Permission = new Permission {
                    Area = "Test", Controller = "Test", Action = "Test"
                }
            });

            context.Add(role);
            context.SaveChanges();

            configuration.Seed();

            Assert.Empty(context.Set <Permission>().Where(permission =>
                                                          permission.Controller == "Test" &&
                                                          permission.Action == "Test" &&
                                                          permission.Area == "Test"));
        }
Beispiel #19
0
        private void SetUpData()
        {
            role = ObjectsFactory.CreateRole();
            foreach (String controller in new[] { "Roles", "Profile" })
            {
                foreach (String action in new[] { "Edit", "Delete" })
                {
                    RolePermission rolePermission = ObjectsFactory.CreateRolePermission(role.Permissions.Count + 1);
                    rolePermission.Permission.Area       = controller == "Roles" ? "Administration" : null;
                    rolePermission.Permission.Controller = controller;
                    rolePermission.Permission.Action     = action;
                    rolePermission.RoleId = role.Id;
                    rolePermission.Role   = null;

                    role.Permissions.Add(rolePermission);
                }
            }

            context.Add(role);
            context.SaveChanges();
        }