public void TestInitialize() { _mockRepo = Substitute.For <IMacroProfileRepository>(); _mockUow = Substitute.For <IUnitOfWork>(); _mockEventStore = Substitute.For <IEventStore>(); _mockUow.MacroProfiles.Returns(_mockRepo); _handler = new RemoveMacrosFromPackageCommandHandler(_mockUow, _mockEventStore); var packageId = Guid.NewGuid(); _completeMacroDtoCollection = new List <CompleteMacroDto>(); for (var i = 0; i < 5; i++) { var macroDto = new MacroDto(Guid.NewGuid()) { Description = "testDescription" + i, Name = "testName" + i, }; var profileDto = new MacroProfileDto(Guid.NewGuid(), packageId, macroDto.Id) { ComponentName = "testModule" + i, MacroPosition = i, }; var completeMacro = new CompleteMacroDto(macroDto, profileDto); _completeMacroDtoCollection.Add(completeMacro); } _cmd = new RemoveMacrosFromPackageCommand(_completeMacroDtoCollection); }
public MacroDto BuildDto(IMacro entity) { var dto = new MacroDto() { Alias = entity.Alias, CacheByPage = entity.CacheByPage, CachePersonalized = entity.CacheByMember, DontRender = entity.DontRender, Name = entity.Name, Python = entity.ScriptPath, RefreshRate = entity.CacheDuration, ScriptAssembly = entity.ControlAssembly, ScriptType = entity.ControlType, UseInEditor = entity.UseInEditor, Xslt = entity.XsltPath, MacroPropertyDtos = BuildPropertyDtos(entity) }; if (entity.HasIdentity) { dto.Id = int.Parse(entity.Id.ToString(CultureInfo.InvariantCulture)); } return(dto); }
public void CreateMacro_WithInvalidExpression_ExceptionThrown() { var macro = new MacroDto() { Expression = "$unknownMarkup$" }; //Macro with an unknown markup Assert.Throws <InvalidMacroException>(() => this.ComponentUnderTest.Create(macro)); }
private ICommand BuildMenuItemCommand(MacroDto macro) { return(new RelayCommand(() => { var text = this.Component.Resolve(macro, PluginContext.Host.SelectedPatient); //TextEditor.Control.CaretPosition.InsertTextInRun(text); TextEditor.Control.Selection.Text = text; })); }
public void ResolveMacro_WhenMacroIsInvalid_ExceptionThrown() { var macro = new MacroDto() { Expression = "$unknownMarkup$" }; //Macro with an unknown markup var patient = this.HelperComponent.GetAllPatientsLight()[0]; Assert.Throws <InvalidMacroException>(() => this.ComponentUnderTest.Resolve(macro, patient)); }
internal Macro(string alias, string name, IUmbracoDatabaseAdaptor umbracoDatabase) : this(umbracoDatabase) { _macroDto = new MacroDto { Alias = alias, Name = name }; }
private void Create() { try { var macro = new MacroDto() { Title = Messages.Macro_New }; this.Component.Create(macro); this.Macros.Add(macro); } catch (Exception ex) { this.Handle.Error(ex); } }
public IMacro BuildEntity(MacroDto dto) { var model = new Macro(dto.Id, dto.UseInEditor, dto.RefreshRate, dto.Alias, dto.Name, dto.ScriptType, dto.ScriptAssembly, dto.Xslt, dto.CacheByPage, dto.CachePersonalized, dto.DontRender, dto.Python); foreach (var p in dto.MacroPropertyDtos) { model.Properties.Add(new MacroProperty(p.Id, p.Alias, p.Name, p.SortOrder, p.EditorAlias)); } //on initial construction we don't want to have dirty properties tracked // http://issues.umbraco.org/issue/U4-1946 model.ResetDirtyProperties(false); return(model); }
/// <summary> /// Resolves the specified macro with the data of the specified patient. /// </summary> /// <param name="macro">The macro.</param> /// <param name="patient">The patient.</param> /// <returns></returns> public string Resolve(MacroDto macro, LightPatientDto patient) { if (macro == null || patient == null) { return(string.Empty); } var p = this.Session.Get <Patient>(patient.Id); if (p == null) { throw new EntityNotFoundException(typeof(Patient)); } var builder = new MacroBuilder(p); return(builder.Resolve(macro.Expression)); }
/// <summary> /// Updates the specified item. /// </summary> /// <param name="item">The item.</param> public void Update(MacroDto item) { if (item == null) { return; } else if (!MacroBuilder.IsValidExpression(item.Expression)) { throw new InvalidMacroException(); } else { var entity = this.Session.Get <Macro>(item.Id); Mapper.Map <MacroDto, Macro>(item, entity); if (entity != null) { this.Session.Update(entity); } } }
protected override void PersistUpdatedItem(IMacro entity) { entity.UpdatingEntity(); MacroDto dto = MacroFactory.BuildDto(entity); Database.Update(dto); // update the properties if they've changed var macro = (Macro)entity; if (macro.IsPropertyDirty("Properties") || macro.Properties.Values.Any(x => x.IsDirty())) { var ids = dto.MacroPropertyDtos?.Where(x => x.Id > 0).Select(x => x.Id).ToArray(); if (ids?.Length > 0) { Database.Delete <MacroPropertyDto>("WHERE macro=@macro AND id NOT IN (@ids)", new { macro = dto.Id, ids }); } else { Database.Delete <MacroPropertyDto>("WHERE macro=@macro", new { macro = dto.Id }); } // detect new aliases, replace with temp aliases // this ensures that we don't have collisions, ever var aliases = new Dictionary <string, string>(); if (dto.MacroPropertyDtos is null) { return; } foreach (MacroPropertyDto propDto in dto.MacroPropertyDtos) { IMacroProperty?prop = macro.Properties.Values.FirstOrDefault(x => x.Id == propDto.Id); if (prop == null) { throw new Exception("oops: property."); } if (propDto.Id == 0 || prop.IsPropertyDirty("Alias")) { var tempAlias = Guid.NewGuid().ToString("N")[..8];
public static IMacro BuildEntity(MacroDto dto) { var model = new Macro(dto.Id, dto.UniqueId, dto.UseInEditor, dto.RefreshRate, dto.Alias, dto.Name, dto.CacheByPage, dto.CachePersonalized, dto.DontRender, dto.MacroSource, (MacroTypes)dto.MacroType); try { model.DisableChangeTracking(); foreach (var p in dto.MacroPropertyDtos.EmptyNull()) { model.Properties.Add(new MacroProperty(p.Id, p.UniqueId, p.Alias, p.Name, p.SortOrder, p.EditorAlias)); } // reset dirty initial properties (U4-1946) model.ResetDirtyProperties(false); return(model); } finally { model.EnableChangeTracking(); } }
internal MacroDto Map(MacroDto a, MacroPropertyDto p) { // Terminating call. Since we can return null from this function // we need to be ready for PetaPoco to callback later with null // parameters if (a == null) { return(Current); } // Is this the same DictionaryItem as the current one we're processing if (Current != null && Current.Id == a.Id) { // Yes, just add this MacroPropertyDtos to the current item's collection Current.MacroPropertyDtos.Add(p); // Return null to indicate we're not done with this Macro yet return(null); } // This is a different Macro to the current one, or this is the // first time through and we don't have one yet // Save the current Macro var prev = Current; // Setup the new current Macro Current = a; Current.MacroPropertyDtos = new List <MacroPropertyDto>(); //this can be null since we are doing a left join if (p.Alias != null) { Current.MacroPropertyDtos.Add(p); } // Return the now populated previous Macro (or null if first time through) return(prev); }
protected override void PersistNewItem(IMacro entity) { entity.AddingEntity(); MacroDto dto = MacroFactory.BuildDto(entity); var id = Convert.ToInt32(Database.Insert(dto)); entity.Id = id; if (dto.MacroPropertyDtos is not null) { foreach (MacroPropertyDto propDto in dto.MacroPropertyDtos) { // need to set the id explicitly here propDto.Macro = id; var propId = Convert.ToInt32(Database.Insert(propDto)); entity.Properties[propDto.Alias].Id = propId; } } entity.ResetDirtyProperties(); }
public long Create(MacroDto item) { Assert.IsNotNull(item, "item"); if (!MacroBuilder.IsValidExpression(item.Expression)) { throw new InvalidMacroException(); } var exist = (from i in this.Session.Query <MacroDto>() where i.Id == item.Id select i).ToList().Count() > 0; if (exist) { throw new ExistingItemException(); } var entity = Mapper.Map <MacroDto, Macro>(item); item.Id = (long)this.Session.Save(entity); return(item.Id); }
public static MacroDto BuildDto(IMacro entity) { var dto = new MacroDto { UniqueId = entity.Key, Alias = entity.Alias, CacheByPage = entity.CacheByPage, CachePersonalized = entity.CacheByMember, DontRender = entity.DontRender, Name = entity.Name, MacroSource = entity.MacroSource, RefreshRate = entity.CacheDuration, UseInEditor = entity.UseInEditor, MacroPropertyDtos = BuildPropertyDtos(entity), MacroType = 7, // PartialView }; if (entity.HasIdentity) { dto.Id = entity.Id; } return(dto); }
public static MacroDto BuildDto(IMacro entity) { var dto = new MacroDto { UniqueId = entity.Key, Alias = entity.Alias, CacheByPage = entity.CacheByPage, CachePersonalized = entity.CacheByMember, DontRender = entity.DontRender, Name = entity.Name, MacroSource = entity.MacroSource, RefreshRate = entity.CacheDuration, UseInEditor = entity.UseInEditor, MacroPropertyDtos = BuildPropertyDtos(entity), MacroType = (int)entity.MacroType }; if (entity.HasIdentity) { dto.Id = int.Parse(entity.Id.ToString(CultureInfo.InvariantCulture)); } return(dto); }
/// <summary> /// Determines whether the specified macro is valid. /// </summary> /// <param name="macro"></param> /// <returns> /// <c>true</c> if macro is valid; otherwise, <c>false</c>. /// </returns> public bool IsValid(MacroDto macro) { return((macro != null) ? MacroBuilder.IsValidExpression(macro.Expression) : false); }
internal Macro(MacroDto macroDto, IUmbracoDatabaseAdaptor umbracoDatabase) : this(umbracoDatabase) { _macroDto = macroDto; }
public static void SetMacro(DependencyObject target, MacroDto value) { target.SetValue(ProfessionProperty, value); }
/// <summary> /// Creates the specified macro. /// </summary> /// <param name="macro">The macro.</param> /// <returns>The id of the created macro</returns> public long Create(MacroDto macro) { return(new Creator(this.Session).Create(macro)); }
/// <summary> /// Updates the specified macro. /// </summary> /// <param name="macro">The macro.</param> public void Update(MacroDto macro) { new Updator(this.Session).Update(macro); }
public void Remove(MacroDto item) { Assert.IsNotNull(item, "item"); this.Remove <Macro>(item); }
/// <summary> /// Removes the specified item. /// </summary> /// <param name="item">The item.</param> public void Remove(MacroDto item) { new Remover(this.Session).Remove(item); }