Esempio n. 1
0
        public void Test_ProductionCalendarService_GetRecordByDate()
        {
            RepositoryTestHelper.SetUpGetAllWithCondition(_repositoryMock, _testData);
            _repositoryMock.Setup(m => m.GetAll(It.IsAny <Expression <Func <ProductionCalendarRecord, bool> > >()))
            .Returns <Expression <Func <ProductionCalendarRecord, bool> > >(condition => _testData.AsQueryable().Where(condition).ToList());

            var svc = new ProductionCalendarService(_repositoryFactoryMock.Object);

            var record = svc.GetRecordByDate(new DateTime(2018, 3, 7));

            _repositoryMock.Verify(m => m.GetAll(It.IsAny <Expression <Func <ProductionCalendarRecord, bool> > >()), Times.Once());
            Assert.NotNull(record);
            Assert.Equal(3, record.ID);
            Assert.Equal(record.CalendarDate, new DateTime(2018, 3, 7));


            record = svc.GetRecordByDate(new DateTime(2018, 3, 1));
            _repositoryMock.Verify(m => m.GetAll(It.IsAny <Expression <Func <ProductionCalendarRecord, bool> > >()), Times.Exactly(2));
            Assert.Null(record);
        }