public void UnitOfWork_ShouldCallCommitOnce_WhenAddInvitationIsCalled()
        {
            // Arrange
            var user = new User();

            this.userRepoMock.Setup(x => x.GetFirst(It.IsAny <Expression <Func <User, bool> > >())).Returns(user);
            this.invitationRepoMock.Setup(x => x.GetAll <Invitation>(It.IsAny <Expression <Func <Invitation, bool> > >(), It.IsAny <Expression <Func <Invitation, Invitation> > >())).Returns(new List <Invitation>());

            var invitationService = new InvitationService(unitOfWorkMock.Object, invitationRepoMock.Object, userRepoMock.Object, invitationFactoryMock.Object);

            // Act
            invitationService.AddInvitation("_", new Guid());

            // Assert
            this.unitOfWorkMock.Verify(x => x.Commit(), Times.Once);
        }
        public void AddInvitation_ShouldReturnTrue_WhenCalled()
        {
            // Arrange
            var user = new User();

            this.userRepoMock.Setup(x => x.GetFirst(It.IsAny <Expression <Func <User, bool> > >())).Returns(user);
            this.invitationRepoMock.Setup(x => x.GetAll <Invitation>(It.IsAny <Expression <Func <Invitation, bool> > >(), It.IsAny <Expression <Func <Invitation, Invitation> > >())).Returns(new List <Invitation>());

            var invitationService = new InvitationService(unitOfWorkMock.Object, invitationRepoMock.Object, userRepoMock.Object, invitationFactoryMock.Object);

            // Act
            var result = invitationService.AddInvitation("_", new Guid());

            // Assert
            Assert.That(result, Is.True);
        }
        public void AddInvitation_ShouldReturnFalse_WhenUserIsAlreadyInThisHousehold()
        {
            // Arrange
            var user = new User();

            user.Households.Add(new Household("_", "_", new byte[0]));
            this.userRepoMock.Setup(x => x.GetFirst(It.IsAny <Expression <Func <User, bool> > >())).Returns(user);
            this.invitationRepoMock.Setup(x => x.GetAll <Invitation>(It.IsAny <Expression <Func <Invitation, bool> > >(), It.IsAny <Expression <Func <Invitation, Invitation> > >())).Returns(new List <Invitation>());

            var invitationService = new InvitationService(unitOfWorkMock.Object, invitationRepoMock.Object, userRepoMock.Object, invitationFactoryMock.Object);

            // Act
            var result = invitationService.AddInvitation("_", user.Households.First().Id);

            // Assert
            Assert.That(result, Is.False);
        }
Esempio n. 4
0
        public async Task <IActionResult> Post([FromBody] InvitationViewModel viewModel)
        {
            var invitation = await invitationService.AddInvitation(viewModel, GetCurrentUserId());

            return(Ok(invitation));
        }