public async Task GrantAccessToApprovers()
            {
                // Arrange
                var cost = MockCost();

                var techApprover = new ApprovalMember
                {
                    Id       = Guid.NewGuid(),
                    MemberId = Guid.NewGuid(),
                    CostUser = new CostUser
                    {
                        FullName = "Test"
                    }
                };
                var approvals = new List <Approval>
                {
                    new Approval
                    {
                        Type            = ApprovalType.IPM,
                        ApprovalMembers = new List <ApprovalMember>
                        {
                            techApprover
                        }
                    }
                };

                EFContext.Approval.AddRange(approvals);
                EFContext.SaveChanges();

                // Act
                await ApprovalService.SubmitApprovals(cost, CostUser, approvals, BuType.Pg);

                // Assert
                PermissionServiceMock.Verify(p => p.GrantApproverAccess(CostUser.Id, cost.Id, It.IsAny <IEnumerable <CostUser> >(), It.IsAny <BuType>()));
            }
        public void TestGetAllUserRolesNoPermission()
        {
            _userRoleController.ControllerContext.HttpContext = PermissionServiceMock.UnauthorizedHttpContext();
            var result = _userRoleController.GetProjectUserRoles(_projId).Result;

            Assert.IsInstanceOf <ForbidResult>(result);
        }
        public void TestDeleteUserRoleNoPermission()
        {
            _userRoleController.ControllerContext.HttpContext = PermissionServiceMock.UnauthorizedHttpContext();
            var userRole = _userRoleRepo.Create(RandomUserRole()).Result;
            var result   = _userRoleController.DeleteUserRole(_projId, userRole.Id).Result;

            Assert.IsInstanceOf <ForbidResult>(result);
        }
        public void TestUpdateUserRolesNoPermission()
        {
            _userRoleController.ControllerContext.HttpContext = PermissionServiceMock.UnauthorizedHttpContext();
            var userRole = RandomUserRole();
            var result   = _userRoleController.UpdateUserRolePermissions(
                InvalidProjectId, userRole.Id, userRole.Permissions.ToArray()).Result;

            Assert.IsInstanceOf <ForbidResult>(result);
        }
Exemplo n.º 5
0
        public void Setup()
        {
            _projRepo          = new ProjectRepositoryMock();
            _wordRepo          = new WordRepositoryMock();
            _permissionService = new PermissionServiceMock();
            _wordService       = new WordService(_wordRepo);
            _audioController   = new AudioController(_wordRepo, _wordService, _permissionService);
            _wordController    = new WordController(_wordRepo, _wordService, _projRepo, _permissionService);

            _projId = _projRepo.Create(new Project {
                Name = "AudioControllerTests"
            }).Result !.Id;
        }
Exemplo n.º 6
0
        public void Setup()
        {
            _userRepo          = new UserRepositoryMock();
            _permissionService = new PermissionServiceMock(_userRepo);
            _avatarController  = new AvatarController(_userRepo, _permissionService)
            {
                // Mock the Http Context because this isn't an actual call avatar controller
                ControllerContext = new ControllerContext {
                    HttpContext = new DefaultHttpContext()
                }
            };
            _userController = new UserController(
                _userRepo, _permissionService, new EmailServiceMock(), new PasswordResetServiceMock());

            _userController.ControllerContext = new ControllerContext {
                HttpContext = new DefaultHttpContext()
            };
            _jwtAuthenticatedUser = new User {
                Username = "******", Password = "******"
            };
            _userRepo.Create(_jwtAuthenticatedUser);
            _jwtAuthenticatedUser = _permissionService.Authenticate(
                _jwtAuthenticatedUser.Username, _jwtAuthenticatedUser.Password).Result ?? throw new Exception();
        }
Exemplo n.º 7
0
        public async Task HandleA5EventObject_BU_AgencyCreated()
        {
            //Setup
            var a5Agency = await GetA5Agency();

            var labelz = a5Agency._cm.Common.Labels.ToList();

            labelz.Add("CM_Prime_P&G");
            a5Agency._cm.Common.Labels = labelz.ToArray();

            var costUser = new CostUser
            {
                Id         = Guid.NewGuid(),
                GdamUserId = a5Agency.CreatedBy._id,
                ParentId   = Guid.NewGuid()
            };
            var agency = new Agency {
                Id = Guid.NewGuid(), GdamAgencyId = a5Agency._id
            };
            var brand = new Brand {
                Id = Guid.NewGuid(), Name = "Brand", AdIdPrefix = "prefix"
            };
            var country = new Country {
                Iso = "GB", Id = Guid.NewGuid()
            };
            var currency = new Currency {
                DefaultCurrency = true, Code = "TEST", Description = "Test Currency"
            };

            var costUsers = new List <CostUser> {
                costUser
            }.AsQueryable();
            var brands = new List <Brand> {
                brand
            }.AsQueryable();

            var abstractTypes = new List <AbstractType>
            {
                new AbstractType
                {
                    Type = AbstractObjectType.Agency.ToString(),
                    Id   = Guid.NewGuid()
                },
                new AbstractType
                {
                    Type   = AbstractObjectType.Module.ToString(),
                    Module = new Module
                    {
                        ClientType = ClientType.Pg
                    },
                    Id = Guid.NewGuid()
                }
            };

            EFContext.AbstractType.AddRange(abstractTypes);
            EFContext.Country.Add(country);
            EFContext.Agency.Add(new Agency
            {
                Name    = "Media Agency",
                Version = 1,
                Labels  = new string[] { }
            });
            EFContext.CostUser.AddRange(costUsers);
            EFContext.Brand.AddRange(brands);
            EFContext.Currency.Add(currency);

            EFContext.SaveChanges();

            PluginAgencyServiceMock.Setup(a => a.AddAgencyAbstractType(It.IsAny <Agency>(), It.IsAny <AbstractType>()))
            .ReturnsAsync(new AbstractType {
                Id = Guid.NewGuid(), ObjectId = Guid.NewGuid()
            });

            PgUserServiceMock.Setup(a => a.AddUsersToAgencyAbstractType(It.IsAny <AbstractType>(), It.IsAny <Guid>())).Returns(Task.CompletedTask);

            //Act
            var addedAgency = await AgencyService.AddAgencyToDb(a5Agency);

            //Assert
            PermissionServiceMock.Verify(a => a.CreateDomainNode(It.IsAny <string>(), It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Once);
            EFContext.Agency.Should().HaveCount(2);
            EFContext.AbstractType.Should().HaveCount(3);
            EFContext.GlobalAgencyRegion.Should().HaveCount(0);
            EFContext.GlobalAgency.Should().HaveCount(0);
            addedAgency.Should().NotBeNull();
            addedAgency.Name.Should().Be("Saatchi");
            addedAgency.Labels.Length.Should().Be(7);
            addedAgency.GdamAgencyId.Should().Be(a5Agency._id);
        }
Exemplo n.º 8
0
        public async Task HandleA5EventObject_Media_AgencyCreated()
        {
            //Setup
            var basePath = AppContext.BaseDirectory;
            var filePath = $"{basePath}{Path.DirectorySeparatorChar}JsonData{Path.DirectorySeparatorChar}a5_agency.json";
            var a5Agency = await JsonReader.GetObject <A5Agency>(filePath, true);

            a5Agency._cm.Common.Labels = a5Agency._cm.Common.Labels.Where(a => !a.StartsWith("SMO_")).ToArray();

            PermissionServiceMock.Setup(a => a.CreateDomainNode(It.IsAny <string>(), It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <Guid>()))
            .ReturnsAsync(new[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString() });
            var costUser = new CostUser
            {
                Id         = Guid.NewGuid(),
                GdamUserId = a5Agency.CreatedBy._id,
                ParentId   = Guid.NewGuid()
            };
            var agency = new Agency {
                Id = Guid.NewGuid(), GdamAgencyId = a5Agency._id
            };
            var brand = new Brand {
                Id = Guid.NewGuid(), Name = "Brand", AdIdPrefix = "prefix"
            };
            var country = new Country {
                Iso = "GB", Id = Guid.NewGuid()
            };
            var currency = new Currency {
                DefaultCurrency = true, Code = "TEST", Description = "Test Currency"
            };

            var costUsers = new List <CostUser> {
                costUser
            }.AsQueryable();
            var brands = new List <Brand> {
                brand
            }.AsQueryable();

            var abstractTypes = new List <AbstractType>
            {
                new AbstractType
                {
                    Type = AbstractObjectType.Agency.ToString(),
                    Id   = Guid.NewGuid()
                },
                new AbstractType
                {
                    Type   = AbstractObjectType.Module.ToString(),
                    Module = new Module
                    {
                        ClientType = ClientType.Pg
                    },
                    Id = Guid.NewGuid()
                }
            };

            EFContext.AbstractType.AddRange(abstractTypes);
            EFContext.Country.Add(country);
            EFContext.CostUser.AddRange(costUsers);
            EFContext.Brand.AddRange(brands);
            EFContext.Currency.Add(currency);

            EFContext.SaveChanges();

            //Act
            await AgencyService.AddAgencyToDb(a5Agency);

            //Assert
            PermissionServiceMock.Verify(a => a.CreateDomainNode(It.IsAny <string>(), It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Never);
            EFContext.Agency.Should().HaveCount(1);
            EFContext.GlobalAgencyRegion.Should().HaveCount(0);
            EFContext.GlobalAgency.Should().HaveCount(0);
        }
            public async Task CallRejectOnApprovalServiceForLatestRevision()
            {
                // Arrange
                const ApprovalType approvalType = ApprovalType.IPM;
                var participantId  = Guid.NewGuid();
                var approverRoleId = Guid.NewGuid();

                var cost = MockCost();

                var approval = new Approval
                {
                    CostStageRevisionId = cost.LatestCostStageRevision.Id,
                    Type            = approvalType,
                    ApprovalMembers = new List <ApprovalMember>
                    {
                        new ApprovalMember
                        {
                            MemberId = User.Id
                        }
                    }
                };

                foreach (var member in approval.ApprovalMembers)
                {
                    member.Approval = approval;
                }
                cost.LatestCostStageRevision.Approvals = new List <Approval> {
                    approval
                };

                EFContext.Approval.Add(approval);
                EFContext.UserUserGroup.Add(new UserUserGroup
                {
                    UserId    = participantId,
                    Id        = Guid.NewGuid(),
                    UserGroup = new UserGroup
                    {
                        ObjectId = cost.Id,
                        Id       = Guid.NewGuid(),
                        RoleId   = approverRoleId,
                    }
                });
                EFContext.Role.Add(new Role
                {
                    Id   = approverRoleId,
                    Name = Roles.CostApprover
                });
                EFContext.SaveChanges();

                cost.Status = CostStageRevisionStatus.Approved;

                // Act
                var response = await ApprovalService.Reject(cost.Id, User, BuType.Pg, null);

                // Assert
                response.Should().NotBeNull();
                response.Success.Should().BeTrue();
                PermissionServiceMock.Verify(p =>
                                             p.RevokeApproverAccess(cost.OwnerId, cost.Id, It.IsAny <IEnumerable <CostUser> >()),
                                             Times.Once);

                PermissionServiceMock.Verify(p =>
                                             p.GrantCostPermission(cost.Id, Roles.CostViewer, It.IsAny <IEnumerable <CostUser> >(), BuType.Pg, It.IsAny <Guid?>(), true),
                                             Times.Once);
            }