コード例 #1
0
        public void CreateBug_ShouldCreateBugInTheDb()
        {
            // Arrange
            CleanDatabase();
            var bugText = "Bug #" + DateTime.Now.Ticks;

            // Act
            var postContent = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("text", bugText)
            });
            var httpResponse   = httpClient.PostAsync("/api/bugs", postContent).Result;
            var bugFromService = httpResponse.Content.ReadAsAsync <Bug>().Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.Created, httpResponse.StatusCode);
            Assert.IsNotNull(httpResponse.Headers.Location);
            Assert.IsTrue(bugFromService.Id != 0);
            Assert.AreEqual(bugFromService.Text, bugText);
            Assert.AreEqual(bugFromService.Status, BugStatus.New);
            Assert.IsNotNull(bugFromService.DateCreated);

            // Assert the database values are correct
            var dbContext = new BugTrackerDbContext();
            var bugFromDb = dbContext.Bugs.FirstOrDefault();

            Assert.IsNotNull(bugFromDb);
            Assert.AreEqual(bugFromService.Id, bugFromDb.Id);
            Assert.AreEqual(bugFromService.Text, bugFromDb.Text);
            Assert.AreEqual(bugFromService.DateCreated.ToString(), bugFromDb.DateCreated.ToString());
            Assert.AreEqual(bugFromService.Status, bugFromDb.Status);
        }
コード例 #2
0
 public TicketController(BugTrackerDbContext context, TicketRepo _ticketRepo, UserRepo _userRepo, ManipulateRoles _userManipulator)
 {
     _context         = context;
     ticketRepo       = _ticketRepo;
     userRepo         = _userRepo;
     rolesManipulator = _userManipulator;
 }
コード例 #3
0
        public void AddBug_WhenBugIsValid_ShouldAddToDb()
        {
            // Arrange -> prepare the objects
            var bug = new Bug()
            {
                Text        = "Sample New Bug",
                DateCreated = DateTime.Now,
                Status      = BugStatus.New
            };

            var dbContext = new BugTrackerDbContext();

            // Act -> perform some logic
            dbContext.Bugs.Add(bug);
            dbContext.SaveChanges();

            // Assert -> validate the results
            var bugInDb = dbContext.Bugs.Find(bug.Id);

            Assert.IsNotNull(bugInDb);
            Assert.AreEqual(bug.Text, bugInDb.Text);
            Assert.AreEqual(bug.Status, bugInDb.Status);
            Assert.AreEqual(bug.DateCreated, bugInDb.DateCreated);
            Assert.IsTrue(bugInDb.Id != 0);
        }
コード例 #4
0
 public static void CleanDatabase()
 {
     using (var dbContext = new BugTrackerDbContext())
     {
         dbContext.Comments.Delete();
         dbContext.Bugs.Delete();
         dbContext.Users.Delete();
         dbContext.SaveChanges();
     }
 }
コード例 #5
0
        private void CleanDatabase()
        {
            // Clean all data in all database tables
            var dbContext = new BugTrackerDbContext();

            dbContext.Bugs.Delete();
            // ...
            // dbContext.AnotherEntity.Delete();
            // ...
            dbContext.SaveChanges();
        }
コード例 #6
0
        public static void AssemblyInit(TestContext context)
        {
            // Start OWIN testing HTTP server with Web API support
            httpTestServer = TestServer.Create(appBuilder =>
            {
                var config = new HttpConfiguration();
                WebApiConfig.Register(config);
                appBuilder.UseWebApi(config);
            });

            httpClient = httpTestServer.HttpClient;

            dbContext = new BugTrackerDbContext();
        }
コード例 #7
0
        public void AddBug_WhenBugIsInvalid_ShouldThrowException()
        {
            // Arrange -> prapare the objects
            var dbContext  = new BugTrackerDbContext();
            var invalidBug = new Bug()
            {
                Text = null
            };

            // Act -> perform some logic
            dbContext.Bugs.Add(invalidBug);
            dbContext.SaveChanges();

            // Assert -> expect an exception
        }
コード例 #8
0
        public void FindWhenObjectIsInDbShouldReturnObject()
        {
            // Arrange
            var bug = GetValidTestBug();

            var databaseContext = new BugTrackerDbContext();
            var repo            = new EfRepository <Bug>(databaseContext);

            // Act
            databaseContext.Bugs.Add(bug);
            databaseContext.SaveChanges();

            var bugInDb = repo.Find(bug.Id);

            // Assert
            Assert.IsNotNull(bugInDb);
            Assert.AreEqual(bug.Text, bugInDb.Text);
        }
コード例 #9
0
        public void ListBugs_NonEmptyDb_ShouldReturnBugsList()
        {
            // Arrange
            CleanDatabase();
            var dbContext = new BugTrackerDbContext();

            dbContext.Bugs.Add(
                new Bug()
            {
                Text        = "Bug #" + DateTime.Now.Ticks,
                DateCreated = DateTime.Now,
                Status      = BugStatus.New
            });
            dbContext.Bugs.Add(
                new Bug()
            {
                Text        = "Bug #" + DateTime.Now.Ticks,
                DateCreated = DateTime.Now,
                Status      = BugStatus.Fixed
            });
            dbContext.SaveChanges();

            // Act
            var httpResponse    = httpClient.GetAsync("/api/bugs").Result;
            var bugsFromService = httpResponse.Content.ReadAsAsync <List <Bug> >().Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, httpResponse.StatusCode);
            Assert.AreEqual(httpResponse.Content.Headers.ContentType.MediaType, "application/json");

            var bugsFromDb = dbContext.Bugs.ToList();

            Assert.AreEqual(bugsFromDb.Count, bugsFromService.Count);

            // Assert the bugs in the DB are the same as the bugs returned from the service
            for (int i = 0; i < bugsFromService.Count; i++)
            {
                Assert.AreEqual(bugsFromService[i].Id, bugsFromDb[i].Id);
                Assert.AreEqual(bugsFromService[i].Text, bugsFromDb[i].Text);
                Assert.AreEqual(bugsFromService[i].Status, bugsFromDb[i].Status);
                Assert.AreEqual(bugsFromService[i].DateCreated.ToString(), bugsFromDb[i].DateCreated.ToString());
            }
        }
コード例 #10
0
        public void AddBugWhenBugIsValidShouldAddToDatabase()
        {
            // Arrange
            var bug = GetValidTestBug();

            var databaseContext = new BugTrackerDbContext();
            var repo            = new EfRepository <Bug>(databaseContext)
            {
                bug
            };

            // Act
            repo.SaveChanges();

            var bugInDb = databaseContext.Bugs.Find(bug.Id);

            // Assert
            Assert.IsNotNull(bugInDb);
            Assert.AreEqual(bug.Text, bugInDb.Text);
        }
コード例 #11
0
        public IHttpActionResult GetBugById([FromUri] int id)
        {
            var bug = this.Data.Bugs.Find(id);

            if (bug == null)
            {
                return(this.NotFound());
            }

            var result = new BugDetailedViewModel()
            {
                Id          = bug.Id,
                Title       = bug.Title,
                Description = bug.Description,
                Authror     = bug.Author == null ? null : bug.Author.UserName,
                Status      = bug.Status.ToString(),
                DateCreated = bug.PublishDate
            };

            var comments = bug.Comments
                           .OrderByDescending(c => c.PublishDate)
                           .Select(c => new CommentViewModel
            {
                Id          = c.Id,
                Text        = c.Text,
                Author      = c.Author == null ? null : c.Author.UserName,
                DateCreated = c.PublishDate
            })
                           .ToList();


            result.Comments = comments;

            var context            = new BugTrackerDbContext();
            var testcommentsFromDb = context.Comments;
            var testComments       = this.Data.Comments.All();

            return(this.Ok(result));
        }
コード例 #12
0
 public TicketRepo(BugTrackerDbContext injectedContext)
 {
     db = injectedContext;
 }
コード例 #13
0
 public ProjectController(BugTrackerDbContext dbContext)
 {
     _repo = new ProjectRepo(dbContext);
 }
コード例 #14
0
 public NotificationRepo(BugTrackerDbContext injectedContext)
 {
     db = injectedContext;
 }
コード例 #15
0
 public ProjectRepo(BugTrackerDbContext injectedContext)
 {
     db = injectedContext;
 }
コード例 #16
0
 public BugsController(BugTrackerDbContext data)
 {
     this.db = data;
 }
コード例 #17
0
 protected BaseController(BugTrackerDbContext data)
 {
     this.Data = data;
 }
コード例 #18
0
ファイル: BasicController.cs プロジェクト: tormibg/SoftUni-1
 protected BasicApiController(BugTrackerDbContext context)
 {
     this.data = context;
 }
コード例 #19
0
 public CommentsController(BugTrackerDbContext data)
 {
     this.db = data;
 }
コード例 #20
0
 protected BaseApiController(BugTrackerDbContext data)
 {
     this.Data = data;
 }
コード例 #21
0
 public UserController(BugTrackerDbContext dbContext)
 {
     _repo = new UserRepo(dbContext);
 }
コード例 #22
0
 public BugController(BugTrackerDbContext context)
 {
     _context = context;
 }
コード例 #23
0
 public ProjectController(BugTrackerDbContext context, ManipulateRoles manipulateRoles)
 {
     _context         = context;
     rolesManipulator = manipulateRoles;
 }
コード例 #24
0
ファイル: Repository.cs プロジェクト: premiera85/SoftUni
 public Repository(BugTrackerDbContext context)
 {
     this.Context = context;
     this.DbSet   = this.Context.Set <T>();
 }
コード例 #25
0
 public PersonController(BugTrackerDbContext context)
 {
     _context = context;
 }
コード例 #26
0
 public AdminController(BugTrackerDbContext context, ManipulateRoles manipulateRoles, ManipulateUsers manipulateUsers)
 {
     _context         = context;
     rolesManipulator = manipulateRoles;
     usersManipulator = manipulateUsers;
 }
コード例 #27
0
 public TicketRepo(BugTrackerDbContext dbContext) : base(dbContext)
 {
 }
コード例 #28
0
 public UserRepo(BugTrackerDbContext injectedContext, ManipulateRoles _roleManipulator)
 {
     db = injectedContext;
     rolesManipulator = _roleManipulator;
 }
コード例 #29
0
 public static void AssemblyInit(TestContext context)
 {
     dbContext = new BugTrackerDbContext();
     dbContext.Database.Delete();
     dbContext.Database.Create();
 }
コード例 #30
0
 public AccountController(BugTrackerDbContext injectedContext, ManipulateRoles manipulateRoles)
 {
     db = injectedContext;
     rolesManipulator = manipulateRoles;
 }
コード例 #31
0
 public ProjectRepo(BugTrackerDbContext dbContext) : base(dbContext)
 {
 }
コード例 #32
0
ファイル: UserRepo.cs プロジェクト: rev-team-5/p2-bug-tracker
 public UserRepo(BugTrackerDbContext dbContext) : base(dbContext)
 {
 }