Ejemplo n.º 1
0
        public void CheckEntityExistsAsync_NullEntity_ThrowsArgumentNullException()
        {
            var mockDbContext = Substitute.For <IDatabaseContext>();
            var mockLogger    = Substitute.For <ILogger <EmployeeDal> >();
            var dal           = new EmployeeDal(mockDbContext, mockLogger);
            var e             = Assert.Throws <ArgumentNullException>(
                () => dal.CheckEntityExistsAsync(null).GetAwaiter().GetResult());

            Assert.That(e.Message, Does.Contain("entity"));
        }
Ejemplo n.º 2
0
        public void CheckEntityExistsAsync_EntityFound_ReturnsTrue()
        {
            var entity = new Employee
            {
                Id = 1,
            };

            var data = new List <Employee>
            {
                entity
            };

            var mockSet       = data.AsQueryable().BuildMockDbSet();
            var mockDbContext = Substitute.For <IDatabaseContext>();

            mockDbContext.Set <Employee>().Returns(mockSet);
            var mockLogger = Substitute.For <ILogger <EmployeeDal> >();
            var dal        = new EmployeeDal(mockDbContext, mockLogger);

            var result = Task.Run(async() => await dal.CheckEntityExistsAsync(1)).GetAwaiter().GetResult();

            Assert.That(result, Is.True);
        }