Esempio n. 1
0
        public async void Authorize_Valid_User()
        {
            var options = new DbContextOptionsBuilder <DashboardDbContext>()
                          .UseInMemoryDatabase(databaseName: "Authorize_Valid_User")
                          .Options;

            var user = new User()
            {
                Email    = "*****@*****.**",
                Password = "******",
                IsActive = true
            };

            using (var context = new DashboardDbContext(options))
            {
                var serviceCheckEmail = new CheckEmailService(context, _mockLoggerCheckEmail.Object);
                var serviceCrud       = new UserCrudService(context, _mockLoggerUserCrud.Object, serviceCheckEmail, _mockSendGridService.Object);

                var userCreate = new User()
                {
                    Email    = user.Email,
                    Password = user.Password,
                    IsActive = user.IsActive
                };

                await serviceCrud.CreateUserAsync(userCreate);

                await context.SaveChangesAsync();
            }

            using (var context = new DashboardDbContext(options))
            {
                var serviceAuth = new UserAuthService(context, _mockLogger.Object);
                var result      = serviceAuth.AuthUser(user);

                Assert.Equal(1, await context.Users.CountAsync());
                Assert.NotNull(result);
                Assert.Equal(user.Email, result.Email);
            }
        }