예제 #1
0
        public void DbContext_GetWhereImageNotExists()
        {
            var ctx = new UserContext();

            // Tests
            var shopRepository = new UserRepository(ctx);

            Assert.AreEqual(shopRepository.GetWhereImageNotExists().Count, 2);
        }
예제 #2
0
        public void DbContext_GetAllUsers()
        {
            var ctx = new UserContext();
            // Create Fake user Data, this will replace our Database entries.
            var userList = new List<User>
            {
                new User() { Id= 1, Name = "Frederik", PictureUrl = "test" },
                new User() { Id=2, Name = "Admin", PictureUrl = "test2" }
            };

            // Tests
            var shopRepository = new UserRepository(ctx);

            Assert.AreEqual(shopRepository.GetAll().Count, 2);
        }
예제 #3
0
        public void FakeContext_GetAllUsers()
        {
            // Create Fake user Data, this will replace our Database entries.
            var userList = new List<User>
            {
                new User() { Id= 1, Name = "Frederik", PictureUrl = "test" },
                new User() { Id=2, Name = "Admin", PictureUrl = "test2" }
            };

            // Create a new instance of the MoqObjectSet class, this will be our mocked replacement for the IObjectSet Users property
            IDbSet<User> moqUserObjectSet = new MoqDbSet<User>(userList);

            // Create mock for IObjectContext and bind the Users property to our mocked "MoqObjectSet" implementation
            var mockContext = new Mock<IUserContext>();
            mockContext.Setup(m => m.Users).Returns(moqUserObjectSet);

            // Tests
            var shopRepository = new UserRepository(mockContext.Object);

            Assert.AreEqual(shopRepository.GetAll().Count, 2);
        }