예제 #1
0
        public async Task GetUserBoardsAsync_MustReturnTheUserBoards()
        {
            var options = new DbContextOptionsBuilder <MWContext>()
                          .UseInMemoryDatabase(databaseName: _fixture.Create <string>())
                          .Options;

            using (var context = new MWContext(options))
            {
                var repo = new UserRepository(context);

                const string user1 = "user1";
                var          b1    = _fixture.Create <Board>();
                var          b2    = _fixture.Create <Board>();

                var pb1 = _fixture.Build <PersistibleBoard>()
                          .With(b => b.BoardDefinition, JsonConvert.SerializeObject(b1).ToString())
                          .With(b => b.Username, user1).Create();
                var pb2 = _fixture.Build <PersistibleBoard>()
                          .With(b => b.BoardDefinition, JsonConvert.SerializeObject(b2).ToString())
                          .With(b => b.Username, user1).Create();
                var pb3 = _fixture.Create <PersistibleBoard>();
                var pb4 = _fixture.Create <PersistibleBoard>();

                context.PersistibleBoards.Add(pb1);
                context.PersistibleBoards.Add(pb2);
                context.PersistibleBoards.Add(pb3);
                context.PersistibleBoards.Add(pb4);
                context.SaveChanges();

                var result = await repo.GetUserBoardsAsync(user1);

                Assert.AreEqual(2, result.Count);
            }
        }
예제 #2
0
        public async Task GetUserBoardsAsync_WhenTheUserDoesNotHaveBoards_MustReturnEmptyList()
        {
            var options = new DbContextOptionsBuilder <MWContext>()
                          .UseInMemoryDatabase(databaseName: _fixture.Create <string>())
                          .Options;

            using (var context = new MWContext(options))
            {
                var repo = new UserRepository(context);

                const string user1 = "user1";
                var          pb1   = _fixture.Create <PersistibleBoard>();
                var          pb2   = _fixture.Create <PersistibleBoard>();
                var          pb3   = _fixture.Create <PersistibleBoard>();

                context.PersistibleBoards.Add(pb1);
                context.PersistibleBoards.Add(pb2);
                context.PersistibleBoards.Add(pb3);
                context.SaveChanges();

                var result = await repo.GetUserBoardsAsync(user1);

                Assert.IsNotNull(result);
                Assert.AreEqual(0, result.Count);
            }
        }
예제 #3
0
        public async Task RegisterUserAsync_MustReturnTheUser()
        {
            var options = new DbContextOptionsBuilder <MWContext>()
                          .UseInMemoryDatabase(databaseName: _fixture.Create <string>())
                          .Options;

            using (var context = new MWContext(options))
            {
                var repo = new UserRepository(context);
                var user = Utils.GetFixture().Create <User>();

                Assert.AreEqual(user, await repo.RegisterUserAsync(user));
            }
        }
예제 #4
0
        public async Task RegisterUserAsync_MustCreateTheUserInTheContext()
        {
            var options = new DbContextOptionsBuilder <MWContext>()
                          .UseInMemoryDatabase(databaseName: _fixture.Create <string>())
                          .Options;

            using (var context = new MWContext(options))
            {
                var repo = new UserRepository(context);
                var user = Utils.GetFixture().Create <User>();

                await repo.RegisterUserAsync(user);

                context.Users.Find(user.Username);
            }
        }
예제 #5
0
        public async Task GetUserAsync_IfTheUserDoesExists_ReturnsNull()
        {
            var options = new DbContextOptionsBuilder <MWContext>()
                          .UseInMemoryDatabase(databaseName: _fixture.Create <string>())
                          .Options;

            using (var context = new MWContext(options))
            {
                var repo = new UserRepository(context);
                var user = Utils.GetFixture().Create <User>();

                context.Users.Add(user);
                context.SaveChanges();

                Assert.IsNull(await repo.GetUserAsync(DateTime.Now.ToString()));
            }
        }
예제 #6
0
        public async Task GetUserAsync_MustReturnTheUser()
        {
            var options = new DbContextOptionsBuilder <MWContext>()
                          .UseInMemoryDatabase(databaseName: _fixture.Create <string>())
                          .Options;

            using (var context = new MWContext(options))
            {
                var repo = new UserRepository(context);

                const string user1 = "user1";
                var          u1    = _fixture.Build <User>()
                                     .With(b => b.Username, user1).Create();

                context.Users.Add(u1);
                context.SaveChanges();

                var result = await repo.GetUserAsync(user1);

                Assert.AreEqual(u1, result);
            }
        }
예제 #7
0
        public async Task GetUserAsync_WhenTheUserDoesNotExist_MustReturnNull()
        {
            var options = new DbContextOptionsBuilder <MWContext>()
                          .UseInMemoryDatabase(databaseName: _fixture.Create <string>())
                          .Options;

            using (var context = new MWContext(options))
            {
                var repo = new UserRepository(context);

                const string user1 = "existingUser";
                const string user2 = "nonExistingUser";
                var          u1    = _fixture.Build <User>()
                                     .With(b => b.Username, user1).Create();

                context.Users.Add(u1);
                context.SaveChanges();

                var result = await repo.GetUserAsync(user2);

                Assert.IsNull(result);
            }
        }
예제 #8
0
 public PostRepository(MWContext context)
 {
     this.context = context;
     this.dbSet   = context.Set <Post>();
 }
예제 #9
0
 public AlbumRepository(MWContext context)
 {
     this.context = context;
     this.dbSet   = context.Set <Album>();
 }
예제 #10
0
 public TasksController(MWContext context)
 {
     _context = context;
 }
예제 #11
0
 public WordListController(MWContext context)
 {
     _context = context;
 }
 public LearningSchedulesController(MWContext context)
 {
     _context = context;
 }