Пример #1
0
        public IActionResult Auth([FromBody] CredentialsInput credentialsInput)
        {
            var cmd = new AuthUser(loginRepository, Repository, SubscriptionRepository, AuthTokenHandler,
                                   subscriptionTypeRepository, credentialsInput);

            return(Ok(cmd.Execute()));
        }
Пример #2
0
        public void ShouldAuth()
        {
            var user    = new User(0, "alexandre", "felix", false, UserType.User);
            var sub     = new Subscription(0, 0, DateTime.Now, 0, true);
            var subType = new SubscriptionType(0, "resident", 8, 3, 2, 20, 15, 20, 25, "test");

            sub.Type = subType;
            var mockTokenhandler = new Mock <ITokenHandler>();

            mockTokenhandler.Setup(mock => mock.EncryptToken(It.IsAny <List <Claim> >())).Returns("authtokens");


            var mockLoginrepo = new Mock <ILoginRepository>();

            mockLoginrepo.Setup(mock => mock.Auth("test", "123")).Returns(0);

            var mockUserRepo = new Mock <IUserRepository>();

            mockUserRepo.Setup(mock => mock.GetById(It.IsAny <long>())).Returns(user);

            var mockSubRepo = new Mock <ISubscriptionRepository>();

            mockSubRepo.Setup(mock => mock.GetOfUser(0)).Returns(sub);

            var mockSubTypeRepo = new Mock <ISubscriptionTypeRepository>();

            mockSubTypeRepo.Setup(m => m.GetById(0)).Returns(subType);

            var doAuth = new AuthUser(mockLoginrepo.Object, mockUserRepo.Object, mockSubRepo.Object,
                                      mockTokenhandler.Object, mockSubTypeRepo.Object,
                                      new CredentialsInput {
                Email = "test", Password = "******"
            });

            var res = doAuth.Execute();

            Assert.AreEqual(user, res.user);
            Assert.AreEqual("felix", res.user.LastName);
            Assert.AreEqual("authtokens", res.auth_token);
            Assert.AreEqual("resident", res.sub.Type.Name);
        }