//Get the list of all reason registered by the current user public List <Reason> GetAll() { using (var db = new ReasonContext()) { return(db.Reason.Include("Referrals").Where(x => x.UserProfileId.Equals(WebSecurity.CurrentUserId)).ToList()); } }
//Find a reason public Reason Find(int id) { using (var db = new ReasonContext()) { return(db.Reason.Find(id)); } }
//Edit a reason content public void Edit(Reason Model, int id) { Reason editedReason; using (var db = new ReasonContext()) { editedReason = db.Reason.Find(id); db.Entry(editedReason).State = EntityState.Modified; editedReason.Name = Model.Name; editedReason.Description = Model.Description; db.SaveChanges(); } }
public void GetReasonById_WrongId_ReturnsNull() { // Use a clean instance of the context to run the test using (var context = new ReasonContext(_options)) { ReasonRepository reasonRepository = new ReasonRepository(context); //act var reason = reasonRepository .GetReasonById(5, _userId1); //assert Assert.Null(reason); } }
public void GetAllReasons() { // Use a clean instance of the context to run the test using (var context = new ReasonContext(_options)) { ReasonRepository reasonRepository = new ReasonRepository(context); //act var reasons = reasonRepository.GetAllReasons; //assert Assert.Equal(15, reasons.Count()); } }
//create a new reason public void Create(Reason Model) { using (var db = new ReasonContext()) { Reason reason = db.Reason.Create(); reason.Name = Model.Name; reason.Description = Model.Description; reason.UserProfile = db.UserProfile.Find(WebSecurity.CurrentUserId); db.Reason.Add(reason); db.SaveChanges(); } }
public void GetReasonById_WrongUserId_ReturnsNull() { // Use a clean instance of the context to run the test using (var context = new ReasonContext(_options)) { ReasonRepository reasonRepository = new ReasonRepository(context); //act var userId = "487f83a4-7e64-4c7f-9330-197b48549ee3"; var reason = reasonRepository .GetReasonById(1, userId); //assert Assert.Null(reason); } }
public void GetReasonById(int id, string userId, string text) { // Use a clean instance of the context to run the test using (var context = new ReasonContext(_options)) { ReasonRepository reasonRepository = new ReasonRepository(context); //act var reason = reasonRepository .GetReasonById(id, userId); var isTrue = reason.Text.Contains(text); //assert Assert.True(isTrue); Assert.Equal(reason.UserId, userId); } }
public ReasonRepositoryTests() { //arrange _options = new DbContextOptionsBuilder <ReasonContext>() .UseInMemoryDatabase(databaseName: "Reasons").Options; // Insert seed data into the database using one instance of the context using (var context = new ReasonContext(_options)) { foreach (var item in ReasonList.ListOfReasons()) { context.Reason.Add(item); } context.SaveChanges(); } }
public ReasonSeeder(ReasonContext ctx, // IHostingEnvironment hosting, UserManager <IdentityUser> userManager, RoleManager <IdentityRole> roleManager) { _ctx = ctx; _userManager = userManager; _roleManager = roleManager; //_hosting = hosting; }
public ReasonAccessor(ReasonContext reasonContext) { _reasonContext = reasonContext; }