public ServiceResult <ProductionDetailsFormDefinitionModel> GetCostSection(CostTemplateVersionModel templateModel, string contentType, string production) { if (templateModel == null) { throw new ArgumentNullException(nameof(templateModel)); } if (templateModel.ProductionDetails == null) { throw new ArgumentNullException(nameof(templateModel.ProductionDetails)); } if (production == "Contract") { // TODO: Why the cost_template contain duplicate versions of the same Usage/Buyout form for Video, Audio and so on?? return(new ServiceResult <ProductionDetailsFormDefinitionModel>(templateModel.ProductionDetails.First().Forms[0])); } if (string.IsNullOrEmpty(contentType)) { return(ServiceResult <ProductionDetailsFormDefinitionModel> .CreateFailedResult("ContentType is empty")); } foreach (var pd in templateModel.ProductionDetails) { if (string.Compare(pd.Type, contentType, StringComparison.OrdinalIgnoreCase) == 0) { foreach (var pdf in pd.Forms) { if (string.Compare(pdf.ProductionType, production, StringComparison.OrdinalIgnoreCase) == 0) { return(new ServiceResult <ProductionDetailsFormDefinitionModel>(pdf)); } if (production == Constants.Miscellaneous.NotApplicable && string.Compare(pdf.ProductionType, Constants.ProductionType.FullProduction, StringComparison.OrdinalIgnoreCase) == 0) { return(new ServiceResult <ProductionDetailsFormDefinitionModel>(pdf)); } } } } string error = $"Production form not found for Content Type '{contentType}' and Production '{production}'"; return(ServiceResult <ProductionDetailsFormDefinitionModel> .CreateFailedResult(error)); }
public void Empty_ContentType_Return_Failure() { //Arrange var templateModel = new CostTemplateVersionModel { ProductionDetails = new List <ProductionDetailsTemplateModel>() }; var contentType = string.Empty; const string production = Constants.ProductionType.FullProduction; var target = new CostSectionFinder(); //Act var result = target.GetCostSection(templateModel, contentType, production); //Assert result.Should().NotBeNull(); result.Success.Should().BeFalse(); }
[TestCase("{\"smoId\": \"cec14a6d-168b-463f-8a8f-32d0c0b4b15c\", \"title\": \"Q4 Tide Dupes\", \"isAIPE\": false, \"smoName\": \"UNITED STATES GROUP\", \"campaign\": \"N/A\", \"costType\": \"Trafficking\", \"projectId\": \"5ac389a3b9fc666ccf84f139\", \"description\": \"dupe materials fourth qtr, Tide\", \"budgetRegion\": {\"id\": \"af2fb04a-f1c0-49c9-903b-f4b70f3a8d41\", \"key\": \"NORTHERN AMERICA AREA\", \"name\": \"North America\"}, \"organisation\": {\"id\": \"ab55bbc4-81cc-4930-a909-47605a928a2e\", \"key\": \"SMO\", \"value\": \"SMO\", \"created\": \"2018-02-14T15:47:15.13419\", \"visible\": true, \"modified\": \"2018-02-14T15:47:15.134189\", \"projects\": null, \"createdById\": \"77681eb0-fc0d-44cf-83a0-36d51851e9ae\", \"dictionaryId\": \"c81e485e-10ab-423f-9597-0959430d3be6\"}, \"approvalStage\": \"OriginalEstimate\", \"initialBudget\": 5000, \"agencyCurrency\": \"USD\", \"agencyProducer\": [\"Amy Salzman (Saatchi & Saatchi)\"], \"airInsertionDate\": \"2018-04-01T04:00:00Z\", \"IsCurrencyChanged\": false, \"agencyTrackingNumber\": \"B119B-000070-00\"}", true)] /* Correct data of SPB-2094 */ public async Task IsValidateFormDetailData_StageDetails(string jsonData, bool expected) { //Cost Production - missing stage details var costId = Guid.NewGuid(); var cost = new Cost { Id = costId, CostType = dataAccess.Entity.CostType.Production, LatestCostStageRevision = new CostStageRevision { StageDetails = new CustomFormData { Id = Guid.NewGuid(), Data = "{\"smoId\": \"747e9209-d22f-423c-9309-7d075edbeed5\", \"title\": \"Power of Softness Superheroes - 20'' Cut Down\", \"isAIPE\": false, \"smoName\": \"CENTRAL EUROPE\", \"campaign\": \"Power of Softness\", \"costType\": \"Production\", \"projectId\": \"5bb346adb9fc665cfaf3676a\", \"costNumber\": \"PRO0003756V0001\", \"contentType\": {\"id\": \"d64450c1-8a27-4b31-bb5f-1f9240597be9\", \"key\": \"Video\", \"value\": \"Video\", \"created\": \"2018-02-14T15:47:15.121647\", \"visible\": true, \"modified\": \"2018-02-14T15:47:15.121646\", \"projects\": null, \"createdById\": \"77681eb0-fc0d-44cf-83a0-36d51851e9ae\", \"dictionaryId\": \"f2a40aba-5066-4a8b-b87a-7e830224dd0f\"}, \"description\": \"Power of Softness Superheroes - 20'' Cut Down from Original 30'' Film\", \"budgetRegion\": {\"id\": \"57eac257-a217-4660-be7f-53cca79f68f4\", \"key\": \"EUROPE AREA\", \"name\": \"Europe\"}, \"organisation\": {\"id\": \"ab55bbc4-81cc-4930-a909-47605a928a2e\", \"key\": \"SMO\", \"value\": \"SMO\", \"created\": \"2018-02-14T15:47:15.13419\", \"visible\": true, \"modified\": \"2018-02-14T15:47:15.134189\", \"projects\": null, \"createdById\": \"77681eb0-fc0d-44cf-83a0-36d51851e9ae\", \"dictionaryId\": \"c81e485e-10ab-423f-9597-0959430d3be6\"}, \"initialBudget\": 8000, \"agencyCurrency\": \"GBP\", \"agencyProducer\": [\"Savannah King\"], \"productionType\": {\"id\": \"a6134764-c8a7-42ba-acb6-5cbbb82d7477\", \"key\": \"Post Production Only\", \"value\": \"Post Production Only\"}, \"IsCurrencyChanged\": false, \"agencyTrackingNumber\": \"TBC\"}" } }, CostTemplateVersionId = _costTemplateVersionId }; _efContextMock.MockAsyncQueryable(new[] { cost }.AsQueryable(), d => d.Cost) .Setup(c => c.FindAsync(It.IsAny <Guid>())) .ReturnsAsync(cost); var costModel = new CostTemplateVersionModel { Cost = new CostTemplateModel { } }; costModel.Cost.Fields = JsonConvert.DeserializeObject <List <FormFieldDefintionModel> >(_productionTemplate); _costTemplateVersionServiceMock.Setup(c => c.GetCostTemplateVersionModel(It.IsAny <Guid>())) .ReturnsAsync(costModel); // Act var isValid = await _costTemplateService.IsValidateFormDetailData(costId, JObject.Parse(jsonData).ToObject <Dictionary <string, dynamic> >()); // Assert isValid.Should().Be(expected); }
public void Null_Template_Throws_Argument_Error() { //Arrange CostTemplateVersionModel templateModel = null; var contentType = Constants.ContentType.Audio; var production = Constants.ProductionType.FullProduction; var target = new CostSectionFinder(); //Act try { target.GetCostSection(templateModel, contentType, production); } catch (ArgumentNullException) { return; } //Assert Assert.Fail(); }
public static CostTemplateVersionModel CreateTemplateModel() { var productionDetailsCollection = new List <ProductionDetailsTemplateModel>(); var templateModel = new CostTemplateVersionModel { ProductionDetails = productionDetailsCollection }; var audioProduction = new ProductionDetailsFormDefinitionModel { ProductionType = Constants.ProductionType.FullProduction }; var audioForms = new List <ProductionDetailsFormDefinitionModel> { audioProduction }; var audio = new ProductionDetailsTemplateModel { Forms = audioForms, Type = Constants.ContentType.Audio }; var digitalProduction = new ProductionDetailsFormDefinitionModel { ProductionType = Constants.ProductionType.FullProduction }; var digitalForms = new List <ProductionDetailsFormDefinitionModel> { digitalProduction }; var digital = new ProductionDetailsTemplateModel { Forms = digitalForms, Type = Constants.ContentType.Digital }; var photographyProduction = new ProductionDetailsFormDefinitionModel { ProductionType = Constants.ProductionType.FullProduction }; var photographyForms = new List <ProductionDetailsFormDefinitionModel> { photographyProduction }; var photography = new ProductionDetailsTemplateModel { Forms = photographyForms, Type = Constants.ContentType.Photography }; var videoProduction = new ProductionDetailsFormDefinitionModel { ProductionType = Constants.ProductionType.FullProduction }; var videoPostProduction = new ProductionDetailsFormDefinitionModel { ProductionType = Constants.ProductionType.PostProductionOnly }; var videoCgi = new ProductionDetailsFormDefinitionModel { ProductionType = Constants.ProductionType.CgiAnimation }; var videoForms = new List <ProductionDetailsFormDefinitionModel> { videoProduction, videoPostProduction, videoCgi }; var video = new ProductionDetailsTemplateModel { Forms = videoForms, Type = Constants.ContentType.Video }; productionDetailsCollection.AddRange(new[] { audio, digital, photography, video }); return(templateModel); }
public void Setup() { _target = new CostLineItemUpdater(_efContextMock.Object, _revisionServiceMock.Object, _templateServiceMock.Object, new CostSectionFinder(), _costExchangeRateServiceMock.Object); var cost = new Cost(); var costStageRevision = new CostStageRevision() { CostLineItems = new List <CostLineItem> { new CostLineItem { } } }; var costTemplateVersion = new CostTemplateVersion(); var costTemplate = new CostTemplate(); var fieldDefinitions = new CustomFormData(); var usd = new Currency(); var euro = new Currency(); var gbp = new Currency(); cost.Id = _costId; costStageRevision.Id = _costStageRevisionId; cost.LatestCostStageRevision = costStageRevision; cost.LatestCostStageRevisionId = _costStageRevisionId; cost.CostTemplateVersion = costTemplateVersion; cost.CostTemplateVersionId = _costTemplateVersionId; costTemplateVersion.CostTemplate = costTemplate; costTemplateVersion.Id = _costTemplateVersionId; costTemplate.FieldDefinitions = fieldDefinitions; euro.Code = "EUR"; usd.Code = "USD"; gbp.Code = "GBP"; euro.Id = Guid.NewGuid(); usd.Id = _usdCurrencyId; gbp.Id = _gbpCurrencyId; var costs = new List <Cost> { cost }; _costStageRevisions = new List <CostStageRevision> { costStageRevision }; var currencies = new List <Currency> { euro, usd, gbp }; _efContextMock.MockAsyncQueryable(costs.AsQueryable(), c => c.Cost); _efContextMock.MockAsyncQueryable(_costStageRevisions.AsQueryable(), c => c.CostStageRevision); _efContextMock.MockAsyncQueryable(currencies.AsQueryable(), c => c.Currency); var stageDetails = new PgStageDetailsForm { ContentType = new core.Builders.DictionaryValue { Id = Guid.NewGuid(), Key = "Video", Value = "Video" }, CostType = dataAccess.Entity.CostType.Production.ToString(), ProductionType = new core.Builders.DictionaryValue { Id = Guid.NewGuid(), Key = "Full Production", Value = "Full Production" }, Title = "Cost Title" }; _revisionServiceMock.Setup(csr => csr.GetStageDetails <PgStageDetailsForm>(_costStageRevisionId)).ReturnsAsync(stageDetails); var costTemplateVersionModel = new CostTemplateVersionModel(); var productionDetailCollection = new List <ProductionDetailsTemplateModel>(); var productionDetails = new ProductionDetailsTemplateModel(); _form = new ProductionDetailsFormDefinitionModel { Name = FormName, Label = "Full production", ProductionType = Constants.ProductionType.FullProduction }; var section = new CostLineItemSectionTemplateModel(); var item = new CostLineItemSectionTemplateItemModel(); section.Name = SectionName; item.Name = ItemName; section.Items = new List <CostLineItemSectionTemplateItemModel> { item }; _form.CostLineItemSections = new List <CostLineItemSectionTemplateModel> { section }; productionDetails.Forms = new List <ProductionDetailsFormDefinitionModel> { _form }; productionDetails.Type = "Video"; productionDetailCollection.Add(productionDetails); costTemplateVersionModel.ProductionDetails = productionDetailCollection; _templateServiceMock.Setup(ts => ts.GetCostTemplateVersionModel(It.IsAny <Guid>())).ReturnsAsync(costTemplateVersionModel); _userIdentity = new UserIdentity { Id = _userId, IpAddress = "127.0.0.1" }; var expectedExchangeRates = new List <ExchangeRate>() { new ExchangeRate { FromCurrency = _usdCurrencyId, Rate = 1 }, }; _costExchangeRateServiceMock.Setup(cer => cer.GetExchangeRatesByDefaultCurrency(It.IsAny <Guid>())) .ReturnsAsync(expectedExchangeRates); }