public async Task CorrectJsonShouldBePassedToS3PutObjectForScalableBitmapImageElement() { const int TemplateCode = 100; const Language Language = Language.Ru; const Anchor Anchor = Anchor.Top; var constraints = new ScalableBitmapImageElementConstraints { SupportedFileFormats = new List <FileFormat> { FileFormat.Png }, ImageSizeRange = new ImageSizeRange { Min = ImageSize.Empty, Max = new ImageSize { Width = 500, Height = 500 } } }; var templateDescriptor = new TemplateDescriptor { Id = TemplateId, VersionId = TemplateVersionId, Properties = new JObject(), Elements = new[] { new ElementDescriptor( ElementDescriptorType.ScalableBitmapImage, TemplateCode, new JObject(), new ConstraintSet(new[] { new ConstraintSetItem(Language, constraints) })) } }; _objectsStorageReaderMock.Setup(m => m.IsObjectExists(It.IsAny <long>())) .ReturnsAsync(() => false); _templatesStorageReaderMock.Setup(m => m.GetTemplateDescriptor(It.IsAny <long>(), It.IsAny <string>())) .ReturnsAsync(() => templateDescriptor); _objectsStorageReaderMock.Setup(m => m.GetObjectLatestVersion(It.IsAny <long>())) .ReturnsAsync(new VersionedObjectDescriptor <long>(ObjectId, ObjectVersionId, DateTime.UtcNow)); var response = new GetObjectMetadataResponse(); var metadataWrapper = MetadataCollectionWrapper.For(response.Metadata); metadataWrapper.Write(MetadataElement.ExpiresAt, DateTime.UtcNow.AddDays(1)); _cephS3ClientMock.Setup(m => m.GetObjectMetadataAsync(It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(() => response); var memoryStream = new MemoryStream(); using (var stream = File.OpenRead(Path.Combine("images", "64x48.png"))) { await stream.CopyToAsync(memoryStream); memoryStream.Position = 0; } var fileKey = Guid.NewGuid().AsS3ObjectKey("key.raw"); var getObjectResponse = new GetObjectResponse { ResponseStream = memoryStream }; metadataWrapper = MetadataCollectionWrapper.For(getObjectResponse.Metadata); metadataWrapper.Write(MetadataElement.Filename, "file name.png"); _cephS3ClientMock.Setup(m => m.GetObjectAsync(It.IsAny <string>(), fileKey, It.IsAny <CancellationToken>())) .ReturnsAsync(getObjectResponse); var objectDescriptor = new ObjectDescriptor { Language = Language, TemplateId = TemplateId, TemplateVersionId = TemplateVersionId, Properties = new JObject(), Elements = new[] { new ObjectElementDescriptor { Type = ElementDescriptorType.ScalableBitmapImage, TemplateCode = TemplateCode, Constraints = new ConstraintSet(new[] { new ConstraintSetItem(Language, constraints) }), Value = new ScalableBitmapImageElementValue { Raw = fileKey, Anchor = Anchor } } } }; await _objectsManagementService.Create(ObjectId, AuthorInfo, objectDescriptor); Assert.True(await _inMemoryContext.Objects.AnyAsync()); var element = await _inMemoryContext.ObjectElements.FirstOrDefaultAsync(); Assert.NotNull(element); var elementJson = JObject.Parse(element.Data); var valueJson = elementJson["value"]; Assert.Equal(valueJson["raw"], fileKey); Assert.NotNull(valueJson["filename"]); Assert.NotNull(valueJson["filesize"]); Assert.Equal(valueJson["anchor"], Anchor.ToString().ToLower()); }
public async Task S3PutObjectShouldNotBeCalledWhileCreation() { const int TemplateCode = 100; const Language Language = Language.Ru; var plainTextConstraints = new PlainTextElementConstraints { MaxSymbols = 100 }; var templateDescriptor = new TemplateDescriptor { Id = TemplateId, VersionId = TemplateVersionId, Properties = new JObject(), Elements = new[] { new ElementDescriptor( ElementDescriptorType.PlainText, TemplateCode, new JObject(), new ConstraintSet(new[] { new ConstraintSetItem(Language, plainTextConstraints) })) } }; _objectsStorageReaderMock.Setup(m => m.IsObjectExists(It.IsAny <long>())) .ReturnsAsync(() => false); _templatesStorageReaderMock.Setup(m => m.GetTemplateDescriptor(It.IsAny <long>(), It.IsAny <string>())) .ReturnsAsync(() => templateDescriptor); _objectsStorageReaderMock.Setup(m => m.GetObjectLatestVersion(It.IsAny <long>())) .ReturnsAsync(new VersionedObjectDescriptor <long>(ObjectId, ObjectVersionId, DateTime.UtcNow)); var objectDescriptor = new ObjectDescriptor { Language = Language, TemplateId = TemplateId, TemplateVersionId = TemplateVersionId, Properties = new JObject(), Elements = new[] { new ObjectElementDescriptor { Type = ElementDescriptorType.PlainText, TemplateCode = TemplateCode, Constraints = new ConstraintSet(new[] { new ConstraintSetItem(Language, plainTextConstraints) }), Value = new TextElementValue { Raw = "Text" } } } }; Assert.False(await _inMemoryContext.Objects.AnyAsync()); await _objectsManagementService.Create(ObjectId, AuthorInfo, objectDescriptor); Assert.True(await _inMemoryContext.Objects.AnyAsync()); }
public async Task CorrectJsonShouldBePassedToS3PutObjectForTextElement() { const int TemplateCode = 100; const Language Language = Language.Ru; var plainTextConstraints = new PlainTextElementConstraints { MaxSymbols = 100 }; var templateDescriptor = new TemplateDescriptor { Id = TemplateId, VersionId = TemplateVersionId, Properties = new JObject(), Elements = new[] { new ElementDescriptor( ElementDescriptorType.PlainText, TemplateCode, new JObject(), new ConstraintSet(new[] { new ConstraintSetItem(Language, plainTextConstraints) })) } }; _objectsStorageReaderMock.Setup(m => m.IsObjectExists(It.IsAny <long>())) .ReturnsAsync(() => false); _templatesStorageReaderMock.Setup(m => m.GetTemplateDescriptor(It.IsAny <long>(), It.IsAny <string>())) .ReturnsAsync(() => templateDescriptor); _objectsStorageReaderMock.Setup(m => m.GetObjectLatestVersion(It.IsAny <long>())) .ReturnsAsync(new VersionedObjectDescriptor <long>(ObjectId, ObjectVersionId, DateTime.UtcNow)); var objectDescriptor = new ObjectDescriptor { Language = Language, TemplateId = TemplateId, TemplateVersionId = TemplateVersionId, Properties = new JObject(), Elements = new[] { new ObjectElementDescriptor { Type = ElementDescriptorType.PlainText, TemplateCode = TemplateCode, Constraints = new ConstraintSet(new[] { new ConstraintSetItem(Language, plainTextConstraints) }), Value = new TextElementValue { Raw = "Text" } } } }; await _objectsManagementService.Create(ObjectId, AuthorInfo, objectDescriptor); Assert.True(await _inMemoryContext.Objects.AnyAsync()); var element = await _inMemoryContext.ObjectElements.FirstOrDefaultAsync(); Assert.NotNull(element); var elementJson = JObject.Parse(element.Data); Assert.Equal("Text", elementJson["value"]["raw"]); }
public ResolvedManifestResourceTemplate(TemplateDescriptor descriptor) { TemplateDescriptor = descriptor; }