private static void CreateUser(LearningSystemContext context, UserManager <ApplicationUser> manager, string username, string email, string password, string secondRole, string thirdRole, string name) { var user = new ApplicationUser { UserName = username, Email = email }; manager.Create(user, password); manager.AddToRole(user.Id, "Student"); if (secondRole != null) { manager.AddToRole(user.Id, secondRole); } if (thirdRole != null) { manager.AddToRole(user.Id, thirdRole); } Student student = new Student() { BirthDate = new DateTime(1995, 07, 15), Name = name, UserId = user.Id }; context.Students.Add(student); context.SaveChanges(); }
private static void AddRoles(LearningSystemContext context) { if (!context.Roles.Any(x => x.Name == "Student")) { var roleManager = new RoleManager <IdentityRole>( new RoleStore <IdentityRole>(context)); roleManager.Create(new IdentityRole("Student")); } if (!context.Roles.Any(x => x.Name == "Trainer")) { var roleManager = new RoleManager <IdentityRole>( new RoleStore <IdentityRole>(context)); roleManager.Create(new IdentityRole("Trainer")); } if (!context.Roles.Any(x => x.Name == "BlogAuthor")) { var roleManager = new RoleManager <IdentityRole>( new RoleStore <IdentityRole>(context)); roleManager.Create(new IdentityRole("BlogAuthor")); } if (!context.Roles.Any(x => x.Name == "Administrator")) { var roleManager = new RoleManager <IdentityRole>( new RoleStore <IdentityRole>(context)); roleManager.Create(new IdentityRole("Administrator")); } }
private static void AddUsers(LearningSystemContext context) { if (!context.Users.Any()) { var store = new UserStore <ApplicationUser>(context); var manager = new UserManager <ApplicationUser>(store); CreateUser(context, manager, "FirstUser", "*****@*****.**", "Aa!1234", "Administrator", "Trainer", "Matthew"); CreateUser(context, manager, "SecondUser", "*****@*****.**", "Aa!1234", "Trainer", null, "TheBest"); CreateUser(context, manager, "ThirdUser", "*****@*****.**", "Aa!1234", "BlogAuthor", null, "Mario"); } }
private static void AddCourses(LearningSystemContext context) { if (!context.Courses.Any()) { context.Courses.AddOrUpdate(course => course.Name, new Course[] { new Course() { Name = "Programing Basics - March 2016", Description = "This course gives you basic knowledge of C# programming language.", StartDate = new DateTime(2016, 03, 23), EndDate = new DateTime(2016, 04, 30), Trainer = context.Students.Find(1).User }, new Course() { Name = "C# Advanced", Description = "This is a course in Advanced C#", StartDate = new DateTime(2017, 03, 23), EndDate = new DateTime(2017, 04, 30), Trainer = context.Students.Find(2).User }, new Course() { Name = "C# OOP Basics", Description = "This course will teach you to the basic principles of Object-Oriented Programming.", StartDate = new DateTime(2016, 03, 23), EndDate = new DateTime(2016, 04, 30), Trainer = context.Students.Find(1).User }, new Course() { Name = "C# OOP Advanced", Description = "In this course you will get to know the principles of High Quality Code", StartDate = new DateTime(2017, 03, 23), EndDate = new DateTime(2017, 04, 30), Trainer = context.Students.Find(2).User } }); } context.SaveChanges(); }
public CourseInstancesServiceTest() { this.mapper = AutoMapperMock.GetMapper(); this.courseInstancesRepositoryMock = new Mock <IRepository <LearningSystemContext, CourseInstance> >(); this.context = LearningSystemContextMock.GetContext(); }
protected override void Seed(LearningSystemContext context) { var roleStore = new RoleStore <IdentityRole>(context); var roleManager = new RoleManager <IdentityRole>(roleStore); foreach (var roleName in Constants.Roles) { if (!roleManager.Roles.Any(r => r.Name == roleName)) { var role = new IdentityRole(roleName); roleManager.Create(role); } } var userStore = new UserStore <ApplicationUser>(context); var userManager = new UserManager <ApplicationUser>(userStore); var user = new ApplicationUser { CUsername = "******", Email = "*****@*****.**", UserName = "******" }; if (!userManager.Users.Any(u => u.Email == user.Email && u.UserName == user.UserName)) { var result = userManager.Create(user, "Administrator123#"); if (!result.Succeeded) { throw new Exception("Could not create administrator account"); } } var adminId = userManager.Users.FirstOrDefault(u => u.Email == user.Email && u.UserName == user.UserName).Id; if (!userManager.IsInRole(adminId, "Administrator")) { userManager.AddToRole(adminId, "Administrator"); } if (!userManager.IsInRole(adminId, "BlogAuthor")) { userManager.AddToRole(adminId, "BlogAuthor"); } if (!userManager.IsInRole(adminId, "Trainer")) { userManager.AddToRole(adminId, "Trainer"); } if (!userManager.IsInRole(adminId, "Student")) { userManager.AddToRole(adminId, "Student"); } if (!context.Students.Any(i => i.Id == adminId)) { context.Students.Add(new Student() { Id = adminId }); context.SaveChanges(); } context.Courses.Add(new Course() { Name = "Probaaa1", Description = "Description1", StartDate = DateTime.Now.AddDays(5), EndDate = DateTime.Now.AddDays(15) }); context.Courses.Add(new Course() { Name = "Probaaa2", Description = "Description1", StartDate = DateTime.Now.AddDays(5), EndDate = DateTime.Now.AddDays(15) }); context.Courses.Add(new Course() { Name = "Probaaa3", Description = "Description1", StartDate = DateTime.Now.AddDays(5), EndDate = DateTime.Now.AddDays(15) }); context.Courses.Add(new Course() { Name = "Probaaa4", Description = "Description1", StartDate = DateTime.Now.AddDays(5), EndDate = DateTime.Now.AddDays(15) }); }
public BlogArticleServiceTest() { this.blogRepositoryMock = new Mock <IRepository <LearningSystemContext, Article> >(); this.context = LearningSystemContextMock.GetContext(); this.mapper = AutoMapperMock.GetMapper(); }
protected Service() { this.context = new LearningSystemContext(); this.userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(this.Context)); }
public void TestInitialize() { this.courseRepositoryMock = new Mock <IRepository <LearningSystemContext, Course> >(); this.context = LearningSystemContextMock.GetContext(); this.mapper = AutoMapperMock.GetMapper(); }
protected Repository() { this.context = new LearningSystemContext(); }