Beispiel #1
0
        public void AddSkeletTest()
        {
            // Arrange
            var mockSet     = new Mock <DbSet <Skelet> >();
            var mockContext = new Mock <ExamDbContext>();

            mockContext.Setup(m => m.Skelets).Returns(mockSet.Object);
            // Result
            var service = new SkeletDbRepository(mockContext.Object);

            service.AddSkelet(_data.ElementAt(0));

            // Assert
            mockSet.Verify(m => m.Add(It.IsAny <Skelet>()), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
Beispiel #2
0
        public void DeleteByIdTest()
        {
            // Arrange
            var data = _data.ToList <Skelet>();

            _mockSet.Setup(m => m.Remove(It.IsAny <Skelet>())).Callback <Skelet>((entity) => data.Remove(entity));
            _mockContext.Setup(x => x.Skelets).Returns(_mockSet.Object);
            ISkeletDbRepository dataAccess = new SkeletDbRepository(_mockContext.Object);

            //Act
            int idToDelete = 666;

            dataAccess.DeleteById(idToDelete);

            //Assert
            Assert.AreEqual(data.Count, 3);
        }
Beispiel #3
0
        public void GetByIdTest()
        {
            // Arrange
            int            id             = 666;
            Skelet         expectedEntity = _data.ElementAt(0);
            DbSet <Skelet> dbSet          = Mock.Of <DbSet <Skelet> >(set => set.Find((id)) == expectedEntity);
            ExamDbContext  context        = new ExamDbContext();

            context.Skelets = dbSet;
            ISkeletDbRepository repository = new SkeletDbRepository(context);

            // Act
            var result = repository.GetById(id);

            // Assert
            Assert.AreSame(expectedEntity, result);
        }