Exemplo n.º 1
0
        public async Task Log_User_Action_Activity_Mongo_Test()
        {
            // Arrange
            DatabaseOptions databaseOptions = _context.MongoDatabaseOptions;
            IOptionsMonitor <DatabaseOptions> databaseOptionsMock   = Mock.Of <IOptionsMonitor <DatabaseOptions> >(_ => _.CurrentValue == databaseOptions);
            UserSessionMongoRepository        userSessionRepository = new UserSessionMongoRepository(new MongoConnection(databaseOptionsMock.CurrentValue));

            // Act
            UserSession userSession = new UserSession
            {
                Id               = DataUtil.GenerateUniqueId(),
                UserId           = "5c06a15e4cc9a850bca44488",
                RequestIpAddress = "127.0.0.1",
                UserActivities   = new List <UserActivity>(),
                SignInDate       = DateTime.UtcNow
            };
            await userSessionRepository.AddAsync(userSession);

            await userSessionRepository.LogUserActivityAsync(userSession.Id, new UserActivity
            {
                Content      = "Abc",
                ActivityDate = DateTime.UtcNow,
                ActivityName = "Test",
                ActivityType = ActivityType.Info
            });

            userSessionRepository.Dispose();
            // Assert
            Assert.True(true);
        }
        private InternalIdentityServiceProvider GetIdentityServiceProvider()
        {
            JwtBearerOptions jwtOptions = new JwtBearerOptions
            {
                Audience = "LetPortal",
                Issuer   = "letportal.app",
                RefreshTokenExpiration = 45,
                TokenExpiration        = 30,
                Secret = "9f3acfa82146f5e4a7dabf17c2b63f538c0bcffb8872e889367df2e2c23cef94"
            };

            IOptionsMonitor <JwtBearerOptions> mockJwtOptions = Mock.Of <IOptionsMonitor <JwtBearerOptions> >(_ => _.CurrentValue == jwtOptions);

            DatabaseOptions databaseOptions = _context.MongoDatabaseOptions;
            IOptionsMonitor <DatabaseOptions> databaseOptionsMock = Mock.Of <IOptionsMonitor <DatabaseOptions> >(_ => _.CurrentValue == databaseOptions);

#pragma warning disable CA2000 // Dispose objects before losing scope
            IssuedTokenMongoRepository issuedTokenRepository = new IssuedTokenMongoRepository(new MongoConnection(databaseOptionsMock.CurrentValue));
            UserSessionMongoRepository userSessionRepository = new UserSessionMongoRepository(new MongoConnection(databaseOptionsMock.CurrentValue));
            RoleMongoRepository        roleRepository        = new RoleMongoRepository(new MongoConnection(databaseOptionsMock.CurrentValue));
#pragma warning restore CA2000 // Dispose objects before losing scope

            Mock <IEmailServiceProvider> mockEmailServiceProvider = new Mock <IEmailServiceProvider>();
            mockEmailServiceProvider
            .Setup(a => a.SendEmailAsync(It.IsAny <EmailEnvelop>(), It.IsAny <EmailOptions>()))
            .Returns(Task.CompletedTask);
            Mock <IServiceLogger <InternalIdentityServiceProvider> > mockServiceLogger = new Mock <IServiceLogger <InternalIdentityServiceProvider> >();

#pragma warning disable CA2000 // Dispose objects before losing scope
            UserManager <User> userManager = GetUserManager();
#pragma warning restore CA2000 // Dispose objects before losing scope
            InternalIdentityServiceProvider internalISProvider = new InternalIdentityServiceProvider(
                userManager,
                GetSignInManager(userManager),
#pragma warning disable CA2000 // Dispose objects before losing scope
                roleManager: GetRoleManager(),
#pragma warning restore CA2000 // Dispose objects before losing scope
                mockJwtOptions,
                issuedTokenRepository,
                userSessionRepository,
                roleRepository,
                mockEmailServiceProvider.Object,
                mockServiceLogger.Object);

            return(internalISProvider);
        }