コード例 #1
0
        public async Task DeveEmprestarJogoParaAmigo()
        {
            #region Setup
            var usuario = new User("1", "*****@*****.**");
            _userRepositoryMock.Setup(x => x.FindByIdAsync(It.IsAny <Guid>()))
            .Returns(Task.FromResult(usuario));

            _friendRepositoryMock.Setup(x => x.FindByIdAsync(It.IsAny <Guid>()))
            .Returns(Task.FromResult(new Friend("1", "*****@*****.**", "333", usuario)));

            _gameRepositoryMock.Setup(x => x.FindByIdAsync(It.IsAny <Guid>()))
            .Returns(Task.FromResult(new Game("1", "1")));

            _loanRepositoryMock.Setup(x => x.AnyAsync(It.IsAny <Expression <Func <Loan, bool> > >()))
            .Returns(Task.FromResult(false));

            var notificationContext = new NotificationContext();
            var service             = new FriendApplicationService(notificationContext, _friendRepositoryMock.Object, _mapperMock.Object, _userRepositoryMock.Object
                                                                   , _gameRepositoryMock.Object, _loanRepositoryMock.Object);
            #endregion


            await service.Lend(Guid.NewGuid(), Guid.NewGuid());

            service.Valid.Should().BeTrue();
        }
コード例 #2
0
        public async Task NaoDeveEmprestarJogoAndaEmprestador()
        {
            #region Setup
            var usuario = new User("1", "*****@*****.**");
            _userRepositoryMock.Setup(x => x.FindByIdAsync(It.IsAny <Guid>()))
            .Returns(Task.FromResult(usuario));

            _friendRepositoryMock.Setup(x => x.FindByIdAsync(It.IsAny <Guid>()))
            .Returns(Task.FromResult(new Friend("1", "*****@*****.**", "333", usuario)));

            _gameRepositoryMock.Setup(x => x.FindByIdAsync(It.IsAny <Guid>()))
            .Returns(Task.FromResult(new Game("1", "1")));

            _loanRepositoryMock.Setup(x => x.AnyAsync(It.IsAny <Expression <Func <Loan, bool> > >()))
            .Returns(Task.FromResult(true));

            var notificationContext = new NotificationContext();
            var service             = new FriendApplicationService(notificationContext, _friendRepositoryMock.Object, _mapperMock.Object, _userRepositoryMock.Object
                                                                   , _gameRepositoryMock.Object, _loanRepositoryMock.Object);
            #endregion


            await service.Lend(Guid.NewGuid(), Guid.NewGuid());

            service.Valid.Should().BeFalse();
            service.GetNotifications.Any(x => x.Message.Contains("Este jogo está emprestado. Você deve Encerrar o emprestimo ativo.")).Should().BeTrue();
        }