protected void SaveWidget_Clicked(object sender, EventArgs e) { try { var control = LoadControl(Field_Url.Value); } catch (Exception x) { Debug.WriteLine(x.ToString()); Services.Get <ILogger>().LogException(x); Error.Text = x.Message; Error.Visible = true; return; } using (Facade facade = new Facade(AppContext.GetContext(Context))) { var widgetId = int.Parse(Field_ID.Value.Trim()); if (widgetId == 0) { var newlyAddedWidget = facade.AddWidget( Field_Name.Value, Field_Url.Value, Field_Icon.Value, Field_Description.Value, Field_DefaultState.Value, Field_IsDefault.Checked, Field_IsLocked.Checked, int.Parse(Field_OrderNo.Value), Field_RoleName.Value, int.Parse(Field_WidgetType.Value)); widgetId = newlyAddedWidget.ID; SetWidgetRoles(widgetId); this.EditWidget(newlyAddedWidget); } else { facade.UpdateWidget(widgetId, Field_Name.Value, Field_Url.Value, Field_Icon.Value, Field_Description.Value, Field_DefaultState.Value, Field_IsDefault.Checked, Field_IsLocked.Checked, int.Parse(Field_OrderNo.Value), Field_RoleName.Value, int.Parse(Field_WidgetType.Value)); SetWidgetRoles(widgetId); } this.LoadWidgets(); EditForm.Visible = false; } }
public void Admin_user_can_delete_a_newly_created_widget() { var facade = default(Facade); var newWidget = default(Widget); var userFacade = default(Facade); var someNewUser = default(UserProfile); var addedWidgetInstance = default(WidgetInstance); "Given admin user and a newly created widget assigned to some roles and users using the widget".Context(() => { facade = new Facade(new AppContext(string.Empty, ADMIN_USER)); newWidget = facade.AddWidget("Test Widget", "omaralzabir.com", string.Empty, "Test widget", string.Empty, false, false, 0, "guest", (int)Enumerations.WidgetType.PersonalTab); facade.AssignWidgetRoles(newWidget.ID, new string[] { GUEST_ROLE }); someNewUser = MembershipHelper.CreateNewAnonUser(); userFacade = new Facade(new AppContext(someNewUser.UserName, someNewUser.UserName)); var userSetup = userFacade.FirstVisitHomeTab(someNewUser.UserName, string.Empty, true, false); addedWidgetInstance = userFacade.AddWidgetInstance(newWidget.ID, 0, 0, 0); Assert.NotNull(addedWidgetInstance); }); "When admin user deletes the widget".Do(() => { facade.DeleteWidget(newWidget.ID); }); "It should delete the widget completely from all users pages".Assert(() => { Assert.False(facade.GetAllWidgets().Exists(w => w.ID == newWidget.ID)); Assert.False(userFacade.GetAllWidgets().Exists(w => w.ID == newWidget.ID)); // OMAR: Turning off as this comes from cache, not from database // Assert.Throws<InvalidOperationException>(() => userFacade.GetWidgetInstanceById(addedWidgetInstance.Id)); }); }