public async Task GetAllCommentsForBar_Throws_When_NoBarName_Passed() { //Arrange var options = Utils.GetOptions(nameof(GetAllCommentsForBar_Throws_When_NoBarName_Passed)); var user = new User { Id = Guid.NewGuid(), UserName = "******" }; var bar = new Bar { Id = Guid.NewGuid(), Name = "Manhattan" }; using (var arrangeContext = new CMContext(options)) { await arrangeContext.Bars.AddAsync(bar); await arrangeContext.Users.AddAsync(user); await arrangeContext.SaveChangesAsync(); } //Act, Assert using (var assertContext = new CMContext(options)) { var sut = new BarCommentsServices(assertContext); await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.GetAllCommentsForBar(bar.Id, null)); } }
public async Task CreateComment_Throws_When_NoUserFound() { //Arrange var options = Utils.GetOptions(nameof(CreateComment_Throws_When_NoUserFound)); var bar = new Bar { Id = Guid.NewGuid(), Name = "Manhattan" }; var userId = Guid.NewGuid(); var barCommentDTO = new BarCommentDTO { BarId = bar.Id, UserId = userId }; using (var arrangeContext = new CMContext(options)) { await arrangeContext.Bars.AddRangeAsync(bar); await arrangeContext.SaveChangesAsync(); } //Act, Assert using (var assertContext = new CMContext(options)) { var sut = new BarCommentsServices(assertContext); await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.CreateComment(barCommentDTO)); } }
public async Task EditComment_Throws_When_NoCommentFound() { //Arrange var options = Utils.GetOptions(nameof(EditComment_Throws_When_NoCommentFound)); var user = new User { Id = Guid.NewGuid(), UserName = "******" }; var bar = new Bar { Id = Guid.NewGuid(), Name = "Manhattan" }; var barComment = new BarComment { BarId = bar.Id, UserId = user.Id, Comments = "My favorite" }; var commentId = Guid.NewGuid(); using (var arrangeContext = new CMContext(options)) { await arrangeContext.Bars.AddAsync(bar); await arrangeContext.Users.AddAsync(user); await arrangeContext.BarComments.AddAsync(barComment); await arrangeContext.SaveChangesAsync(); } //Act, Assert using (var assertContext = new CMContext(options)) { var sut = new BarCommentsServices(assertContext); await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => sut.EditComment(commentId, "Changes made")); } }
public async Task GetAllCommentsForBar_Returns_Correct_WhenParam_IsValid() { //Arrange var options = Utils.GetOptions(nameof(GetAllCommentsForBar_Returns_Correct_WhenParam_IsValid)); var user = new User { Id = Guid.NewGuid(), UserName = "******" }; var user2 = new User { Id = Guid.NewGuid(), UserName = "******" }; var bar = new Bar { Id = Guid.NewGuid(), Name = "Manhattan" }; var barComment = new BarComment { BarId = bar.Id, UserId = user.Id }; var barComment2 = new BarComment { BarId = bar.Id, UserId = user2.Id }; using (var arrangeContext = new CMContext(options)) { await arrangeContext.Bars.AddAsync(bar); await arrangeContext.Users.AddRangeAsync(user, user2); await arrangeContext.BarComments.AddRangeAsync(barComment, barComment2); await arrangeContext.SaveChangesAsync(); } //Act, Assert using (var assertContext = new CMContext(options)) { var sut = new BarCommentsServices(assertContext); var result = await sut.GetAllCommentsForBar(bar.Id, "Manhattan"); Assert.AreEqual(2, result.Count()); Assert.AreEqual(result.ToList()[0].UserId, user.Id); Assert.AreEqual(result.ToList()[1].UserId, user2.Id); Assert.IsInstanceOfType(result, typeof(ICollection <BarCommentDTO>)); } }
public async Task GetAllCommentsOfUser_ShouldReturn_Correct() { //Arrange var options = Utils.GetOptions(nameof(GetAllCommentsOfUser_ShouldReturn_Correct)); var user = new User { Id = Guid.NewGuid(), UserName = "******" }; var bar = new Bar { Id = Guid.NewGuid(), Name = "Manhattan" }; var bar2 = new Bar { Id = Guid.NewGuid(), Name = "Cosmos" }; var comment = new BarComment { BarId = bar.Id, UserId = user.Id }; var comment2 = new BarComment { BarId = bar2.Id, UserId = user.Id, IsDeleted = true }; using (var arrangeContext = new CMContext(options)) { await arrangeContext.Bars.AddRangeAsync(bar, bar2); await arrangeContext.Users.AddAsync(user); await arrangeContext.BarComments.AddRangeAsync(comment, comment2); await arrangeContext.SaveChangesAsync(); } //Act, Assert using (var assertContext = new CMContext(options)) { //TODO: Replace USername with id var sut = new BarCommentsServices(assertContext); var result = await sut.GetAllCommentsOfUser(user.Id); Assert.AreEqual(1, result.Count); Assert.IsInstanceOfType(result, typeof(ICollection <BarCommentDTO>)); } }
public async Task GetAllCommentsForBar_Returns_OnlyExistingEntities() { //Arrange var options = Utils.GetOptions(nameof(GetAllCommentsForBar_Returns_OnlyExistingEntities)); var user = new User { Id = Guid.NewGuid(), UserName = "******" }; var user2 = new User { Id = Guid.NewGuid(), UserName = "******" }; var bar = new Bar { Id = Guid.NewGuid(), Name = "Manhattan" }; var barComment = new BarComment { BarId = bar.Id, UserId = user.Id }; var barComment2 = new BarComment { BarId = bar.Id, UserId = user2.Id, IsDeleted = true }; using (var arrangeContext = new CMContext(options)) { await arrangeContext.Bars.AddAsync(bar); await arrangeContext.Users.AddRangeAsync(user, user2); await arrangeContext.BarComments.AddRangeAsync(barComment, barComment2); await arrangeContext.SaveChangesAsync(); } //Act, Assert using (var assertContext = new CMContext(options)) { var sut = new BarCommentsServices(assertContext); var result = await sut.GetAllCommentsForBar(bar.Id, "Manhattan"); Assert.AreEqual(1, result.Count()); } }
public async Task CreateComment_CreatesBar_Correct() { //Arrange var options = Utils.GetOptions(nameof(CreateComment_CreatesBar_Correct)); var user = new User { Id = Guid.NewGuid(), UserName = "******" }; var bar = new Bar { Id = Guid.NewGuid(), Name = "Manhattan" }; var barCommentDTO = new BarCommentDTO { BarId = bar.Id, UserId = user.Id, Comments = "Good bar" }; using (var arrangeContext = new CMContext(options)) { await arrangeContext.Users.AddRangeAsync(user); await arrangeContext.Bars.AddRangeAsync(bar); await arrangeContext.SaveChangesAsync(); } //Act, Assert using (var assertContext = new CMContext(options)) { var sut = new BarCommentsServices(assertContext); var result = await sut.CreateComment(barCommentDTO); Assert.AreEqual(bar.Id, result.BarId); Assert.AreEqual(user.Id, result.UserId); Assert.AreEqual(1, assertContext.BarComments.Count()); Assert.IsInstanceOfType(result, typeof(BarCommentDTO)); } }
public async Task DeleteComment_ShouldDelete_Correct() { //Arrange var options = Utils.GetOptions(nameof(DeleteComment_ShouldDelete_Correct)); var user = new User { Id = Guid.NewGuid(), UserName = "******" }; var bar = new Bar { Id = Guid.NewGuid(), Name = "Manhattan" }; var barComment = new BarComment { BarId = bar.Id, UserId = user.Id }; using (var arrangeContext = new CMContext(options)) { await arrangeContext.Bars.AddAsync(bar); await arrangeContext.Users.AddAsync(user); await arrangeContext.BarComments.AddAsync(barComment); await arrangeContext.SaveChangesAsync(); } //Act, Assert using (var assertContext = new CMContext(options)) { var sut = new BarCommentsServices(assertContext); var result = await sut.DeleteComment(barComment.Id); Assert.AreEqual(true, result.IsDeleted); Assert.AreEqual(user.Id, result.UserId); Assert.AreEqual(bar.Id, result.BarId); Assert.IsInstanceOfType(result, typeof(BarCommentDTO)); } }
public async Task EditComment_Updates_Correctly() { //Arrange var options = Utils.GetOptions(nameof(EditComment_Updates_Correctly)); var user = new User { Id = Guid.NewGuid(), UserName = "******" }; var bar = new Bar { Id = Guid.NewGuid(), Name = "Manhattan" }; var barComment = new BarComment { BarId = bar.Id, UserId = user.Id, Comments = "Good one" }; using (var arrangeContext = new CMContext(options)) { await arrangeContext.Bars.AddAsync(bar); await arrangeContext.Users.AddAsync(user); await arrangeContext.BarComments.AddAsync(barComment); await arrangeContext.SaveChangesAsync(); } //Act, Assert using (var assertContext = new CMContext(options)) { var sut = new BarCommentsServices(assertContext); var result = await sut.EditComment(barComment.Id, "Changes made"); Assert.AreEqual("Changes made", result.Comments); Assert.IsInstanceOfType(result, typeof(BarCommentDTO)); } }