public JsonResult Create(CreateComplexShapeRequestDTO complexShapeDto) { var shapeEngine = _EngineFactory.GetBusinessEngine <IShapeEngine>(); var id = shapeEngine.Create(complexShapeDto); return(Json(id, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Creates an image which contains shape(s) /// </summary> /// <param name="complexShapeDto">Image data. Holds shape data and effects</param> /// <returns>Last record Id</returns> public int Create(CreateComplexShapeRequestDTO complexShapeDto) { if (complexShapeDto != null) { var image = ConvertDTOToComponent(complexShapeDto); JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }; var json = JsonConvert.SerializeObject(image, settings); if (json != null && !string.IsNullOrWhiteSpace(image.Name)) { var repository = _RepositoryFactory.GetRepository <GeoPaint.Entities.ComplexShape>(); var entity = new Entities.ComplexShape(); entity.Name = image.Name; entity.Content = json; repository.Insert(entity); return(entity.Id); } else { throw new ArgumentNullException(); } } else { throw new ArgumentNullException(); } }
public void CreateComplexShape_HappyPathWithoutEffect_NotNull() { int result = 0; var complaxeShape = new CreateComplexShapeRequestDTO() { Name = "Simple Image", Shapes = new System.Collections.Generic.List <CreateShapeRequestDTO>() { new CreateShapeRequestDTO() { Type = "Square", StartPositionX = 1, StartPositionY = 2, Width = 5, } } }; var entity = new Entities.ComplexShape() { Id = 1, Name = complaxeShape.Name, Content = "{\"$type\":\"GeoPaint.Component.ComplexShape, GeoWeb.DTO\",\"Shapes\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.BaseObject, GeoWeb.DTO]], mscorlib\",\"$values\":[{\"$type\":\"GeoPaint.Component.Line, GeoWeb.DTO\",\"EndPositionX\":50,\"EndPositionY\":30,\"Id\":0,\"PositionX\":0,\"PositionY\":0,\"Effects\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.ShapeEffect, GeoWeb.DTO]], mscorlib\",\"$values\":[{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":1,\"Value\":\"5\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":3,\"Value\":\"blue\"}]}},{\"$type\":\"GeoPaint.Component.Square, GeoWeb.DTO\",\"Width\":30,\"Id\":1,\"PositionX\":80,\"PositionY\":80,\"Effects\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.ShapeEffect, GeoWeb.DTO]], mscorlib\",\"$values\":[{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":1,\"Value\":\"2\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":3,\"Value\":\"black\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":2,\"Value\":\"red\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":4,\"Value\":\"false\"}]}},{\"$type\":\"GeoPaint.Component.Circle, GeoWeb.DTO\",\"Radius\":30,\"Id\":2,\"PositionX\":10,\"PositionY\":20,\"Effects\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.ShapeEffect, GeoWeb.DTO]], mscorlib\",\"$values\":[{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":1,\"Value\":\"2\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":3,\"Value\":\"black\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":2,\"Value\":\"yellow\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":4,\"Value\":\"true\"}]}}]},\"Id\":0,\"Name\":\"Tool\",\"Effects\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.ComplexShapeEffect, GeoWeb.DTO]], mscorlib\",\"$values\":[]}}", }; _mockDataRepositoryFactory.GetRepository <Entities.ComplexShape>().Insert(entity); var engine = new ShapeEngine(_mockDataRepositoryFactory, _mockBusinessEngineFactory); result = engine.Create(complaxeShape); Assert.AreEqual(complaxeShape.Name, entity.Name); }
public void UpdateComplexShape_HappyPathWithEffect_NotNull() { int result = 0; var complaxeShape = new CreateComplexShapeRequestDTO() { Name = "Simple Image", Shapes = new System.Collections.Generic.List <CreateShapeRequestDTO>() { new CreateShapeRequestDTO() { Type = "Square", StartPositionX = 80, StartPositionY = 80, Width = 5, Effects = new System.Collections.Generic.List <Component.ShapeEffect>() { new Component.ShapeEffect() { Value = "2", EffectType = VirtualEffectTypes.BorderWidth } } } } }; var entity = new Entities.ComplexShape() { Id = 1, Name = complaxeShape.Name, Content = "{\"$type\":\"GeoPaint.Component.ComplexShape, GeoWeb.DTO\",\"Shapes\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.BaseObject, GeoWeb.DTO]], mscorlib\",\"$values\":[{\"$type\":\"GeoPaint.Component.Line, GeoWeb.DTO\",\"EndPositionX\":50,\"EndPositionY\":30,\"Id\":0,\"PositionX\":0,\"PositionY\":0,\"Effects\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.ShapeEffect, GeoWeb.DTO]], mscorlib\",\"$values\":[{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":1,\"Value\":\"5\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":3,\"Value\":\"blue\"}]}},{\"$type\":\"GeoPaint.Component.Square, GeoWeb.DTO\",\"Width\":30,\"Id\":1,\"PositionX\":80,\"PositionY\":80,\"Effects\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.ShapeEffect, GeoWeb.DTO]], mscorlib\",\"$values\":[{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":1,\"Value\":\"2\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":3,\"Value\":\"black\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":2,\"Value\":\"red\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":4,\"Value\":\"false\"}]}},{\"$type\":\"GeoPaint.Component.Circle, GeoWeb.DTO\",\"Radius\":30,\"Id\":2,\"PositionX\":10,\"PositionY\":20,\"Effects\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.ShapeEffect, GeoWeb.DTO]], mscorlib\",\"$values\":[{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":1,\"Value\":\"2\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":3,\"Value\":\"black\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":2,\"Value\":\"yellow\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":4,\"Value\":\"true\"}]}}]},\"Id\":0,\"Name\":\"Tool\",\"Effects\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.ComplexShapeEffect, GeoWeb.DTO]], mscorlib\",\"$values\":[]}}", }; _mockDataRepositoryFactory.GetRepository <Entities.ComplexShape>().Insert(entity); var engine = new ShapeEngine(_mockDataRepositoryFactory, _mockBusinessEngineFactory); result = engine.Create(complaxeShape); JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }; var deserializedComplexShape = JsonConvert.DeserializeObject <ComplexShape>(entity.Content, settings); Assert.AreEqual(complaxeShape.Name, entity.Name); Assert.AreEqual(complaxeShape.Shapes.First().StartPositionX, deserializedComplexShape.Shapes[1].PositionX); Assert.AreEqual(complaxeShape.Shapes.First().StartPositionY, deserializedComplexShape.Shapes[1].PositionY); Assert.AreEqual(complaxeShape.Shapes.First().Effects.First().EffectType, deserializedComplexShape.Shapes[1].Effects.First().EffectType); Assert.AreEqual(complaxeShape.Shapes.First().Effects.First().Value, deserializedComplexShape.Shapes[1].Effects.First().Value); }
public void CreateComplexShape_Null_ReturnsArgumentNullException() { var complaxeShape = new CreateComplexShapeRequestDTO() { Name = "", Shapes = new System.Collections.Generic.List <CreateShapeRequestDTO>() { new CreateShapeRequestDTO() } }; var engine = new ShapeEngine(_mockDataRepositoryFactory, _mockBusinessEngineFactory); Assert.That(() => engine.Create(complaxeShape), Throws.ArgumentNullException); }
/// <summary> /// Converts image data transfer object to an entity /// </summary> /// <returns>Entity object</returns> private ComplexShape ConvertDTOToComponent(CreateComplexShapeRequestDTO complexShapeDto) { var complexShape = new ComplexShape(); complexShape.Id = complexShapeDto.Id; complexShape.Name = complexShapeDto.Name; if (complexShape.Effects != null) { foreach (var effect in complexShapeDto.Effects) { complexShape.Effects.Add(effect); } } foreach (var shape in complexShapeDto.Shapes) { BaseObject component = null; switch (shape.Type) { case "Square": { component = new Square() { Effects = shape.Effects, PositionX = shape.StartPositionX, PositionY = shape.StartPositionY, Width = shape.Width }; break; } case "Circle": { component = new Circle() { Effects = shape.Effects, PositionX = shape.StartPositionX, PositionY = shape.StartPositionY, Radius = shape.Width }; break; } case "Line": { component = new Line() { Effects = shape.Effects, PositionX = shape.StartPositionX, PositionY = shape.StartPositionY, EndPositionX = shape.EndPositionX, EndPositionY = shape.EndPositionY }; break; } default: break; } if (component != null) { complexShape.AddShape(component); } } return(complexShape); }
public int Create(CreateComplexShapeRequestDTO complexShapeDto) { var shapeEngine = _EngineFactory.GetBusinessEngine <IShapeEngine>(); return(shapeEngine.Create(complexShapeDto)); }