public void TryGetBagtotheFutureSnsUserById() { //arrange var testId = 3; bttfSnsUserRepo.Setup(x => x.SingleOrDefault(It.IsAny <System.Linq.Expressions.Expression <Func <BagtotheFutureSnsUser, bool> > >())) .Returns(BagtotheFutureSnsUserList.SingleOrDefault(x => x.Id == testId)); //action var result = service.GetBagtotheFutureSnsUserById(testId); //assert Assert.NotNull(result); Assert.Equal(testId, result.Id); bttfSnsUserRepo.Verify(x => x.Add(It.IsAny <BagtotheFutureSnsUser>()), Times.Never); bttfSnsUserRepo.Verify(x => x.Save(), Times.Never); bttfSnsUserRepo.Verify(x => x.GetAll(), Times.Never); bttfSnsUserRepo.Verify(x => x.Any(It.IsAny <System.Linq.Expressions.Expression <Func <BagtotheFutureSnsUser, bool> > >()), Times.Never); bttfSnsUserRepo.Verify(x => x.FirstOrDefault(It.IsAny <System.Linq.Expressions.Expression <Func <BagtotheFutureSnsUser, bool> > >()), Times.Never); bttfSnsUserRepo.Verify(x => x.Filter(It.IsAny <System.Linq.Expressions.Expression <Func <BagtotheFutureSnsUser, bool> > >()), Times.Never); bttfSnsUserRepo.Verify(x => x.Remove(It.IsAny <BagtotheFutureSnsUser>()), Times.Never); bttfSnsUserRepo.Verify(x => x.SingleOrDefault(It.IsAny <System.Linq.Expressions.Expression <Func <BagtotheFutureSnsUser, bool> > >()), Times.Once); bttfSnsUserRepo.Verify(x => x.Update(It.IsAny <BagtotheFutureSnsUser>()), Times.Never); }
public void TryCreateBagtotheFutureSnsFailed() { //arrange var entry = BagtotheFutureSnsList[0]; var entryUser = BagtotheFutureSnsUserList.SingleOrDefault(x => x.Id == 1000); bttfSnsUserRepo.Setup(x => x.SingleOrDefault(It.IsAny <System.Linq.Expressions.Expression <Func <BagtotheFutureSnsUser, bool> > >())).Returns(entryUser); bttfSnsRepo.Setup(x => x.Add(It.IsAny <BagtotheFutureSns>())).Returns(entry); //assert var result = Assert.Throws <BagtotheFutureServiceException>(() => { //action service.CreateBagtotheFutureSns(entry); }); Assert.NotNull(result); Assert.Equal("400", result.Code); Assert.Contains("sns공유 절차가 잘못되었습니다.", result.Message); }
public void TryCreateBagtotheFutureSns() { //arrange var entry = BagtotheFutureSnsList[0]; var entryUser = BagtotheFutureSnsUserList.SingleOrDefault(x => x.Id == entry.UserId); bttfSnsUserRepo.Setup(x => x.SingleOrDefault(It.IsAny <System.Linq.Expressions.Expression <Func <BagtotheFutureSnsUser, bool> > >())).Returns(entryUser); bttfSnsRepo.Setup(x => x.Add(It.IsAny <BagtotheFutureSns>())).Returns(entry); //action var result = service.CreateBagtotheFutureSns(entry); //assert Assert.NotNull(result); Assert.Equal(entryUser.Id, result.User.Id); Assert.Matches(entry.SnsTypeDisplayName, result.SnsTypeDisplayName); bttfSnsRepo.Verify(x => x.Add(It.IsAny <BagtotheFutureSns>()), Times.Once); bttfSnsRepo.Verify(x => x.Save(), Times.Once); bttfSnsRepo.Verify(x => x.GetAll(), Times.Never); bttfSnsRepo.Verify(x => x.Any(It.IsAny <System.Linq.Expressions.Expression <Func <BagtotheFutureSns, bool> > >()), Times.Never); bttfSnsRepo.Verify(x => x.FirstOrDefault(It.IsAny <System.Linq.Expressions.Expression <Func <BagtotheFutureSns, bool> > >()), Times.Never); bttfSnsRepo.Verify(x => x.Filter(It.IsAny <System.Linq.Expressions.Expression <Func <BagtotheFutureSns, bool> > >()), Times.Never); bttfSnsRepo.Verify(x => x.Remove(It.IsAny <BagtotheFutureSns>()), Times.Never); bttfSnsRepo.Verify(x => x.SingleOrDefault(It.IsAny <System.Linq.Expressions.Expression <Func <BagtotheFutureSns, bool> > >()), Times.Never); bttfSnsRepo.Verify(x => x.Update(It.IsAny <BagtotheFutureSns>()), Times.Never); bttfSnsUserRepo.Verify(x => x.Add(It.IsAny <BagtotheFutureSnsUser>()), Times.Never); bttfSnsUserRepo.Verify(x => x.Save(), Times.Never); bttfSnsUserRepo.Verify(x => x.GetAll(), Times.Never); bttfSnsUserRepo.Verify(x => x.Any(It.IsAny <System.Linq.Expressions.Expression <Func <BagtotheFutureSnsUser, bool> > >()), Times.Never); bttfSnsUserRepo.Verify(x => x.FirstOrDefault(It.IsAny <System.Linq.Expressions.Expression <Func <BagtotheFutureSnsUser, bool> > >()), Times.Never); bttfSnsUserRepo.Verify(x => x.Filter(It.IsAny <System.Linq.Expressions.Expression <Func <BagtotheFutureSnsUser, bool> > >()), Times.Never); bttfSnsUserRepo.Verify(x => x.Remove(It.IsAny <BagtotheFutureSnsUser>()), Times.Never); bttfSnsUserRepo.Verify(x => x.SingleOrDefault(It.IsAny <System.Linq.Expressions.Expression <Func <BagtotheFutureSnsUser, bool> > >()), Times.Once); bttfSnsUserRepo.Verify(x => x.Update(It.IsAny <BagtotheFutureSnsUser>()), Times.Never); }