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); }
public TicketController(BugTrackerDbContext context, TicketRepo _ticketRepo, UserRepo _userRepo, ManipulateRoles _userManipulator) { _context = context; ticketRepo = _ticketRepo; userRepo = _userRepo; rolesManipulator = _userManipulator; }
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); }
public static void CleanDatabase() { using (var dbContext = new BugTrackerDbContext()) { dbContext.Comments.Delete(); dbContext.Bugs.Delete(); dbContext.Users.Delete(); dbContext.SaveChanges(); } }
private void CleanDatabase() { // Clean all data in all database tables var dbContext = new BugTrackerDbContext(); dbContext.Bugs.Delete(); // ... // dbContext.AnotherEntity.Delete(); // ... dbContext.SaveChanges(); }
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(); }
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 }
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); }
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()); } }
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); }
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)); }
public TicketRepo(BugTrackerDbContext injectedContext) { db = injectedContext; }
public ProjectController(BugTrackerDbContext dbContext) { _repo = new ProjectRepo(dbContext); }
public NotificationRepo(BugTrackerDbContext injectedContext) { db = injectedContext; }
public ProjectRepo(BugTrackerDbContext injectedContext) { db = injectedContext; }
public BugsController(BugTrackerDbContext data) { this.db = data; }
protected BaseController(BugTrackerDbContext data) { this.Data = data; }
protected BasicApiController(BugTrackerDbContext context) { this.data = context; }
public CommentsController(BugTrackerDbContext data) { this.db = data; }
protected BaseApiController(BugTrackerDbContext data) { this.Data = data; }
public UserController(BugTrackerDbContext dbContext) { _repo = new UserRepo(dbContext); }
public BugController(BugTrackerDbContext context) { _context = context; }
public ProjectController(BugTrackerDbContext context, ManipulateRoles manipulateRoles) { _context = context; rolesManipulator = manipulateRoles; }
public Repository(BugTrackerDbContext context) { this.Context = context; this.DbSet = this.Context.Set <T>(); }
public PersonController(BugTrackerDbContext context) { _context = context; }
public AdminController(BugTrackerDbContext context, ManipulateRoles manipulateRoles, ManipulateUsers manipulateUsers) { _context = context; rolesManipulator = manipulateRoles; usersManipulator = manipulateUsers; }
public TicketRepo(BugTrackerDbContext dbContext) : base(dbContext) { }
public UserRepo(BugTrackerDbContext injectedContext, ManipulateRoles _roleManipulator) { db = injectedContext; rolesManipulator = _roleManipulator; }
public static void AssemblyInit(TestContext context) { dbContext = new BugTrackerDbContext(); dbContext.Database.Delete(); dbContext.Database.Create(); }
public AccountController(BugTrackerDbContext injectedContext, ManipulateRoles manipulateRoles) { db = injectedContext; rolesManipulator = manipulateRoles; }
public ProjectRepo(BugTrackerDbContext dbContext) : base(dbContext) { }
public UserRepo(BugTrackerDbContext dbContext) : base(dbContext) { }