示例#1
0
        public void Test_ProductionCalendarService_AddRecord_NoParam()
        {
            var svc = new ProductionCalendarService(_repositoryFactoryMock.Object);

            Assert.Throws <ArgumentNullException>(() => svc.AddRecord(null));
            _repositoryMock.Verify(m => m.Add(It.IsAny <ProductionCalendarRecord>()), Times.Never());
        }
示例#2
0
        public void Test_ProductionCalendarService_DeleteRecord()
        {
            RepositoryTestHelper.SetUpDeleteById <ProductionCalendarRecord, IProductionCalendarRepository>(_repositoryMock);

            var svc = new ProductionCalendarService(_repositoryFactoryMock.Object);

            svc.DeleteRecord(1);

            _repositoryMock.Verify(m => m.Delete(1), Times.Once());
        }
示例#3
0
        public void Test_ProductionCalendarService_GetAllRecords()
        {
            RepositoryTestHelper.SetUpGetAllWithSort(_repositoryMock, _testData);

            var svc     = new ProductionCalendarService(_repositoryFactoryMock.Object);
            var records = svc.GetAllRecords();

            _repositoryMock.Verify(m => m.GetAll(It.IsAny <Func <IQueryable <ProductionCalendarRecord>, IOrderedQueryable <ProductionCalendarRecord> > >()), Times.Once());

            Assert.Equal(7, records.Count());
            Assert.Equal(records[0].CalendarDate, new DateTime(2018, 3, 5));
            Assert.Equal(records[6].CalendarDate, new DateTime(2018, 3, 11));
        }
示例#4
0
        public void Test_ProductionCalendarService_AddRecord()
        {
            RepositoryTestHelper.SetUpAdd <ProductionCalendarRecord, IProductionCalendarRepository>(_repositoryMock);

            var newRecord = new ProductionCalendarRecord
            {
                Year         = 2018,
                Month        = 3,
                Day          = 1,
                CalendarDate = new DateTime(2018, 3, 1),
                WorkingHours = 8
            };
            var svc         = new ProductionCalendarService(_repositoryFactoryMock.Object);
            var savedRecord = svc.AddRecord(newRecord);

            _repositoryMock.Verify(m => m.Add(newRecord), Times.Once());
            //Assert.That(savedRecord, Is.SameAs(newRecord));
            Assert.Same(savedRecord, newRecord);
        }
示例#5
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);
        }