Ejemplo n.º 1
0
        private static void RegisterCompanyCommand(this IBelongToCompany document, ICompanyCommand command)
        {
            if (document == null || command == null)
                return;

            if (string.IsNullOrWhiteSpace(document.CompanyId))
                document.CompanyId = command.CommandCompanyId;

            if (command.CommandCompanyId == null)
                throw new ApplicationException(string.Format("Command doesn't have company id. {0}, {1}", command.GetType().Name, command.ToJson()));

            if (document.CompanyId == AdministratorCompany) //HACK: allow updates of admin docs
                return;

            if (document.CompanyId == command.CommandCompanyId)
                return;

            var msg = string.Format("Attempt to update different company. document: {0}. command {1}",
                                    document.ToJson(), command.ToJson());
            throw new AccessViolationException(msg);
        }
        public void Validate_WhenCalled_AssertShouldNotBeNullWasCalledOnObjectValidatorForName()
        {
            ICompanyNameCommand companyNameCommand = CreateCompanyNameCommandMock().Object;
            ICompanyCommand     sut = CreateSut(companyNameCommand: companyNameCommand);

            sut.Validate(_validatorMockContext.ValidatorMock.Object);

            _validatorMockContext.ObjectValidatorMock.Verify(m => m.ShouldNotBeNull(
                                                                 It.Is <ICompanyNameCommand>(value => value == companyNameCommand),
                                                                 It.Is <Type>(value => value == sut.GetType()),
                                                                 It.Is <string>(value => string.CompareOrdinal(value, "Name") == 0)),
                                                             Times.Once);
        }
        public void Validate_WhenCalled_AssertShouldHaveMaxLengthWasCalledOnStringValidatorForHomePage()
        {
            string          homePage = _fixture.Create <string>();
            ICompanyCommand sut      = CreateSut(homePage: homePage);

            sut.Validate(_validatorMockContext.ValidatorMock.Object);

            _validatorMockContext.StringValidatorMock.Verify(m => m.ShouldHaveMaxLength(
                                                                 It.Is <string>(value => string.CompareOrdinal(value, homePage) == 0),
                                                                 It.Is <int>(value => value == 256),
                                                                 It.Is <Type>(value => value == sut.GetType()),
                                                                 It.Is <string>(value => string.CompareOrdinal(value, "HomePage") == 0),
                                                                 It.Is <bool>(value => value)),
                                                             Times.Once);
        }
        public void Validate_WhenCalled_AssertShouldMatchPatternWasCalledOnStringValidatorForHomePage()
        {
            string          homePage = _fixture.Create <string>();
            ICompanyCommand sut      = CreateSut(homePage: homePage);

            sut.Validate(_validatorMockContext.ValidatorMock.Object);

            _validatorMockContext.StringValidatorMock.Verify(m => m.ShouldMatchPattern(
                                                                 It.Is <string>(value => string.CompareOrdinal(value, homePage) == 0),
                                                                 It.Is <Regex>(value => string.CompareOrdinal(value.ToString(), RegexTestHelper.UrlRegexPattern) == 0),
                                                                 It.Is <Type>(value => value == sut.GetType()),
                                                                 It.Is <string>(value => string.CompareOrdinal(value, "HomePage") == 0),
                                                                 It.Is <bool>(value => value)),
                                                             Times.Once);
        }
        public void Validate_WhenCalled_AssertShouldHaveMinLengthWasCalledOnStringValidatorForSecondaryPhone()
        {
            string          secondaryPhone = _fixture.Create <string>();
            ICompanyCommand sut            = CreateSut(secondaryPhone: secondaryPhone);

            sut.Validate(_validatorMockContext.ValidatorMock.Object);

            _validatorMockContext.StringValidatorMock.Verify(m => m.ShouldHaveMinLength(
                                                                 It.Is <string>(value => string.CompareOrdinal(value, secondaryPhone) == 0),
                                                                 It.Is <int>(value => value == 1),
                                                                 It.Is <Type>(value => value == sut.GetType()),
                                                                 It.Is <string>(value => string.CompareOrdinal(value, "SecondaryPhone") == 0),
                                                                 It.Is <bool>(value => value)),
                                                             Times.Once);
        }