public void ChangeLot_ChangedNameAndComments_NameChangedCommentsNotChanged() { var lot = new Lot { SellerUserId = "*****@*****.**", SellDate = DateTime.Now.AddDays(1), StartDate = DateTime.Now, Name = "Name1", LotComments = new List <LotComment> { new LotComment { Message = "Message1", LotId = 1, UserId = "*****@*****.**" } } }; lotOperationsHandler.AddLot(lot, "", ""); var lotComment = new LotComment { Message = "Message2", LotId = 1, UserId = "*****@*****.**" }; var modifiedLot = lotOperationsHandler.GetLot(1); modifiedLot.LotComments = new List <LotComment> { lotComment }; modifiedLot.Name = "Name2"; lotOperationsHandler.ChangeLot(1, modifiedLot); var resultLot = lotOperationsHandler.GetLot(1); resultLot.LotComments = lotCommentOperationsHandler.GetLotComments(1).ToList(); Assert.AreEqual(1, lotOperationsHandler.GetAllLots().Count()); Assert.AreEqual(1, resultLot.LotComments.Count()); Assert.AreEqual("Name2", resultLot.Name); Assert.AreEqual("Message1", resultLot.LotComments[0].Message); }
public async Task DeleteUserAccountAsync_ValidId_DeletesWithCommentsAndLots() { var user = new UserAccountInfo { Name = "User1", Email = "*****@*****.**" }; var comment1 = new LotComment { Message = "Message1", UserId = "*****@*****.**", LotId = 1 }; var comment2 = new LotComment { Message = "Message2", UserId = "*****@*****.**", LotId = 1 }; var lot = new Lot { SellerUserId = "*****@*****.**", StartDate = DateTime.Now, SellDate = DateTime.Now.AddDays(1), }; await userAccountOperationsHandler.AddUserAccountAsync(user); await lotOperationsHandler.AddLotAsync(lot, "", ""); await lotCommentOperationsHandler.AddCommentAsync(comment1); await lotCommentOperationsHandler.AddCommentAsync(comment2); await userAccountOperationsHandler.DeleteUserAccountAsync("*****@*****.**", "", ""); Assert.AreEqual(0, (await userAccountOperationsHandler.GetAllUserAccountsAsync()).Count()); //Lot was deleted together with user, so lot with Id = 1 doesn`t exist Assert.ThrowsAsync <WrongIdException>(() => lotOperationsHandler.GetLotAsync(1)); }
public async Task AddCommentAsync_ValidInput_AddsComment() { var lot = new Lot { SellerUserId = "*****@*****.**", StartDate = DateTime.Now, SellDate = DateTime.Now.AddDays(1), Name = "Name1" }; await lotOperationsHandler.AddLotAsync(lot, "", ""); var lotComment = new LotComment { Message = "Comment1", UserId = "*****@*****.**", LotId = 1 }; await lotCommentOperationsHandler.AddCommentAsync(lotComment); var lotComment2 = new LotComment { Message = "Comment2", UserId = "*****@*****.**", LotId = 1 }; await lotCommentOperationsHandler.AddCommentAsync(lotComment2); var resultLot = await lotOperationsHandler.GetLotAsync(1); resultLot.LotComments = lotCommentOperationsHandler.GetLotComments(resultLot.Id).ToList(); var resultUser = await userAccountOperationsHandler.GetUserAccountAsync("*****@*****.**"); resultUser.LotComments = lotCommentOperationsHandler.GetUserComments(resultUser.Email).ToList(); Assert.AreEqual(1, (await lotOperationsHandler.GetAllLotsAsync()).Count()); Assert.AreEqual(2, resultLot.LotComments.Count()); Assert.AreEqual(2, resultUser.LotComments.Count()); Assert.AreEqual("Comment1", resultLot.LotComments[0].Message); Assert.AreEqual("DefaultUser", resultLot.LotComments[0].User.Name); Assert.AreEqual("Comment2", resultLot.LotComments[1].Message); Assert.AreEqual("DefaultUser", resultLot.LotComments[1].User.Name); }
public void AddComment(LotComment lotComment) { //Don`t check id`s, because //This will throw exception if UserId is wrong userAccountOperationsHandler.GetUserAccount(lotComment.UserId); //This will throw exception if LotId if wrong Lot lot = lotOperationsHandler.GetLot(lotComment.LotId); lot.LotComments = GetLotComments(lot.Id).ToList(); lot.AddComment(lotComment); UoW.LotComments.Add(mapper.Map <LotCommentEntity>(lotComment)); UoW.SaveChanges(); //private ChangeLot, without checking Lot again lotOperationsHandler.ChangeLotUnsafe(lot); }
public async Task AddCommentAsync(LotComment lotComment) { //Don`t check id`s, because //This will throw exception if UserId is wrong await userAccountOperationsHandler.GetUserAccountAsync(lotComment.UserId); //This will throw exception if LotId if wrong Lot lot = await lotOperationsHandler.GetLotAsync(lotComment.LotId); lot.LotComments = (await GetLotCommentsAsync(lot.Id)).ToList(); lot.AddComment(lotComment); UoW.LotComments.Add(mapper.Map <LotCommentEntity>(lotComment)); await UoW.SaveChangesAsync(); //private ChangeLot, without checking Lot again await lotOperationsHandler.ChangeLotUnsafeAsync(lot); }
public async Task AddCommentAsync_InvalidInput_ThrowsWrongIdException() { var lot = new Lot { SellerUserId = "*****@*****.**", StartDate = DateTime.Now, SellDate = DateTime.Now.AddDays(1), Name = "Name1" }; await lotOperationsHandler.AddLotAsync(lot, "", ""); await userAccountOperationsHandler.AddUserAccountAsync(new UserAccountInfo { Name = "Commenter", Email = "*****@*****.**" }); var invalidUserIdComment = new LotComment { Message = "Comment1", UserId = "*****@*****.**", LotId = 1 }; var invalidLotIdComment = new LotComment { Message = "Comment1", UserId = "*****@*****.**", LotId = 2 }; Assert.ThrowsAsync <WrongIdException>(() => lotCommentOperationsHandler.AddCommentAsync(invalidUserIdComment)); Assert.ThrowsAsync <WrongIdException>(() => lotCommentOperationsHandler.AddCommentAsync(invalidLotIdComment)); }