Esempio n. 1
0
 public IHttpActionResult Get(int id)
 {
     using (var context = new DataContext())
     {
         BugRepository  bugRepository = new BugRepository(context);
         var            bug           = bugRepository.Find(id);
         UserRepository userRepo      = new UserRepository(context);
         bug.CreatedBy = userRepo.Find(CurrentUserId);
         var models = MapperHelper.Map <BugApi>(bug);
         return(Ok(models));
     }
 }
Esempio n. 2
0
 public IHttpActionResult Get(int id)
 {
     using (var context = new DataContext())
     {
         BugRepository  bugRepository  = new BugRepository(context);
         var            bugs           = bugRepository.Find(id);
         UserRepository userRepository = new UserRepository(context);
         bugs.createdby = userRepository.Find(bugs.createdByid);
         if (bugs.modifiedById != null)
         {
             bugs.modifiedBy = userRepository.Find(bugs.modifiedById);
         }
         var models = MapperHelp.Map <BugApi>(bugs);
         return(Ok(models));
     }
 }
Esempio n. 3
0
        // GET: api/Bug/5
        public IHttpActionResult Get(int id)
        {
            using (var ctx = new DataContext())
            {
                BugRepository  bugRepository  = new BugRepository(ctx);
                var            bug            = bugRepository.Find(id);
                UserRepository userRepository = new UserRepository(ctx);
                bug.CreatedBy = userRepository.Find(bug.CreatedById);
                if (bug.ModfiedById != null)
                {
                    bug.ModifiedBy = userRepository.Find(bug.ModfiedById);
                }

                var model = MapperHelper.Map <BugApi>(bug);
                return(Ok(model));
            }
        }
Esempio n. 4
0
        public void AddBugWithoutBothDescriptionAndLogDateShouldThrowsValidationException()
        {
            // Arrange -> Prepare the objects
            var bug = new Bug();

            // Act -> Test the objects
            var bugRepository = new BugRepository(new BugLoggerDbContext());

            bugRepository.Add(bug);
            bugRepository.SaveChanges();

            // Assert -> Validate the result
            var bugFromDb = bugRepository.Find(bug.BugId);

            Assert.IsNotNull(bugFromDb);
            Assert.AreEqual(bug.Description, bugFromDb.Description);
        }
        public void AddBugShouldBeAddedToDatabaseAndShouldBeReturnedFromRepository()
        {
            // Arrange -> Prepare the objects
            var bug = new Bug()
            {
                Description = "bug-1",
                LogDate = DateTime.Now
            };
   
            // Act -> Test the objects
            var bugRepository = new BugRepository(new BugLoggerDbContext());
            bugRepository.Add(bug);
            bugRepository.SaveChanges();

            // Assert -> Validate the result
            var bugFromDb = bugRepository.Find(bug.BugId);

            Assert.IsNotNull(bugFromDb);
            Assert.AreEqual(bug.Description, bugFromDb.Description);
        }
Esempio n. 6
0
        public void AddBugShouldBeAddedToDatabaseAndShouldBeReturnedFromRepository()
        {
            // Arrange -> Prepare the objects
            var bug = new Bug()
            {
                Description = "bug-1",
                LogDate     = DateTime.Now
            };

            // Act -> Test the objects
            var bugRepository = new BugRepository(new BugLoggerDbContext());

            bugRepository.Add(bug);
            bugRepository.SaveChanges();

            // Assert -> Validate the result
            var bugFromDb = bugRepository.Find(bug.BugId);

            Assert.IsNotNull(bugFromDb);
            Assert.AreEqual(bug.Description, bugFromDb.Description);
        }
        public void AddBugWithNullDescriptionShouldThrowsValidationException()
        {
            // Arrange -> Prepare the objects
            var bug = new Bug()
            {
                Description = null,
                LogDate = DateTime.Now
            };

            // Act -> Test the objects
            var bugRepository = new BugRepository(new BugLoggerDbContext());
            bugRepository.Add(bug);
            bugRepository.SaveChanges();

            // Assert -> Validate the result
            var bugFromDb = bugRepository.Find(bug.BugId);

            Assert.IsNotNull(bugFromDb);
            Assert.AreEqual(bug.Description, bugFromDb.Description);
        }