本文整理汇总了C#中UserRepository.Add方法的典型用法代码示例。如果您正苦于以下问题:C# UserRepository.Add方法的具体用法?C# UserRepository.Add怎么用?C# UserRepository.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserRepository
的用法示例。
在下文中一共展示了UserRepository.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestGet_InitializeValidUsers_PasswordsShouldMatch
public void TestGet_InitializeValidUsers_PasswordsShouldMatch()
{
// Arrange
var roomsRepo = new UserRepository();
roomsRepo.Add(new User("username1", "password123", Roles.User));
roomsRepo.Add(new User("username2", "password1234", Roles.VenueAdmin));
roomsRepo.Add(new User("username3", "password123", Roles.User));
// Act
var user = roomsRepo.Get(2);
// Assert
Assert.AreEqual(HashUtilities.GetSha256Hash("password1234"), user.PasswordHash, "Passwords don't match.");
}
示例2: TestGet_InitializeValidUsers_UsernamesShouldMatch
public void TestGet_InitializeValidUsers_UsernamesShouldMatch()
{
// Arrange
var roomsRepo = new UserRepository();
roomsRepo.Add(new User("username1", "password123", Roles.User));
roomsRepo.Add(new User("username2", "password123", Roles.VenueAdmin));
roomsRepo.Add(new User("username3", "password123", Roles.User));
// Act
var user = roomsRepo.Get(2);
// Assert
Assert.AreEqual("username2", user.Username, "Usernames don't match.");
}
示例3: TestGet_InitializeValidUsers_UserShouldNotBeNull
public void TestGet_InitializeValidUsers_UserShouldNotBeNull()
{
// Arrange
var roomsRepo = new UserRepository();
roomsRepo.Add(new User("username1", "password123", Roles.User));
roomsRepo.Add(new User("username2", "password123", Roles.VenueAdmin));
roomsRepo.Add(new User("username3", "password123", Roles.User));
// Act
var user = roomsRepo.Get(2);
// Assert
Assert.IsNotNull(user, "User should not be null.");
}
示例4: UserRepository
public void UserRepository()
{
IUserRepository userRepository = new UserRepository(new EntityFrameworkRepositoryContext());
User user1 = new User { Name = "小菜" };
User user2 = new User { Name = "大神" };
userRepository.Add(user1);
userRepository.Add(user2);
userRepository.Context.Commit();
//var user = URepository.GetUserByName("小菜");
//if (user != null)
//{
// Console.WriteLine(user.Name);
//}
}
示例5: InsertUserCheckUnique
public void InsertUserCheckUnique()
{
var unitOfWork = new UnitOfWork<GenericRepositoryTestContext>();
var user = new User
{
Email = "[email protected]",
Name = "Wim Pool"
};
var userRepo = new UserRepository(unitOfWork);
userRepo.Add(user);
try
{
userRepo.SaveChanges();
}
catch (DbEntityValidationException validationException)
{
foreach (var error in validationException.EntityValidationErrors)
{
Assert.IsTrue(error.ValidationErrors.Count == 1);
Assert.AreEqual(error.ValidationErrors.First().ErrorMessage, "NotUnique");
Assert.AreEqual(error.ValidationErrors.First().PropertyName, "Email");
}
}
var users = userRepo.FindBy(u => u.Email == "[email protected]");
Assert.IsTrue(users.Count() == 1);
}
示例6: AddUser
public void AddUser()
{
using (CapriconContext context = new CapriconContext())
{
var newUser = new User()
{
FirstName = "james",
LastName = "kamau",
OtherName = "",
Gender = Gender.Female,
MobilePhone = "0756 123 456",
Email = "[email protected]",
Town = "Nairobi",
District = "Nairobi",
DateOfBirth = DateTime.Now.AddYears(-40),
};
var userRep = new UserRepository(context);
userRep.Add(newUser);
try
{
context.SaveChanges();
}
catch (DbEntityValidationException ex)
{
//Retrieve validation errors
ex.EntityValidationErrors.ToList().ForEach
(
v =>
{
v.ValidationErrors.ToList().ForEach
(
e =>
{
System.Diagnostics.Debug.WriteLine(e.ErrorMessage);
}
);
}
);
Assert.Fail("Test failed");
}
//retrieve saved object
var context1 = new CapriconContext();
var repository = new UserRepository(context1);
var savedUsers = repository.GetAll().ToList();
Assert.AreEqual(savedUsers.Count(), 1, "returns 20 records");
var savedUsersList = savedUsers;
savedUsersList.ForEach
(
s =>
{
Debug.WriteLine(s.UserId +" - "+ s.FirstName +" "+ s.LastName);
}
);
};
}
示例7: TestAdd
public void TestAdd()
{
try
{
var userEntiry = new UserEntity()
{
Password = "viczhang",
CreatedAt = DateTime.UtcNow,
UserName = "Vic",
Emails = new List<string>()
{
"[email protected]",
"[email protected]"
},
Options = new Dictionary<string, string>()
{
{"city", "Zhuhai"},
{"language", "cn"}
}
};
var userRepo = new UserRepository();
var task = userRepo.Add(userEntiry);
task.Wait();
Assert.IsNotNull(userEntiry.Id);
Assert.IsFalse(string.IsNullOrWhiteSpace(task.Result));
}
catch (Exception e)
{
Assert.Fail(e.Message);
}
}
示例8: Base_Inheritance_Save
public void Base_Inheritance_Save()
{
var repository = new UserRepository();
var user = new User {Name = "Base_Inheritance_Save"};
repository.Add(user);
repository._collectionName.Should().Be("User");
}
示例9: User_Add_ShouldSuccess
public void User_Add_ShouldSuccess()
{
//
// TODO: 在此处添加测试逻辑
//
User user = new User();
user.Username = "zhangsan";
IUserRepository r = new UserRepository();
r.Add(user);
}
示例10: addUser
public bool addUser(User user)
{
if (user != null)
{
UserRepository repository = new UserRepository();
repository.Add(user);
return true;
}
return false;
}
示例11: CanAddUser
public void CanAddUser()
{
var repo = new UserRepository();
var user = new User
{
Username = "matthew.kimber",
Password = "password",
EmailAddress = "[email protected]",
FirstName = "Matthew",
MiddleName = "Scott",
LastName = "Kimber",
PhoneNumber = "222-1234567",
IsActive = true,
LicenseNumber = "ABCDEFG123",
StaffType = StaffType.Physician,
Address = new Address
{
Street1 = "939 E. 490 N.",
Street2 = "Apt. 1B",
City = "Ogden",
Region = "Utah",
//Country = "USA",
IsActive = true
},
DateCreated = DateTime.Now,
IsApproved = true
};
repo.Add(user);
UnitOfWork.CurrentSession.Flush();
UnitOfWork.CurrentSession.Clear();
var retrievedUser = repo.Get("matthew.kimber");
Assert.AreEqual(user.Username, retrievedUser.Username);
}
示例12: FillDb
public static void FillDb()
{
using (var context = new BankDbContext())
{
Console.WriteLine("ConnectionString\n" + context.Database.Connection.ConnectionString);
Console.WriteLine("DataSource\n" + context.Database.Connection.DataSource);
Console.WriteLine("ConnectionString\n" + context.Database.Connection.Database);
// CLEARS ALL DATA !!!
Console.WriteLine("ALL DATA WILL BE DELETED FROM DB NOW!!! ([ENTER] TO PROCEED)");
Console.ReadLine();
//if (!context.Database.Exists())
//{
context.Database.Delete();
context.Database.Create();
//}
context.Database.Initialize(true);//
Console.WriteLine("Db initialized");
Console.ReadLine();
context.Accounts.RemoveRange(context.Accounts);
///Console.WriteLine("I've successfully completed first db action!");
///Console.ReadLine();
context.Clients.RemoveRange(context.Clients);
context.Credits.RemoveRange(context.Credits);
context.CreditTypes.RemoveRange(context.CreditTypes);
context.Payments.RemoveRange(context.Payments);
context.Requests.RemoveRange(context.Requests);
//context.RequestStatuses.RemoveRange(context.RequestStatuses);
context.Users.RemoveRange(context.Users);
context.SaveChanges();
// CLEARS ALL DATA !!!
//var statusRepo = new RequestStatusRepository(context);
//var statusCreated = new RequestStatus { Status = "Created" };
//var statusConfirmedByOperator = new RequestStatus { Status = "statusConfirmedByOperator" };
//var statusConfirmedBySse = new RequestStatus { Status = "statusConfirmedBySecurityServiceEmployee" };
////var statusConfirmed = new RequestStatus { Status = "ConfirmedBy" };
//var statusCreditProvided = new RequestStatus { Status = "statusCreditProvided" };
//var statusDenied = new RequestStatus { Status = "Denied" };
//statusRepo.Add(statusCreated, statusConfirmedByOperator, statusConfirmedByOperator, statusCreditProvided,statusDenied);
// context.SaveChanges();
// var confirmedByOperatorStatusId = statusCreditProvided.RequestStatusId;
// var createdStatusId = statusCreated.RequestStatusId;
// var deinedStatusId = statusDenied.RequestStatusId;
var creditShort = new CreditType
{
Name = "Easy Money",
//Type = "" WTF IS TYPE?????
TimeMonths = 12,
PercentPerYear = 20.0m,
Currency = "USD",
FinePercent = 40.0m,
MinAmount = 200,
MaxAmount = 2000,
IsAvailable = true
};
var creditMedium = new CreditType
{
Name = "Not So Easy Money",
//Type = "" WTF IS TYPE?????
TimeMonths = 12 * 2,
PercentPerYear = 25.0m,
Currency = "USD",
FinePercent = 50.0m,
MinAmount = 200,
MaxAmount = 5000,
IsAvailable = true
};
var creditLong = new CreditType
{
Name = "Still Money",
//Type = "" WTF IS TYPE?????
TimeMonths = 12 * 4,
PercentPerYear = 30.0m,
Currency = "USD",
FinePercent = 60.0m,
MinAmount = 200,
MaxAmount = 5000,
IsAvailable = true
};
var creditTypeRepo = new CreditTypeRepository(context);
creditTypeRepo.Add(creditShort, creditLong, creditMedium);
context.SaveChanges();
var creditEasyId = creditShort.CreditTypeId;
var creditMediumId = creditMedium.CreditTypeId;
var creditLongId = creditLong.CreditTypeId;
var admin = new User { Login = "admin", Password = "admin", Role = UserRole.Admin, IsActive = true };
var ss = new User // security service employee
{ Login = "security", Password = "security", Role = UserRole.SecurityServiceEmployee, IsActive = true };
var operator1 = new User //
{ Login = "operator1", Password = "operator1", Role = UserRole.Operator, IsActive = true };
var operator2 = new User //
//.........这里部分代码省略.........
示例13: Add_User
public void Add_User(object s, EventArgs e)
{
Utility Util = new Utility();
if (Page.IsValid)
{
UserRepository User = new UserRepository();
User.UserName = Util.FormatTextForInput(Request.Form[Username.UniqueID]);
User.Password = Encryption.Encrypt(Util.FormatTextForInput(Request.Form[Password1.UniqueID]));
User.Email1 = Util.FormatTextForInput(Request.Form[Email.UniqueID]);
User.FirstName = Util.FormatTextForInput(Request.Form[Firstname.UniqueID]);
User.LastName = Util.FormatTextForInput(Request.Form[Lastname.UniqueID]);
User.SetSex = Request.Form[RadioButtonSex.UniqueID];
User.CityID = 1;
User.StateID = 8;
User.CountryID = 18;
/*User.CityID = Int16.Parse(Request.Form[City.UniqueID]);
User.StateID = Int16.Parse(Request.Form[State.UniqueID]);
User.CountryID = Int16.Parse(Request.Form[Cntry.UniqueID]);*/
User.DOB = DateTime.Parse(Date1.CalendarDateString);
if (Int32.Parse(Request.Form[Newsletter.UniqueID]) == 1)
{
User.canEmailSend = true;
}
else
User.canEmailSend = false;
User.ECPreference = "";
for (int i = 0; i < ExamCategoryList.Items.Count; i++)
{
if (ExamCategoryList.Items[i].Selected)
{
if (User.ECPreference.Length > 0)
User.ECPreference += ",";
User.ECPreference += ExamCategoryList.Items[i].Value;
}
}
User.Mobile = Util.FormatTextForInput(Request.Form[Mobile.UniqueID]);
User.Address = Util.FormatTextForInput(Request.Form[Address.UniqueID]);
//User.ContactMe = Int32.Parse(Util.FormatTextForInput(Request.Form[ContactMe.UniqueID]));
User.Website = Util.FormatTextForInput(Request.Form[Website.UniqueID]);
User.AboutMe = Util.FormatTextForInput(Request.Form[AboutMe.UniqueID]);
//User.GUID = Guid.NewGuid().ToString("N");
//Prevent username and email duplication. Ensure that all username and email in the database are unique.
//This initialize the value.
UserNameAndEmailValidation.Param(User.UserName, User.Email1);
#region Form Input Validation
//Handles validation of username and email. This prevent duplication.
if (!UserNameAndEmailValidation.IsValid)
{
lbvalenght.Text = UserNameAndEmailValidation.ErrMsg;
lbvalenght.Visible = true;
txtsecfield.Text = "";
return;
}
if (!Validator.IsValidUserName(User.UserName))
{
lbvalenght.Text = "<br>Error: Username must be at least 6 characters long and 15 characters maximun, and should only contain AlphaNumeric.";
lbvalenght.Visible = true;
txtsecfield.Text = "";
return;
}
//Let's decrypt the password for validation.
if (!Validator.IsValidPassword(Encryption.Decrypt(User.Password)))
{
lbvalenght.Text = "<br>Error: Password must be at least 6 characters long and 12 characters maximun, and should only contain AlphaNumeric.";
lbvalenght.Visible = true;
txtsecfield.Text = "";
return;
}
//Let's decrypt the password for validation.
if (Util.FormatTextForInput(Request.Form[Password1.UniqueID]) != Util.FormatTextForInput(Request.Form[Password2.UniqueID]))
{
lbvalenght.Text = "<br>Error: Password did not matach. Please re-enter a password and make sure they both match.";
lbvalenght.Visible = true;
txtsecfield.Text = "";
return;
}
if (!Validator.IsValidEmail(User.Email1))
{
lbvalenght.Text = "<br>Error: Invalid email address. Email address must be a valid format.";
lbvalenght.Visible = true;
txtsecfield.Text = "";
return;
}
if (!Validator.IsValidName(User.FirstName))
{
lbvalenght.Text = "<br>Error: Firstname should be alphabet and not contain illegal characters.";
lbvalenght.Visible = true;
txtsecfield.Text = "";
return;
//.........这里部分代码省略.........
示例14: PerformInitialSetup
private static void PerformInitialSetup(IDocumentSession session)
{
IUserService userService = new UserService(session);
if (!userService.DoesUserExistWithUsername("robashton"))
{
User newUser = new User("robashton", "password");
IUserRepository userRepository = new UserRepository(session);
userRepository.Add(newUser);
}
session.SaveChanges();
}
示例15: TestGet_InvalidPositiveId_ShouldReturnNull
public void TestGet_InvalidPositiveId_ShouldReturnNull()
{
// Arrange
var roomsRepo = new UserRepository();
roomsRepo.Add(new User("username1", "password123", Roles.User));
roomsRepo.Add(new User("username2", "password123", Roles.VenueAdmin));
roomsRepo.Add(new User("username3", "password123", Roles.User));
// Act
var user = roomsRepo.Get(4);
// Assert
Assert.IsNull(user);
}