public double RegisterShape(string id, int typeParam, double width, int idx, string userName) { var shape = _shapeFactory.CreateShape((ShapeTypeEnum)typeParam, width); lock (_shapesCollection) { _shapesCollection.Add( new ShapeDTO() { Id = id, ShapeType = typeParam.ToString(), Width = width.ToString(), Idx = idx }); var shapesCollectionJson = JsonConvert.SerializeObject(_shapesCollection); var storage = new ShapeStorage(); if (!string.IsNullOrEmpty(userName)) { storage.SaveShapesCollection(shapesCollectionJson, userName); } } return(Math.Round(shape.CalculateArea(), 1)); }
public void RemoveShape(string id, string userName) { _shapesCollection.RemoveAll(x => x.Id == id); var shapesCollectionJson = JsonConvert.SerializeObject(_shapesCollection); var storage = new ShapeStorage(); if (!string.IsNullOrEmpty(userName)) { storage.SaveShapesCollection(shapesCollectionJson, userName); } }
public void SaveAndRestore() { // Configure DataDirectory var solutionDir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName; string dataPath = Path.Combine(solutionDir, "WebShapes\\App_Data"); AppDomain.CurrentDomain.SetData("DataDirectory", dataPath); var shapeStorage = new ShapeStorage(); var etalonString = "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."; var key4Storage = "user@contoso"; shapeStorage.SaveShapesCollection(etalonString, key4Storage); var valueFromDb = shapeStorage.QueryShapesCollection(key4Storage).Trim(); Assert.IsTrue(etalonString.Equals(valueFromDb)); }