Esempio n. 1
0
        public StayControllerTest()
        {
            var contextMock    = new Mock <BookingContext>(_options);
            var loggerMock     = new Mock <ILogger <StayController> >();
            var repositoryMock = new Mock <Repository <StayModel> >(new BookingContext(_options));
            var unitOfWorkMock = new Mock <UnitOfWork>(contextMock.Object);

            repositoryMock.Setup(m => m.DeleteAsync(0)).Throws(new Exception());
            repositoryMock.Setup(m => m.DeleteAsync(1)).Returns(Task.FromResult(1));
            repositoryMock.Setup(m => m.InsertAsync(It.IsAny <StayModel>())).Returns(Task.FromResult <StayModel>(null));
            repositoryMock.Setup(m => m.SelectAsync()).Returns(Task.FromResult <IEnumerable <StayModel> >(null));
            repositoryMock.Setup(m => m.SelectAsync(0)).Throws(new Exception());
            repositoryMock.Setup(m => m.SelectAsync(1)).Returns(Task.FromResult <StayModel>(null));
            repositoryMock.Setup(m => m.Update(It.IsAny <StayModel>()));
            unitOfWorkMock.Setup(m => m.Stay).Returns(repositoryMock.Object);

            _logger     = loggerMock.Object;
            _unitOfWork = unitOfWorkMock.Object;
            _controller = new StayController(_logger, _unitOfWork);
        }