Пример #1
0
        public async Task CheckEquivalenceConstrictors(int conditionStampId, int onConditionNextDepartmentId,
                                                       int onConditionAddedStampId, int onConditionRemovedStampId, int elseConditionNextDepartmentId,
                                                       int elseConditionAddedStampId, int elseConditionRemovedStampId)
        {
            //Arrange
            var bypassSheetDefault = BypassSheetTestHelper.GetInitializedBypassSheet(3, 1, 5);
            var bypassSheetConfig  = BypassSheetTestHelper.GetInitializedBypassSheet(3, 1, 5);

            var ruleDefault = new ConditionDepartmentRule(conditionStampId, onConditionNextDepartmentId,
                                                          elseConditionNextDepartmentId, onConditionAddedStampId, onConditionRemovedStampId,
                                                          elseConditionAddedStampId, elseConditionRemovedStampId);
            var ruleConfig = new ConditionDepartmentRule(new ConditionDepartmentRuleConfig
            {
                ConditionStampId              = conditionStampId,
                OnConditionNextDepartmentId   = onConditionNextDepartmentId,
                OnConditionAddedStampId       = onConditionAddedStampId,
                OnConditionRemovedStampId     = onConditionRemovedStampId,
                ElseConditionNextDepartmentId = elseConditionNextDepartmentId,
                ElseConditionAddedStampId     = elseConditionAddedStampId,
                ElseConditionRemovedStampId   = elseConditionRemovedStampId
            });

            //Act
            var next1 = await ruleDefault.ExecuteRuleAsync(bypassSheetDefault).ConfigureAwait(false);

            var next2 = await ruleConfig.ExecuteRuleAsync(bypassSheetConfig).ConfigureAwait(false);

            //Assert
            Assert.Equal(next1, next2);
            Assert.True(bypassSheetDefault.Stamps.SetEquals(bypassSheetConfig.Stamps));
        }
Пример #2
0
        public async Task ExecuteRuleNextDepartmentId()
        {
            //Arrange
            var bypassSheet = BypassSheetTestHelper.GetInitializedBypassSheet(3, 1, 5);
            var ruleAdd     = new DefaultDepartmentRule(2);

            //Act
            var nextId = await ruleAdd.ExecuteRuleAsync(bypassSheet).ConfigureAwait(false);

            //Assert
            Assert.Equal(2, nextId);
        }
Пример #3
0
        public async Task ExecuteRuleNotExistRemove()
        {
            //Arrange
            var bypassSheet    = BypassSheetTestHelper.GetInitializedBypassSheet(1, 5);
            var expectedStamps = BypassSheetTestHelper.GetInitializedBypassSheet(1, 5).Stamps;

            var ruleAdd = new DefaultDepartmentRule(2, removedStampId: 3);

            //Act
            await ruleAdd.ExecuteRuleAsync(bypassSheet).ConfigureAwait(false);

            //Assert
            Assert.True(expectedStamps.SetEquals(bypassSheet.Stamps));
        }
Пример #4
0
        public async Task CheckInfinityCycle()
        {
            //Arrange
            var bypassSheet = BypassSheetTestHelper.GetInitializedBypassSheet(3, 1, 5);
            var history     = new StampsHistoryElement
            {
                NextDepartmentId = 2,
                Stamps           = new HashSet <int> {
                    3, 2, 1, 5
                }
            };

            var ruleAdd    = new DefaultDepartmentRule(2, 2);
            var department = new Department(2, ruleAdd);

            department.StampsHistory.Add(history);

            //Assert IsCycle - false
            Assert.False(department.IsCycle);


            //Act execute check cycle step
            await department.ExecuteDepartmentRuleAsync(bypassSheet).ConfigureAwait(false);

            //Assert IsCycle - true
            Assert.True(department.IsCycle);


            //Arrange old history
            var oldHistoryElementCount = department.StampsHistory.Count;

            //Act repeat rule after finding cycle

            await department.ExecuteDepartmentRuleAsync(bypassSheet).ConfigureAwait(false);

            //Assert history don't changed
            Assert.Equal(oldHistoryElementCount, department.StampsHistory.Count);
        }
Пример #5
0
        public async Task CheckEquivalenceConstructors()
        {
            //Arrange
            var bypassSheetDefault = BypassSheetTestHelper.GetInitializedBypassSheet(3, 1, 5);
            var bypassSheetConfig  = BypassSheetTestHelper.GetInitializedBypassSheet(3, 1, 5);

            var ruleAddDefault = new DefaultDepartmentRule(2, 2, 5);
            var ruleAddConfig  = new DefaultDepartmentRule(new DefaultDepartmentRuleConfig
            {
                NextDepartmentId = 2,
                AddedStampId     = 2,
                RemovedStampId   = 5
            });

            //Act
            var next1 = await ruleAddDefault.ExecuteRuleAsync(bypassSheetDefault).ConfigureAwait(false);

            var next2 = await ruleAddConfig.ExecuteRuleAsync(bypassSheetConfig).ConfigureAwait(false);

            //Assert
            Assert.Equal(next1, next2);
            Assert.True(bypassSheetDefault.Stamps.SetEquals(bypassSheetConfig.Stamps));
        }
Пример #6
0
        public async Task ExecuteElseConditionRule()
        {
            //Arrange
            var bypassSheet    = BypassSheetTestHelper.GetInitializedBypassSheet(3, 1, 5);
            var expectedStamps = BypassSheetTestHelper.GetInitializedBypassSheet(5, 4, 3).Stamps;

            var rule = new ConditionDepartmentRule(new ConditionDepartmentRuleConfig
            {
                ConditionStampId              = 2,
                OnConditionNextDepartmentId   = 4,
                OnConditionAddedStampId       = 2,
                OnConditionRemovedStampId     = 5,
                ElseConditionNextDepartmentId = 3,
                ElseConditionAddedStampId     = 4,
                ElseConditionRemovedStampId   = 1
            });

            //Act
            var nextId = await rule.ExecuteRuleAsync(bypassSheet).ConfigureAwait(false);

            //Assert
            Assert.Equal(3, nextId);
            Assert.True(expectedStamps.SetEquals(bypassSheet.Stamps));
        }