public void GetAll()
        {
            // Arrange
            var testEntities = new List <TestEntity> {
                new TestEntity {
                    Id = 22, Name = "One"
                }, new TestEntity {
                    Id = 23, Name = "Two"
                }
            }.AsQueryable();

            var mockDbSet = new Mock <DbSet <TestEntity> >();

            mockDbSet.Setup(d => d.AsQueryable()).Returns(testEntities);

            var mockContext = new Mock <IContext>();

            mockContext.Setup(c => c.Set <TestEntity>()).Returns(mockDbSet.Object);

            var inMemory = new InMemory <TestEntity>(mockContext.Object);

            // Act
            var actual = inMemory.GetAll();

            // Assert
            mockDbSet.Verify(d => d.AsQueryable(), Times.Once);
            mockContext.Verify(c => c.Set <TestEntity>(), Times.Once);

            Assert.AreEqual(testEntities, actual);
        }
Exemplo n.º 2
0
        //Class for testing the adding of a blab and getting a user by ID
        public void Get_All_Blabs_BlabsExist()
        {
            User newUser = new User();

            newUser.ChangeEmail("*****@*****.**");
            _harness.Add(newUser);
            IEnumerable <BaseEntity> allBlabs = _harness.GetAll();
            int count = 0;

            foreach (var blab in allBlabs)
            {
                count++;
            }
            bool hasItems = false;

            if (count > 0)
            {
                hasItems = true;
            }
            Assert.AreEqual(hasItems, true);
        }
        //Class for testing the adding of a blab and getting a user by ID
        public void Get_All_Blabs_BlabsExist()
        {
            Blab newBlab = new Blab();

            newBlab.Message = "Hello, this is not Chris blabbing for the first time";
            newBlab.UserID  = "*****@*****.**";
            IEnumerable <BaseEntity> allBlabs = _harness.GetAll();
            int count = 0;

            foreach (var blab in allBlabs)
            {
                count++;
            }
            bool hasItems = false;

            if (count > 0)
            {
                hasItems = true;
            }
            Assert.AreEqual(hasItems, true);
        }