Пример #1
0
 //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());
     }
 }
Пример #2
0
 //Find a reason
 public Reason Find(int id)
 {
     using (var db = new ReasonContext())
     {
         return(db.Reason.Find(id));
     }
 }
Пример #3
0
        //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();
            }
        }
Пример #4
0
 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);
     }
 }
Пример #5
0
        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());
            }
        }
Пример #6
0
        //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();
            }
        }
Пример #7
0
 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);
     }
 }
Пример #8
0
 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);
     }
 }
Пример #9
0
        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();
            }
        }
Пример #10
0
 public ReasonSeeder(ReasonContext ctx, // IHostingEnvironment hosting,
                     UserManager <IdentityUser> userManager, RoleManager <IdentityRole> roleManager)
 {
     _ctx = ctx; _userManager = userManager; _roleManager = roleManager; //_hosting = hosting;
 }
Пример #11
0
 public ReasonAccessor(ReasonContext reasonContext)
 {
     _reasonContext = reasonContext;
 }