public void AuthenticatedStringProperty() { ProfileBase profile = ProfileBase.Create("foo", true); ResetAppId(profile.Providers["MySqlProfileProvider"] as MySQLProfileProvider); profile["Name"] = "Fred Flintstone"; profile.Save(); SettingsPropertyCollection getProps = new SettingsPropertyCollection(); SettingsProperty getProp1 = new SettingsProperty("Name"); getProp1.PropertyType = typeof(String); getProps.Add(getProp1); MySQLProfileProvider provider = InitProfileProvider(); SettingsContext ctx = new SettingsContext(); ctx.Add("IsAuthenticated", true); ctx.Add("UserName", "foo"); SettingsPropertyValueCollection getValues = provider.GetPropertyValues(ctx, getProps); Assert.AreEqual(1, getValues.Count); SettingsPropertyValue getValue1 = getValues["Name"]; Assert.AreEqual("Fred Flintstone", getValue1.PropertyValue); }
public void AnonymousUserSettingNonAnonymousProperties() { MySQLProfileProvider provider = InitProfileProvider(); SettingsContext ctx = new SettingsContext(); ctx.Add("IsAuthenticated", false); ctx.Add("UserName", "user1"); SettingsPropertyValueCollection values = new SettingsPropertyValueCollection(); SettingsProperty property1 = new SettingsProperty("color"); property1.PropertyType = typeof(string); property1.Attributes["AllowAnonymous"] = false; SettingsPropertyValue value = new SettingsPropertyValue(property1); value.PropertyValue = "blue"; values.Add(value); provider.SetPropertyValues(ctx, values); DataTable dt = FillTable("SELECT * FROM my_aspnet_Applications"); Assert.AreEqual(0, dt.Rows.Count); dt = FillTable("SELECT * FROM my_aspnet_Users"); Assert.AreEqual(0, dt.Rows.Count); dt = FillTable("SELECT * FROM my_aspnet_Profiles"); Assert.AreEqual(0, dt.Rows.Count); }
public void GetAllProfiles() { ProfileBase profile = ProfileBase.Create("foo", true); ResetAppId(profile.Providers["MySqlProfileProvider"] as MySQLProfileProvider); profile["Name"] = "Fred Flintstone"; profile.Save(); SettingsPropertyCollection getProps = new SettingsPropertyCollection(); SettingsProperty getProp1 = new SettingsProperty("Name"); getProp1.PropertyType = typeof(String); getProps.Add(getProp1); MySQLProfileProvider provider = InitProfileProvider(); SettingsContext ctx = new SettingsContext(); ctx.Add("IsAuthenticated", true); ctx.Add("UserName", "foo"); int total; ProfileInfoCollection profiles = provider.GetAllProfiles( ProfileAuthenticationOption.All, 0, 10, out total); Assert.AreEqual(1, total); }
public void AuthenticatedDateTime() { ProfileBase profile = ProfileBase.Create("foo", true); ResetAppId(profile.Providers["MySqlProfileProvider"] as MySQLProfileProvider); DateTime date = DateTime.Now; profile["BirthDate"] = date; profile.Save(); SettingsPropertyCollection getProps = new SettingsPropertyCollection(); SettingsProperty getProp1 = new SettingsProperty("BirthDate"); getProp1.PropertyType = typeof(DateTime); getProp1.SerializeAs = SettingsSerializeAs.Xml; getProps.Add(getProp1); MySQLProfileProvider provider = InitProfileProvider(); SettingsContext ctx = new SettingsContext(); ctx.Add("IsAuthenticated", true); ctx.Add("UserName", "foo"); SettingsPropertyValueCollection getValues = provider.GetPropertyValues(ctx, getProps); Assert.AreEqual(1, getValues.Count); SettingsPropertyValue getValue1 = getValues["BirthDate"]; Assert.AreEqual(date, getValue1.PropertyValue); }
/// <summary> /// We have to manually reset the app id because our profile provider is loaded from /// previous tests but we are destroying our database between tests. This means that /// our provider thinks we have an application in our database when we really don't. /// Doing this will force the provider to generate a new app id. /// Note that this is not really a problem in a normal app that is not destroying /// the database behind the back of the provider. /// </summary> /// <param name="p"></param> private void ResetAppId(MySQLProfileProvider p) { Type t = p.GetType(); FieldInfo fi = t.GetField("applicationId", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.GetField); fi.SetValue(p, -1); }
private MySQLProfileProvider InitProfileProvider() { MySQLProfileProvider p = new MySQLProfileProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); p.Initialize(null, config); return(p); }
/// <summary> /// We have to manually reset the app id because our profile provider is loaded from /// previous tests but we are destroying our database between tests. This means that /// our provider thinks we have an application in our database when we really don't. /// Doing this will force the provider to generate a new app id. /// Note that this is not really a problem in a normal app that is not destroying /// the database behind the back of the provider. /// </summary> /// <param name="p"></param> private void ResetAppId(MySQLProfileProvider p) { Type t = p.GetType(); FieldInfo fi = t.GetField("app", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.GetField); object appObject = fi.GetValue(p); Type appType = appObject.GetType(); PropertyInfo pi = appType.GetProperty("Id"); pi.SetValue(appObject, -1, null); }
public void StringCollectionAsProperty() { ProfileBase profile = ProfileBase.Create("foo", true); ResetAppId(profile.Providers["MySqlProfileProvider"] as MySQLProfileProvider); StringCollection colors = new StringCollection(); colors.Add("red"); colors.Add("green"); colors.Add("blue"); profile["FavoriteColors"] = colors; profile.Save(); DataTable dt = FillTable("SELECT * FROM my_aspnet_Applications"); Assert.AreEqual(1, dt.Rows.Count); dt = FillTable("SELECT * FROM my_aspnet_Users"); Assert.AreEqual(1, dt.Rows.Count); dt = FillTable("SELECT * FROM my_aspnet_Profiles"); Assert.AreEqual(1, dt.Rows.Count); // now retrieve them SettingsPropertyCollection getProps = new SettingsPropertyCollection(); SettingsProperty getProp1 = new SettingsProperty("FavoriteColors"); getProp1.PropertyType = typeof(StringCollection); getProp1.SerializeAs = SettingsSerializeAs.Xml; getProps.Add(getProp1); MySQLProfileProvider provider = InitProfileProvider(); SettingsContext ctx = new SettingsContext(); ctx.Add("IsAuthenticated", true); ctx.Add("UserName", "foo"); SettingsPropertyValueCollection getValues = provider.GetPropertyValues(ctx, getProps); Assert.AreEqual(1, getValues.Count); SettingsPropertyValue getValue1 = getValues["FavoriteColors"]; StringCollection outValue = (StringCollection)getValue1.PropertyValue; Assert.AreEqual(3, outValue.Count); Assert.AreEqual("red", outValue[0]); Assert.AreEqual("green", outValue[1]); Assert.AreEqual("blue", outValue[2]); }
public void SettingValuesCreatesAnAppAndUserId() { MySQLProfileProvider provider = InitProfileProvider(); SettingsContext ctx = new SettingsContext(); ctx.Add("IsAuthenticated", false); ctx.Add("UserName", "user1"); SettingsPropertyValueCollection values = new SettingsPropertyValueCollection(); SettingsProperty property1 = new SettingsProperty("color"); property1.PropertyType = typeof(string); property1.Attributes["AllowAnonymous"] = true; SettingsPropertyValue value = new SettingsPropertyValue(property1); value.PropertyValue = "blue"; values.Add(value); provider.SetPropertyValues(ctx, values); DataTable dt = FillTable("SELECT * FROM my_aspnet_applications"); Assert.True(1 == dt.Rows.Count, "Rows count on table my_aspnet_applications is not 1"); dt = FillTable("SELECT * FROM my_aspnet_users"); Assert.True(1 == dt.Rows.Count, "Rows count on table my_aspnet_users is not 1"); dt = FillTable("SELECT * FROM my_aspnet_profiles"); Assert.True(1 == dt.Rows.Count, "Rows count on table my_aspnet_profiles is not 1"); values["color"].PropertyValue = "green"; provider.SetPropertyValues(ctx, values); dt = FillTable("SELECT * FROM my_aspnet_applications"); Assert.True(1 == dt.Rows.Count, "Rows count on table my_aspnet_applications is not 1 after setting property"); dt = FillTable("SELECT * FROM my_aspnet_users"); Assert.True(1 == dt.Rows.Count, "Rows count on table my_aspnet_users is not 1 after setting property"); dt = FillTable("SELECT * FROM my_aspnet_profiles"); Assert.True(1 == dt.Rows.Count, "Rows count on table my_aspnet_profiles is not 1 after setting property"); }