示例#1
0
        public async Task ActivityDoesntChangeStateOnValidationErrors()
        {
            var container = ObjectFactory.Container;

            var callCount = new Dictionary <string, int>();

            callCount["activate"] = 0;

            var activityDo = ActivationTestsSetup(container, callCount);
            var terminalTransmitterMock = new TerminalTransmitterMock();

            terminalTransmitterMock.CallActivityBody = (action, parameters, dto) =>
            {
                if (action == "activate")
                {
                    using (var updatableStorage = _crate.GetUpdatableStorage(dto.ActivityDTO))
                    {
                        updatableStorage.Add(Crate.FromContent("Validation Errors", new ValidationResultsCM
                        {
                            ValidationErrors =
                            {
                                new ValidationResultDTO
                                {
                                    ErrorMessage = "Generic error"
                                }
                            }
                        }));
                    }
                }

                return(dto.ActivityDTO);
            };

            container.Inject(typeof(ITerminalTransmitter), terminalTransmitterMock);

            await container.GetInstance <IActivity>().Activate(activityDo);

            using (var uow = ObjectFactory.GetInstance <IUnitOfWork>())
            {
                Assert.AreEqual(ActivationState.Deactivated, uow.PlanRepository.GetById <ActivityDO>(activityDo.Id).ActivationState, "Activity with validation errors should stay deactivated");
            }
        }
示例#2
0
        private ActivityDO ActivationTestsSetup(IContainer container, Dictionary <string, int> callCount)
        {
            var terminalTransmitterMock = new TerminalTransmitterMock();

            terminalTransmitterMock.CallActivityBody = (action, parameters, dto) =>
            {
                int count;

                if (callCount.TryGetValue(action, out count))
                {
                    callCount[action] = count + 1;
                }
                else
                {
                    callCount[action] = 1;
                }

                return(dto.ActivityDTO);
            };

            ActivityDO activityDo = FixtureData.TestActivityStateInProcess();

            activityDo.CrateStorage = JsonConvert.SerializeObject(new ActivityDTO());

            using (var uow = ObjectFactory.GetInstance <IUnitOfWork>())
            {
                uow.ActivityTemplateRepository.Add(activityDo.ActivityTemplate);
                uow.PlanRepository.Add(new PlanDO()
                {
                    Name       = "sdfsdf",
                    PlanState  = PlanState.Inactive,
                    ChildNodes = { activityDo }
                });
                uow.SaveChanges();
            }

            container.Inject(typeof(ITerminalTransmitter), terminalTransmitterMock);

            return(activityDo);
        }