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);
        }
Example #2
0
        public async Task HandleA5EventObject_ProjectUpdated_BrandHasMultipleSectors_Query()
        {
            //Setup
            string brandName = "Rejoice";
            Guid   agencyId  = Guid.Parse("1c9eb953-f297-43ac-90d4-ecc5f5af5602");

            var brand1 = new Brand
            {
                Name   = brandName,
                Id     = Guid.NewGuid(),
                Sector = new Sector {
                    Name = "Baby", AgencyId = agencyId
                }
            };
            var brand2 = new Brand
            {
                Id     = Guid.NewGuid(),
                Name   = brandName,
                Sector = new Sector {
                    Name = "Family Care", AgencyId = agencyId
                }
            };
            var brand3 = new Brand
            {
                Id     = Guid.NewGuid(),
                Name   = brandName,
                Sector = new Sector {
                    Name = "Feminine", AgencyId = agencyId
                }
            };

            var brands = new List <Brand> {
                brand1, brand2, brand3
            };

            _efContextMemory.Brand.AddRange(brands);
            _efContextMemory.SaveChanges();

            var inputtedBrand = brand2;
            var expectedBrand = brand2;

            //Act
            var brand = _efContextMemory.Brand.FirstOrDefault(x => x.Sector.AgencyId == inputtedBrand.Sector.AgencyId && x.Sector.Name == inputtedBrand.Sector.Name && x.Name == inputtedBrand.Name);

            //Assert
            brand.Name.Should().Be(expectedBrand.Name);
            brand.Sector.Name.Should().Be(expectedBrand.Sector.Name);
            brand.Sector.AgencyId.Should().Be(expectedBrand.Sector.AgencyId);
        }
        private void SetupDataSharedAcrossTests()
        {
            const string     agencyLocation      = "United Kingdom";
            const string     agencyName          = "Saatchi";
            const string     brandName           = "P&G";
            const string     costNumber          = "P101";
            const CostStages costStageName       = CostStages.OriginalEstimate;
            const string     costOwnerGdamUserId = "57e5461ed9563f268ef4f19d";
            const string     costOwnerFullName   = "Mr Cost Owner";
            const string     projectName         = "Pampers";
            const string     projectGdamId       = "57e5461ed9563f268ef4f19c";
            const string     projectNumber       = "PandG01";

            var projectId = Guid.NewGuid();

            _cost = new Cost();
            var costOwner = new CostUser
            {
                UserBusinessRoles = new List <UserBusinessRole>
                {
                    new UserBusinessRole
                    {
                        BusinessRole = new BusinessRole
                        {
                            Key   = Constants.BusinessRole.FinanceManager,
                            Value = Constants.BusinessRole.FinanceManager
                        }
                    }
                }
            };
            var approverUser = new CostUser
            {
                UserBusinessRoles = new List <UserBusinessRole>
                {
                    new UserBusinessRole
                    {
                        BusinessRole = new BusinessRole
                        {
                            Key   = Constants.BusinessRole.Ipm,
                            Value = Constants.BusinessRole.Ipm
                        }
                    }
                }
            };
            var insuranceUser = new CostUser
            {
                UserBusinessRoles = new List <UserBusinessRole>
                {
                    new UserBusinessRole
                    {
                        BusinessRole = new BusinessRole
                        {
                            Key   = Constants.BusinessRole.InsuranceUser,
                            Value = Constants.BusinessRole.InsuranceUser
                        }
                    }
                }
            };

            var latestRevision = new CostStageRevision();
            var costStage      = new CostStage();
            var project        = new Project();
            var brand          = new Brand();
            var agency         = new Agency();
            var country        = new Country();

            agency.Country                = country;
            approverUser.Id               = _approverUserId;
            _cost.CreatedBy               = costOwner;
            _cost.CreatedById             = _costOwnerId;
            _cost.Owner                   = costOwner;
            _cost.OwnerId                 = _costOwnerId;
            _cost.CostNumber              = costNumber;
            _cost.LatestCostStageRevision = latestRevision;
            _cost.Project                 = project;
            costOwner.Agency              = agency;
            costOwner.Id                  = _costOwnerId;
            insuranceUser.Id              = _insuranceUserId;
            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;
            costOwner.Id          = _costOwnerId;
            latestRevision.Id     = _costStageRevisionId;
            project.Id            = projectId;
            project.Name          = projectName;
            project.GdamProjectId = projectGdamId;
            project.AdCostNumber  = projectNumber;
            country.Name          = agencyLocation;

            var agencies = new List <Agency> {
                agency
            };
            var brands = new List <Brand> {
                brand
            };
            var costs = new List <Cost> {
                _cost
            };
            var costStages = new List <CostStageRevision> {
                latestRevision
            };
            var costUsers = new List <CostUser> {
                approverUser, costOwner, insuranceUser
            };
            var countries = new List <Country> {
                country
            };
            var projects = new List <Project> {
                project
            };

            _efContextMock.MockAsyncQueryable(agencies.AsQueryable(), c => c.Agency);
            _efContextMock.MockAsyncQueryable(brands.AsQueryable(), c => c.Brand);
            _efContextMock.MockAsyncQueryable(costs.AsQueryable(), c => c.Cost);
            _efContextMock.MockAsyncQueryable(costStages.AsQueryable(), c => c.CostStageRevision);
            _efContextMock.MockAsyncQueryable(costUsers.AsQueryable(), c => c.CostUser);
            _efContextMock.MockAsyncQueryable(countries.AsQueryable(), c => c.Country);
            _efContextMock.MockAsyncQueryable(projects.AsQueryable(), c => c.Project);

            _efContextMock.MockAsyncQueryable(new List <NotificationSubscriber>
            {
                new NotificationSubscriber
                {
                    CostId     = _cost.Id,
                    CostUserId = _costOwnerId,
                    CostUser   = costOwner
                }
            }.AsQueryable(), a => a.NotificationSubscriber);

            _stageDetails = new PgStageDetailsForm
            {
                Title        = "Test Title",
                BudgetRegion = new AbstractTypeValue
                {
                    Name = Constants.BudgetRegion.AsiaPacific
                },
                ContentType = new core.Builders.DictionaryValue
                {
                    Value = Constants.ContentType.Audio
                },
                ProductionType = new core.Builders.DictionaryValue
                {
                    Value = Constants.ProductionType.PostProductionOnly
                }
            };
            _costStageRevisionServiceMock.Setup(c => c.GetStageDetails <PgStageDetailsForm>(_cost.LatestCostStageRevision)).Returns(_stageDetails);
        }
Example #4
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));
        }
Example #5
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);
        }
Example #6
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);
        }
Example #7
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);
        }