Ejemplo n.º 1
0
        public InMemoryRepository(JabbrContext context)
        {
            /*AJS: UNCOMMENTED THIS AND COMMENTED OUT HARD CODING TO GET TESTS TO WORK*/
            _users         = new SafeCollection <ChatUser>();
            _rooms         = new SafeCollection <ChatRoom>();
            _identities    = new SafeCollection <ChatUserIdentity>();
            _attachments   = new SafeCollection <Attachment>();
            _notifications = new SafeCollection <Notification>();
            _settings      = new SafeCollection <Settings>();
            _allowed       = new SafeCollection <ChatPrivateRoomUsers>();
            _owner         = new SafeCollection <ChatRoomOwners>();
            _userRooms     = new SafeCollection <ChatRoomUsers>();

            var user = new ChatUser
            {
                Id           = "1",
                Name         = "Jane",
                LastActivity = Convert.ToDateTime("2016-08-23 00:26:35.713"),
                IsAdmin      = true,
                IsAfk        = true,
                Status       = 1
            };

            _users.Add(user);


            ChatClient = new ChatClient
            {
                Key  = 1,
                Id   = "meow",
                Name = "testClient",
            };

            ClientState = new ClientState
            {
                ActiveRoom = "Lobby"
            };

            // instantiate UserViewModel object from User
            UserModel = new UserViewModel(user);


            // Add RoomView to RoomList

            LobbyRoomList = new List <LobbyRoomViewModel> {
            };
        }
        public InMemoryRepositoryTest()
        {
            // Establish EF Core InMemoryDatabase
            var serviceProvider = new ServiceCollection()
                                  .AddEntityFrameworkInMemoryDatabase()
                                  .BuildServiceProvider();

            _options = new DbContextOptionsBuilder <JabbrContext>()
                       .UseInMemoryDatabase()
                       .UseInternalServiceProvider(serviceProvider);

            // Set up the db context, be sure it disposes to get clean DB for each test
            using (var context = new JabbrContext(_options.Options))
            {
                _repository = new InMemoryRepository(context);
            }
        }
Ejemplo n.º 3
0
        public RepositoryExtensionsTest()
        {
            // Set up the db context
            _options = new DbContextOptionsBuilder <JabbrContext>();
            string connection = "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=JabbREFTest;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";

            _options.UseSqlServer(connection);
            DbContextOptions <JabbrContext> options = _options.Options;

            _context = new JabbrContext(options);

            _repository = new InMemoryRepository(_context);
            _principal  = new ClaimsPrincipal();
            _cache      = new DefaultCache();

            // For now, Jane is hardcoded as a user in the InMemoryRepository
            // Remove Jane for consistency in testing
            var jane = _repository.GetUserByName("Jane");

            _repository.Remove(jane);
        }
Ejemplo n.º 4
0
 public PersistedRepository(JabbrContext db)
 {
     _db = db;
 }
Ejemplo n.º 5
0
        public ChatTest()
        {
            // Fetch new instances of the required objects
            _context    = new JabbrContext(new DbContextOptions <JabbrContext>());
            _repository = new InMemoryRepository(_context);

            _cache = new DefaultCache();
            _recentMessageCache = new RecentMessageCache();
            _settings           = new OptionsManager <ApplicationSettings>(new List <IConfigureOptions <ApplicationSettings> >()
            {
            });

            _chatService = new ChatService(_cache, _recentMessageCache, _repository);

            // Create Mocks of the objects being passed into SignalR
            var request    = new Mock <HttpRequest>();
            var connection = new Mock <IConnection>();
            var pipeline   = new Mock <IHubPipelineInvoker>();

            // Taken from normal JabbR-Core execution
            var connectionId = "79482a87-8d16-42bc-b5ce-1fb7b309ad1e";

            // Establish new Chat hub with normal SignalR connection + pipeline
            var chat = new TestableChat(_repository, _settings, _chatService, connection);

            chat.Clients = new HubConnectionContext(pipeline.Object, chat.MockConnection.Object, "Chat", connectionId);

            // Include required claims with request for authentication
            // Adam's LoginFakerMiddleware runs but doesn't establish Hub context
            // so we can put the same code here to establish an identity
            var claims = new List <Claim>();

            claims.Add(new Claim(ClaimTypes.Name, "James"));
            claims.Add(new Claim(ClaimTypes.AuthenticationMethod, "provider"));
            claims.Add(new Claim(ClaimTypes.NameIdentifier, "identity"));
            claims.Add(new Claim(ClaimTypes.Email, "*****@*****.**"));
            claims.Add(new Claim(JabbRClaimTypes.Identifier, "2"));

            var claimsIdentity  = new ClaimsIdentity(claims, Constants.JabbRAuthType);
            var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);

            ChatUser user = new ChatUser()
            {
                Name     = "James",
                Email    = "*****@*****.**",
                Id       = "2",
                Identity = claimsIdentity.ToString()
            };

            // Add to repository for methods that perform user verification
            _repository.Add(user);

            // Establish request properties here, investigate query string
            request.Setup(r => r.Cookies).Returns(new Mock <IRequestCookieCollection>().Object);
            request.Setup(r => r.HttpContext.User).Returns(claimsPrincipal);

            // Register the real SignalR context to the TestableChat.
            chat.Context = new HubCallerContext(request.Object, connectionId);
            chat.Groups  = new GroupManager(connection.Object, "mygroup");

            // Instantiate Chat hub.
            _chat = chat;
        }
Ejemplo n.º 6
0
 public SettingsManager(ICache cache, JabbrContext context)
 {
     _cache   = cache;
     _context = context;
 }