/// <summary> /// Imitation of work through the UI /// </summary> /// <param name="context"></param> /// <param name="timeEntry"></param> private void PreOperationAndThenCreate(XrmFakedContext context, Entity timeEntry) { var plugin = new TimeEntryUniqueDatePlugin(); context.ExecutePluginWithTarget(plugin, timeEntry, "Create", 20); context.GetOrganizationService().Create(timeEntry); }
public void DataDublicationIsNotAllowedTest() { XrmFakedContext context = new XrmFakedContext(); var plugin = new TimeEntryUniqueDatePlugin(); Guid resourseId = Guid.NewGuid(); DateTime startDate = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc); TimeSpan duration = TimeSpan.FromDays(1); context.Initialize(new List <Entity> { EntityFactory.CreateTimeEntry(startDate, TimeSpan.FromHours(2), resourseId), EntityFactory.CreateTimeEntry(startDate.AddDays(1), TimeSpan.FromHours(2), resourseId) }); var timeEntry = EntityFactory.CreateTimeEntry(startDate, duration, resourseId); Assert.ThrowsException <InvalidPluginExecutionException>(() => context.ExecutePluginWithTarget(plugin, timeEntry, "Create", 20), "Duplicates creation is canceled"); }