Exemplo n.º 1
0
        public async Task HandleA5EventObject_ProjectCreated_Not_Saved(A5Project project)
        {
            //Setup
            _gdamClientMock.Setup(a => a.FindProjectById(project._id)).ReturnsAsync(project);
            _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 agency = new Agency {
                Id = Guid.NewGuid(), GdamAgencyId = project.Agency._id, Labels = new[] { "stuff" }
            };
            var costUser = new CostUser
            {
                Id         = Guid.NewGuid(),
                GdamUserId = project.CreatedBy._id,
                ParentId   = Guid.NewGuid()
            };

            var agencies = new List <Agency> {
                agency
            }.AsQueryable();
            var costUsers = new List <CostUser> {
                costUser
            }.AsQueryable();
            var projectsList = new List <Project>().AsQueryable();

            _efContextMock.MockAsyncQueryable(agencies, c => c.Agency);
            _efContextMock.MockAsyncQueryable(costUsers, c => c.CostUser);
            _efContextMock.MockAsyncQueryable(projectsList, c => c.Project);

            //Act
            await _projectService.AddProjectToDb(project);

            //Assert
            _efContextMock.Verify(a => a.Add(It.IsAny <Project>()), Times.Never);
        }
        protected void SetupDataSharedAcrossTests(Agency agency, Country country,
                                                  Cost cost, CostStageRevision latestRevision, Project project, CostUser costOwner, Guid costOwnerId, CostStage costStage,
                                                  Brand brand, Guid costId, Guid costStageRevisionId, Guid projectId, string budgetRegion = Constants.BudgetRegion.AsiaPacific)
        {
            agency.Country  = country;
            cost.CostNumber = CostNumber;
            cost.LatestCostStageRevision = latestRevision;
            cost.Project             = project;
            costOwner.Agency         = agency;
            costOwner.Id             = costOwnerId;
            latestRevision.CostStage = costStage;
            project.Brand            = brand;

            agency.Name           = AgencyName;
            brand.Name            = BrandName;
            cost.Id               = costId;
            costStage.Name        = CostStageName.ToString();
            costOwner.FullName    = CostOwnerFullName;
            costOwner.GdamUserId  = CostOwnerGdamUserId;
            latestRevision.Id     = costStageRevisionId;
            project.Id            = projectId;
            project.Name          = ProjectName;
            project.GdamProjectId = ProjectGdamId;
            project.AdCostNumber  = ProjectNumber;
            country.Name          = AgencyLocation;

            var stageDetails = new PgStageDetailsForm
            {
                ContentType = new core.Builders.DictionaryValue
                {
                    Id  = Guid.NewGuid(),
                    Key = ContentType
                },
                CostType       = cost.CostType.ToString(),
                ProductionType = new core.Builders.DictionaryValue
                {
                    Id  = Guid.NewGuid(),
                    Key = CostProductionType
                },
                Title = CostTitle,
                AgencyTrackingNumber = AgencyTrackingNumber,
                BudgetRegion         = new AbstractTypeValue
                {
                    Key  = budgetRegion,
                    Name = budgetRegion
                }
            };
            var existingUser = EFContext.CostUser.FirstOrDefault(a => a.GdamUserId == CostOwnerGdamUserId);

            if (existingUser == null)
            {
                EFContext.Add(costOwner);
                EFContext.SaveChanges();
            }

            CostStageRevisionServiceMock.Setup(csr => csr.GetStageDetails <PgStageDetailsForm>(costStageRevisionId)).ReturnsAsync(stageDetails);
        }
Exemplo n.º 3
0
        protected async Task <A5Agency> PrepareTestData(params string[] labels)
        {
            var gdamAgencyId = "gdamAgencyId1";
            var a5Agency     = await GetA5Agency();

            a5Agency._id = gdamAgencyId;
            if (labels != null)
            {
                var labelz = a5Agency._cm.Common.Labels.ToList();
                labelz.AddRange(labels);
                a5Agency._cm.Common.Labels = labelz.ToArray();
            }

            var costAgency = new Agency
            {
                Id           = Guid.NewGuid(),
                GdamAgencyId = gdamAgencyId,
                Labels       = a5Agency._cm.Common.Labels
            };
            var countryIso = a5Agency._cm.Common.Address.Country.FirstOrDefault();

            var agencyAbstractType = new AbstractType {
                ObjectId = costAgency.Id
            };
            var defaultCurrecny = new Currency {
                DefaultCurrency = true, Code = "USD"
            };
            var country = new Country {
                Iso = countryIso
            };

            EFContext.AbstractType.Add(agencyAbstractType);
            EFContext.Agency.Add(costAgency);
            EFContext.Currency.Add(defaultCurrecny);
            EFContext.Country.Add(country);
            EFContext.SaveChanges();

            return(a5Agency);
        }
Exemplo n.º 4
0
        public async Task Update_PG_User_Has_Modified_ShouldPersistUpdatedUser()
        {
            //Setup
            var loggedInUserId     = Guid.NewGuid();
            var businessRoleId     = Guid.NewGuid();
            var userId             = Guid.NewGuid();
            var newRoleId          = Guid.NewGuid();
            var accessDetailTypeId = Guid.NewGuid();
            var loggedInUser       = new UserIdentity
            {
                Id = loggedInUserId
            };
            var actioningUser = new CostUser
            {
                Id = loggedInUserId
            };
            CostUser dbUser;
            var      agency = new Agency
            {
                Id     = Guid.NewGuid(),
                Name   = "Test Agency",
                Labels = new[] { "CM_Prime_P&G", "costPG" }
            };
            var abstractTypes = new List <AbstractType>
            {
                new AbstractType
                {
                    Id     = accessDetailTypeId,
                    Type   = Constants.AccessObjectType.Module,
                    Module = new dataAccess.Entity.Module
                    {
                        Id         = Guid.NewGuid(),
                        ClientType = ClientType.Pg,
                        Name       = "Procter & Gamble",
                        ClientTag  = "costPG",
                        Key        = "P&G"
                    }
                }
            };
            var model = Setup(businessRoleId, userId, newRoleId, agency, abstractTypes, accessDetailTypeId, out dbUser);

            _efContext.CostUser.Add(actioningUser);
            _efContext.SaveChanges();
            _permissionServiceMock.Setup(a => a.CheckHasAccess(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(true);

            //Act
            var result = await _userService.Update(loggedInUser, userId, model, BuType.Pg);

            //Assert
            result.Success.Equals(true);
            result.Messages.First().Should().Be("User updated.");

            var verifyUser = _efContext.CostUser.FirstOrDefault(a => a.Id == dbUser.Id);

            verifyUser.UserBusinessRoles.Count.Should().Be(1);
            verifyUser.UserBusinessRoles.First().BusinessRole.RoleId.Should().Be(newRoleId);
            verifyUser.UserBusinessRoles.First().BusinessRole.Id.Should().Be(businessRoleId);

            verifyUser.UserBusinessRoles.First().ObjectId.Should().Be(accessDetailTypeId);

            verifyUser.ApprovalLimit.Should().Be(99999);
        }
Exemplo n.º 5
0
        private UpdateUserModel Setup(Guid businessRoleId, Guid userId, Guid newRoleId, Agency agency, List <AbstractType> abstractTypes, Guid accessTypeId, out CostUser dbUser)
        {
            dbUser = new CostUser
            {
                Id     = userId,
                Agency = agency
            };

            var model = new UpdateUserModel
            {
                AccessDetails = new List <AccessDetail>
                {
                    new AccessDetail
                    {
                        BusinessRoleId = businessRoleId,
                        ObjectType     = Constants.AccessObjectType.Client
                    }
                },
                ApprovalLimit = 99999
            };

            var abstractTypez = abstractTypes.AsQueryable();
            var costUsers = new List <CostUser> {
                dbUser
            }.AsQueryable();
            var agencies = new List <Agency> {
                agency
            }.AsQueryable();
            var businessRoles = new List <BusinessRole>
            {
                new BusinessRole {
                    Id = businessRoleId, Value = "Cost Viewer", Key = "Cost Viewer", RoleId = newRoleId
                },
                new BusinessRole {
                    Key = plugins.Constants.BusinessRole.AdstreamAdmin
                }
            }.AsQueryable();
            var userUserGroups = new List <UserUserGroup>
            {
                new UserUserGroup
                {
                    UserId = Guid.NewGuid()
                }
            }.AsQueryable();

            _efContext.AbstractType.AddRange(abstractTypez);
            _efContext.CostUser.AddRange(costUsers);
            _efContext.Agency.AddRange(agencies);
            _efContext.BusinessRole.AddRange(businessRoles);
            _efContext.UserUserGroup.AddRange(userUserGroups);
            _efContext.SaveChanges();

            _permissionServiceMock.Setup(
                p =>
                p.GrantUserAccess <AbstractType>(It.IsAny <Guid>(), It.IsAny <Guid>(),
                                                 new CostUser {
                Id = userId
            },
                                                 It.IsAny <BuType>(), It.IsAny <Guid?>(), It.IsAny <string>(),
                                                 It.IsAny <bool>()));

            _permissionServiceMock.Setup(p => p.RevokeAccessForSubjectWithRole(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <bool>()))
            .ReturnsAsync(new[] { Guid.NewGuid().ToString() });

            var abstractType = abstractTypes.First();

            _moduleServiceMock.Setup(a => a.GetClientModulePerUserAsync(It.IsAny <CostUser>())).ReturnsAsync(new Module
            {
                Id     = abstractType.Id,
                BuType = (BuType)abstractType.Module.ClientType,
                Key    = abstractType.Module.Key,
                Name   = abstractType.Module.Name
            });

            _mapper.Setup(m => m.Map <CostUserSearchItem>(It.IsAny <CostUser>())).Returns(new CostUserSearchItem());
            _mapper.Setup(m => m.Map <AgencySearchItem>(It.IsAny <AbstractType>())).Returns(new AgencySearchItem());
            _elasticSearchServiceMock.Setup(a => a.UpdateSearchItem(It.IsAny <AgencySearchItem>(), Constants.ElasticSearchIndices.AgencyIndexName)).Returns(Task.CompletedTask);
            _elasticSearchServiceMock.Setup(a => a.UpdateSearchItem(It.IsAny <CostUserSearchItem>(), Constants.ElasticSearchIndices.CostUsersIndexName)).Returns(Task.CompletedTask);
            return(model);
        }
Exemplo n.º 6
0
        private void SetupPurchaseOrderCost(Cost cost, CostStageRevision latestRevision,
                                            CostUser costOwner, Guid previousRevisionId, Guid latestRevisionId, string poNumber)
        {
            const string brandApproverGdamUserId = "57e5461ed9563f268ef4f1ta";
            const string brandApproverName       = "John Smith";
            var          costId      = Guid.NewGuid();
            var          costOwnerId = Guid.NewGuid();
            var          projectId   = Guid.NewGuid();

            var previousStageId = Guid.NewGuid();
            var latestStageId   = Guid.NewGuid();

            var previousRevision        = new CostStageRevision();
            var previousStage           = new CostStage();
            var latestStage             = new CostStage();
            var project                 = new Project();
            var brand                   = new Brand();
            var agency                  = new Agency();
            var country                 = new Country();
            var brandApproval           = new Approval();
            var brandApprover           = new ApprovalMember();
            var brandApproverAsCostUser = new CostUser();

            previousRevision.CostStage = previousStage;
            previousRevision.Id        = previousRevisionId;

            previousStage.Id = previousRevision.CostStageId = previousStageId;
            latestStage.Id   = latestRevision.CostStageId = latestStageId;

            previousStage.Name = CostStages.OriginalEstimate.ToString();
            latestStage.Name   = CostStages.FinalActual.ToString();

            cost.CostStages.AddRange(new[] { previousStage, latestStage });

            //China non-Cyclone Agencies should create a notification for non-backup approver when the cost total amount has changed
            SetupDataSharedAcrossTests(agency, country, cost, latestRevision, project, costOwner, costOwnerId, latestStage,
                                       brand, costId, latestRevisionId, projectId, Constants.BudgetRegion.China);

            brandApproval.ApprovalMembers = new List <ApprovalMember> {
                brandApprover
            };
            brandApprover.CostUser = brandApproverAsCostUser;

            brandApproval.Type = ApprovalType.Brand;
            brandApproverAsCostUser.GdamUserId = brandApproverGdamUserId;
            brandApproverAsCostUser.FullName   = brandApproverName;

            var approvals = new List <Approval> {
                brandApproval
            };

            ApprovalServiceMock.Setup(a => a.GetApprovalsByCostStageRevisionId(It.IsAny <Guid>(), true)).ReturnsAsync(approvals);

            var pgPaymentDetails = new PgPaymentDetails
            {
                PoNumber = poNumber
            };

            CostStageServiceMock.Setup(cssm => cssm.GetPreviousCostStage(latestStageId)).Returns(Task.FromResult(previousStage));
            CostStageRevisionServiceMock.Setup(csrsm => csrsm.GetLatestRevision(previousStageId)).Returns(Task.FromResult(previousRevision));
            CustomObjectDataServiceMock
            .Setup(codsm => codsm.GetCustomData <PgPaymentDetails>(latestRevisionId, CustomObjectDataKeys.PgPaymentDetails))
            .Returns(Task.FromResult(pgPaymentDetails));
            CustomObjectDataServiceMock
            .Setup(codsm => codsm.GetCustomData <PgPaymentDetails>(previousRevisionId, CustomObjectDataKeys.PgPaymentDetails))
            .Returns(Task.FromResult(pgPaymentDetails));
        }
Exemplo n.º 7
0
        public async Task HandleA5EventObject_ProjectCreated_WithA4Brand_field()
        {
            //Setup
            var basePath        = AppContext.BaseDirectory;
            var projectFilePath = $"{basePath}{Path.DirectorySeparatorChar}JsonData{Path.DirectorySeparatorChar}a5_project.json";
            var agencyFilePath  = $"{basePath}{Path.DirectorySeparatorChar}JsonData{Path.DirectorySeparatorChar}a5_agency_a4brandfield.json";
            var a5Project       = await _jsonReader.GetObject <A5Project>(projectFilePath, false);

            _gdamClientMock.Setup(a => a.FindProjectById(a5Project._id)).ReturnsAsync(a5Project);
            _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 = a5Project.CreatedBy._id,
                ParentId   = Guid.NewGuid()
            };
            var agency = new Agency {
                Id = Guid.NewGuid(), GdamAgencyId = a5Project.Agency._id, Labels = new[] { Constants.BusinessUnit.CostModulePrimaryLabelPrefix }
            };
            var brand = new Brand {
                Id = Guid.NewGuid(), Name = "Brand", AdIdPrefix = "prefix", Sector = new Sector {
                    AgencyId = agency.Id
                }
            };

            var a5Agency = await _jsonReader.GetObject <A5Agency>(agencyFilePath, true);

            _gdamClientMock.Setup(a => a.FindAgencyById(agency.GdamAgencyId)).ReturnsAsync(a5Agency);

            var agencies = new List <Agency> {
                agency
            }.AsQueryable();
            var projectsList = new List <Project>().AsQueryable();
            var costUsers = new List <CostUser> {
                costUser
            }.AsQueryable();
            var brands = new List <Brand> {
                brand
            }.AsQueryable();
            var dictionary =
                new Dictionary
            {
                Name = "Campaign",
                DictionaryEntries = new List <DictionaryEntry> {
                    new DictionaryEntry {
                        Id = Guid.NewGuid(), Key = "Key", Value = "Value", Visible = true
                    }
                },
                Id = Guid.NewGuid()
            };

            _moduleServiceMock.Setup(a => a.GetClientModulePerUserAsync(It.IsAny <CostUser>())).ReturnsAsync(new core.Models.AbstractTypes.Module {
                Id = Guid.NewGuid()
            });
            _dictionaryServiceMock.Setup(a => a.GetDictionaryWithEntriesByName(It.IsAny <Guid>(), It.IsAny <string>())).Returns(dictionary);

            _efContextMock.MockAsyncQueryable(projectsList, c => c.Project);
            _efContextMock.MockAsyncQueryable(costUsers, c => c.CostUser);
            _efContextMock.MockAsyncQueryable(brands, c => c.Brand);
            _efContextMock.MockAsyncQueryable(agencies, c => c.Agency);

            //Act
            await _projectService.AddProjectToDb(a5Project);

            //Assert
            _efContextMock.Verify(a => a.Add(It.IsAny <Project>()), Times.Once);
        }
Exemplo n.º 8
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.º 9
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);
        }