本文整理汇总了C#中User.Save方法的典型用法代码示例。如果您正苦于以下问题:C# User.Save方法的具体用法?C# User.Save怎么用?C# User.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类User
的用法示例。
在下文中一共展示了User.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifySavingParentParentObjectPreservesDeepestChildren
public void VerifySavingParentParentObjectPreservesDeepestChildren()
{
SetUp();
User user = new User();
user.Username = "thomas";
Role role = new Role();
role.Name = "admin";
user.Roles.Add(role);
user.Save();
user = User.SelectFirst();
Assert.AreEqual(1, user.Roles.Count);
Assert.AreEqual("admin", user.Roles[0].Name);
Article a = new Article();
a.Header = "sdfihsdf";
a.Body = "sdfiojhsdf";
a.Followers.Add(user);
a.Author = user;
a.Save();
user = User.SelectFirst();
Assert.AreEqual(1, user.Roles.Count);
Assert.AreEqual("admin", user.Roles[0].Name);
}
示例2: CanFindUserByUsername
public void CanFindUserByUsername()
{
var user = new User {Username = "pyavari"};
user.Save();
Assert.IsNotNull(User.FindByUsername("pyavari"));
}
示例3: AddClaimAsync
public void AddClaimAsync()
{
User TempUser = new User() { UserName = "TestUser", PasswordHash = Guid.NewGuid().ToString().Hash() };
TempUser.Save();
Store.AddClaimAsync(TempUser, new Claim(ClaimTypes.AuthenticationMethod, "Windows")).Wait();
Assert.Equal(1, TempUser.Claims.Count);
Assert.Equal("Windows", TempUser.Claims[0].Value);
Assert.Equal(ClaimTypes.AuthenticationMethod, TempUser.Claims[0].Type);
Assert.Throws<ArgumentNullException>(() => Store.AddClaimAsync(null, new Claim(ClaimTypes.AuthenticationMethod, "Windows")).Wait());
Assert.Throws<ArgumentNullException>(() => Store.AddClaimAsync(TempUser, null).Wait());
}
示例4: AddLoginAsync
public void AddLoginAsync()
{
User TempUser = new User() { UserName = "TestUser", PasswordHash = Guid.NewGuid().ToString().Hash() };
TempUser.Save();
Store.AddLoginAsync(TempUser, new Microsoft.AspNet.Identity.UserLoginInfo("Something", "A Key")).Wait();
Assert.Equal(1, TempUser.ExternalLogins.Count);
Assert.Equal("Something", TempUser.ExternalLogins[0].LoginProvider);
Assert.Equal("A Key", TempUser.ExternalLogins[0].ProviderKey);
Assert.Throws<ArgumentNullException>(() => Store.AddLoginAsync(TempUser, null).Wait());
Assert.Throws<ArgumentNullException>(() => Store.AddLoginAsync(null, new Microsoft.AspNet.Identity.UserLoginInfo("Something", "A Key")).Wait());
}
示例5: GenerateFirstTimeUsers
public static void GenerateFirstTimeUsers()
{
string[] names = new string[] {"Lucy", "Karu", "Andy", "Suarez", "Nia"
, "Hasebe", "UserA", "UserB", "UserC", "Sai"};
foreach(string name in names)
{
User u = new User(name);
u.Save();
}
}
示例6: VerifyTwoSimilarUsernameThrows
public void VerifyTwoSimilarUsernameThrows()
{
SetUp();
User user = new User();
user.Username = "thomas";
user.Save();
User user2 = new User();
user2.Username = "thomas";
user2.Save();
}
示例7: CanFindDocumentsByUser
public void CanFindDocumentsByUser()
{
var user = new User
{
Documents = new List<Document> {new Document {Text = "This is an interesting docuemnt."}},
Favourites = new List<Favourite>()
};
user.Save();
ResetScope();
user = User.Find(user.Id);
Assert.AreEqual(1, user.Documents.Count);
}
示例8: UpdateBalanceTest
public void UpdateBalanceTest()
{
var userRepo = new UserRepo();
var user = new User();
userRepo.Save(user);
user.UpdateBalance(40, "Salary ;(");
user.Save();
var loaded = userRepo.GetAll().Single(u => u.Id == user.Id).WithBallanceLog();
Assert.AreEqual(40, loaded.Balance, "Balance not loaded.");
Assert.AreEqual(1, loaded.BallanceLog.Count(), "Log is incorrect.");
Assert.AreEqual(40, loaded.BallanceLog.First().Amount, "Amount is incorrect.");
Assert.AreEqual("Salary ;(", loaded.BallanceLog.First().Comment, "Comment is incorrect");
}
示例9: Can_save_and_read_User
public void Can_save_and_read_User()
{
var stefan = new User
{
Email = "[email protected]",
Name = "Stefan",
Password = "Super compilcated password!",
About = "Stefan is a very cool."
};
stefan.Save();
var users = User.Queryable
.Where(u => u.Name.StartsWith("S"))
.ToList();
Assert.NotEmpty(users);
Assert.Equal("Stefan", users.Single().Name);
}
示例10: ISecurityComplex
public static ISecurityComplex ISecurityComplex(this IFaker faker) {
var securityComplex = Isolate.Fake.Instance<ISecurityComplex>();
Isolate.WhenCalled(() => SecuritySystem.Instance).WillReturn(securityComplex);
Isolate.WhenCalled(() => securityComplex.RoleType).WillReturn(typeof (Role));
Isolate.WhenCalled(() => securityComplex.UserType).WillReturn(typeof (User));
Isolate.Fake.StaticMethods(typeof (SecuritySystem));
Isolate.WhenCalled(() => SecuritySystem.UserType).WillReturn(typeof (User));
var user = new User(Session.DefaultSession);
user.Save();
Isolate.WhenCalled(() => SecuritySystem.CurrentUser).WillReturn(user);
XafTypesInfo.Instance.RegisterEntity(securityComplex.RoleType);
XafTypesInfo.Instance.RegisterEntity(securityComplex.UserType);
return securityComplex;
}
示例11: PopulateDefaultData
private static void PopulateDefaultData()
{
using(new SessionScope())
{
User[] users = ActiveRecordBase<User>.FindAll();
if (users.Length != 0) return;
var defaultUser = new User
{
FirstName = "Andy",
LastName = "Pike",
Email = "[email protected]",
PasswordSalt = "a5cdbd8d-b160-4249-b726-034d16f4c762",
PasswordHash = "2F884D20EBE8F4F8CA1BB79DAE1250F5"
};
defaultUser.Save();
}
}
示例12: GenerateData
public void GenerateData()
{
User u=new User(){Username = "admin",Password = "admin"};
u.Save();
//generate 100 users
for(int i=0;i<100;i++)
{
Client c=new Client(){Name = "client "+i,Network = "Orange",Phone = "0745961116"};
c.Save();
}
ModemSettings modemSettings = new ModemSettings()
{
Port = "COM1",
BitPerSec = 115200,
DataBits = 8,
Parity =Parity.None,
StopBits =StopBits.One,
FlowControl = "NONE"
};
modemSettings.Save();
var clients = Client.FindAll();
for(int i=0;i<5;i++)
{
for(int j=0;j<6;j++)
{
var date = DateTime.Now.AddDays(j);
SmsHistory h = new SmsHistory()
{
// Client = clients[i],
Date = date.ToString(),
Message = "Mesajul Nr " + j,
Status = "Send ok",
ClientName = clients[i].Name,
ClientPhone = clients[i].Phone
};
h.Save();
}
}
}
示例13: CanAddFavourite
public void CanAddFavourite()
{
var user = new User
{
Documents = new List<Document> {new Document {Text = "Favourite"}},
Favourites = new List<Favourite>()
};
user.Save();
using (new SessionScope())
{
User.Find(user.Id).AddFavourite(1);
}
using (new SessionScope(FlushAction.Never))
{
Assert.AreEqual(1, User.Find(user.Id).Favourites.Count);
Assert.AreEqual(1, Favourite.FindAll().Count());
}
}
示例14: CanFindAuthor
public void CanFindAuthor()
{
var user = new User
{
Email = "[email protected]",
Username = "pyavari",
Documents = new List<Document>
{
new Document
{
Text = "This is a document!"
}
}
};
user.Save();
ResetScope();
var document = Document.Find(user.Documents.First().Id);
Assert.AreEqual("pyavari", document.Author.Username);
}
示例15: Run
public override void Run()
{
Console.Write("Creating admin user group and user... ");
using (Context context = ContextManager.Instance.CreateContext(ConnectionMode.AutoOpen, TransactionMode.AutoCommit))
{
var f = new EntityFactory(context);
var c = f.LoadEntity<Cluster>(clusterName);
var u = new User(c)
{
Name = adminUsername,
Email = adminEmail,
DeploymentState = Registry.DeploymentState.Deployed,
};
u.SetPassword(adminPassword);
u.Save();
// TODO: create admin group membership
}
Console.WriteLine("done.");
}