private async Task <IEnumerable <MergeTemplate> > GetLegacyMergeTemplates(string spreadsheetId, CancellationToken cancellationToken = default(CancellationToken)) { var returnValue = new List <MergeTemplate>(); foreach (var row in await _sheetsService.GetValuesAsync(spreadsheetId, range: string.Concat("mm-config!", MM_CONFIG_ENTIRE_SHEET_RANGE))) { if (row.Count == 0) { _logger.Warning("Row {RowNumber} had no data, not contributing to returned merge templates", returnValue.Count + 1); } else if (row.Count == 1) { _logger.Warning("Row {RowNumber} had only 1 cell, not contributing to returned merge templates", returnValue.Count + 1); } else if (row[1] == null) { _logger.Warning("Row {RowNumber} did not contain a value in the second cell, not contributing to returned merge templates", returnValue.Count + 1); } else { returnValue.Add(MergeTemplate.CreateFrom(row[0].ToString(), spreadsheetId, row[1].ToString())); } } return(returnValue); }
public void CreateMergeTemplateFromSerializedDataWithBadHeaderRowNumber() { dynamic templateJsonObject = JObject.Parse(Mocks.SAMPLE_MM_JSON); templateJsonObject.mergeData.headerRow = "NotANumber"; string templateJson = templateJsonObject.ToString(); var template = MergeTemplate.CreateFrom("Id1", "SheetId", templateJson); template.HeaderRowNumber.Should().Be(1); }
public void CreateMergeTempalteFromSerializedDataWithInvalidTypeThrows() { dynamic templateJsonObject = JObject.Parse(Mocks.SAMPLE_MM_JSON); templateJsonObject.mergeData.type = "badType"; string templateJson = templateJsonObject.ToString(); Action action = () => MergeTemplate.CreateFrom("Id1", "SheetId", templateJson); action.Should().Throw <InvalidOperationException>(); }
public void CreateMergeTemplateFromSerializedData(bool timeStampShouldPrefixNameWithMergeTemplateTitle) { dynamic templateJsonObject = JObject.Parse(Mocks.SAMPLE_MM_JSON); // set "usetitle" as per the timeStampShouldPrefixNameWithMergeTemplateTitle parameter templateJsonObject.mergeData.usetitle = timeStampShouldPrefixNameWithMergeTemplateTitle ? "true" : "false"; string templateJson = templateJsonObject.ToString(); var template = MergeTemplate.CreateFrom("Id1", "SheetId", templateJson); ValidateTemplateFromJson(template, templateJson); template.SpreadSheetId.Should().Be("SheetId"); }
public void CreateMergeTemplateFromSerializedDataWithWithoutCreatedDate() { dynamic templateJsonObject = JObject.Parse(Mocks.SAMPLE_MM_JSON); templateJsonObject.createdDatetime = null; string templateJson = templateJsonObject.ToString(); DateTime utcMin = DateTime.UtcNow; var template = MergeTemplate.CreateFrom("Id1", "SheetId", templateJson); DateTime utcMax = DateTime.UtcNow; template.CreatedDateUtc.Should().BeOnOrAfter(utcMin).And.BeOnOrBefore(utcMax); }
public void CreateMergeTemplateFromSerializedDataWithoutUser() { var template = MergeTemplate.CreateFrom("Id1", "SheetId", Mocks.SAMPLE_MM_JSON); template.Should().NotBeNull(); template.CreatedBy.Should().Be("Unknown user"); dynamic templateJsonObject = JObject.Parse(Mocks.SAMPLE_MM_JSON); templateJsonObject.createdBy = null; string templateJson = templateJsonObject.ToString(); template = MergeTemplate.CreateFrom("Id1", "SheetId", templateJson); template.Should().NotBeNull(); template.CreatedBy.Should().Be("Unknown user"); }