Exemple #1
0
        public UserServiceTests()
        {
            // Definindo quais serão as classes mockadas
            userServiceMock    = new Mock <IUserService>();
            signManagerMock    = new Mock <IApplicationSignInManager>();
            unitOfWorkMock     = new Mock <IUnitOfWork>();
            userRepositoryMock = new Mock <IUserRepository>();

            //Simula login do usuario
            Thread.CurrentPrincipal = new UserMock().GetClaimsUser();

            userRepositoryMock.Setup(repo => repo.Insert(It.IsAny <User>())).Returns(() =>
            {
                return(UserMock.GetUser2());
            });

            userRepositoryMock.Setup(repo => repo.Update(It.IsAny <User>())).Returns(() =>
            {
                return(UserMock.GetUser2());
            });

            userRepositoryMock.Setup(repo => repo.Find(It.IsAny <Expression <Func <User, bool> > >())).Returns(() =>
            {
                return(UserMock.GetUser2());
            });

            userRepositoryMock.Setup(repo => repo.Find(It.IsAny <IncludeList <User> >(), It.IsAny <Guid>())).Returns(() =>
            {
                return(UserMock.GetUser2());
            });

            userRepositoryMock.Setup(repo => repo.Get()).Returns(() =>
            {
                return(new List <User>()
                {
                    UserMock.GetUser2(),
                    UserMock.GetUser1()
                }.AsQueryable());
            });

            userServiceMock.Setup(service => service.Insert(It.IsAny <User>())).Verifiable();
        }
Exemple #2
0
        public TransferServiceTests()
        {
            transferRepositoryMock    = new Mock <ITransferRepository>();
            unitOfWorkMock            = new Mock <IUnitOfWork>();
            validatorkMock            = new Mock <IValidator <Transfer> >();
            userRepositoryMock        = new Mock <IUserRepository>();
            entryRepositoryMock       = new Mock <IEntryRepository>();
            bankAccountRepositoryMock = new Mock <IBankAccountRepository>();

            service = new Service.TransferService(transferRepositoryMock.Object,
                                                  unitOfWorkMock.Object,
                                                  validatorkMock.Object,
                                                  userRepositoryMock.Object,
                                                  entryRepositoryMock.Object,
                                                  bankAccountRepositoryMock.Object);

            userRepositoryMock.Setup(repo => repo.GetUser(11111)).Returns(() =>
            {
                return(UserMock.GetUser1());
            });

            userRepositoryMock.Setup(repo => repo.GetUser(22222)).Returns(() =>
            {
                return(UserMock.GetUser2());
            });

            transferRepositoryMock.Setup(repo => repo.Insert(It.IsAny <Transfer>())).Returns(() =>
            {
                return(new Transfer()
                {
                    Id = new Guid("4c046d1f-a991-4c6f-8be2-47b4c466f028"),
                    UserOrigin = UserMock.GetUser1(),
                    UserDestination = UserMock.GetUser2(),
                    Value = 100
                });
            });
        }