protected override void Context()
        {
            DbContext = new PRToolsEntities();
            DocumentRepository = new DocumentRepository(DbContext, new TimeProvider());

            _transactionScope = new TransactionScope();
            using (_transactionScope)
            {
                TestCustomer = new Customer
                                   {
                                       CustomerType = DbContext.CustomerTypes.FirstOrDefault(),
                                       GooglePlacesURL = "GooglePlacesURL",
                                       TwitterHandle = "TwitterHandle",
                                       WebsiteURL = "WebsiteURL",
                                       ListName = "ListName",
                                       Name = "Name",
                                       ParentCustomerId = 0,
                                       Phone = "555-555-5555",
                                   };

                DbContext.Customers.AddObject(TestCustomer);

                TestDocument = new Document
                                   {
                                       Title = "TestTitle",
                                       Body = "This is a test body",
                                       CreatedByUsername = "******",
                                       CreatedDate = new DateTime(2011, 1, 1),
                                   };

                DbContext.Documents.AddObject(TestDocument);

                DbContext.SaveChanges();
            }
        }
        protected override void Context()
        {
            Username = "******";
            base.Context();

            _saveDocumentInputModel = new SaveDocumentInputModel
                                          {
                                              Title = "some title",
                                              Body = "some html to save",
                                          };

            _documentReturnedFromMappingEngine = new Document
                                                     {
                                                         Title = _saveDocumentInputModel.Title,
                                                         Body = _saveDocumentInputModel.Body,
                                                     };

            MappingEngine.Stub(
                x =>
                x.Map<SaveDocumentInputModel, Document>(Arg<SaveDocumentInputModel>.Is.Equal(_saveDocumentInputModel)))
                .Return(_documentReturnedFromMappingEngine);

            _documentReturnedFromDocumentSaver = new Document
                                                     {
                                                         DocumentId = 7,
                                                         Title = _saveDocumentInputModel.Title,
                                                         Body = _saveDocumentInputModel.Body,
                                                     };

            DocumentSaver.Stub(
                x =>
                x.Execute(Arg<string>.Is.Equal(Username), Arg<Document>.Is.Equal(_documentReturnedFromMappingEngine)))
                .Return(_documentReturnedFromDocumentSaver);

            _saveDocumentViewModelReturnedFromMappingEngine = new SaveDocumentViewModel
                                                                  {
                                                                      Title = _documentReturnedFromDocumentSaver.Title,
                                                                      Body = _documentReturnedFromDocumentSaver.Body,
                                                                      DocumentId =
                                                                          _documentReturnedFromDocumentSaver.DocumentId,
                                                                  };
            MappingEngine.Stub(
                x => x.Map<Document, SaveDocumentViewModel>(Arg<Document>.Is.Equal(_documentReturnedFromDocumentSaver)))
                .Return(_saveDocumentViewModelReturnedFromMappingEngine);

            _expectedSaveDocumentViewModel = new SaveDocumentViewModel
                                                 {
                                                     Title = _saveDocumentViewModelReturnedFromMappingEngine.Title,
                                                     Body = _saveDocumentViewModelReturnedFromMappingEngine.Body,
                                                     DocumentId =
                                                         _saveDocumentViewModelReturnedFromMappingEngine.DocumentId,
                                                 };
        }
        protected override void Context()
        {
            base.Context();

            _document = Builder<Document>.CreateNew().Build();

            AuthorizationService.Stub(
                x => x.CanExecute(Arg<string>.Is.Equal(Username), Arg<string>.Is.Equal("CreateDocument")))
                .Return(true);

            _validationResultReturnedFromValidator = new ValidationResult();
            Validator.Stub(x => x.Validate(Arg<Document>.Is.Equal(_document)))
                .Return(_validationResultReturnedFromValidator);

            _documentReturnedFromRepository = new Document
                                                  {
                                                      Body = _document.Body,
                                                      CreatedByUsername = Username,
                                                      CreatedDate = new DateTime(2011, 1, 1),
                                                      CustomerId = 7,
                                                      CustomerName = "some customer name",
                                                      DocumentId = 123,
                                                      Title = _document.Title,
                                                  };

            DocumentRepository.Stub(x => x.Save(Arg<string>.Is.Equal(Username), Arg<Document>.Is.Anything))
                .Return(_documentReturnedFromRepository);

            _expectedDocument = new Document
                                    {
                                        Body = _documentReturnedFromRepository.Body,
                                        CreatedByUsername = _documentReturnedFromRepository.CreatedByUsername,
                                        CreatedDate = _documentReturnedFromRepository.CreatedDate,
                                        CustomerId = _documentReturnedFromRepository.CustomerId,
                                        CustomerName = _documentReturnedFromRepository.CustomerName,
                                        DocumentId = _documentReturnedFromRepository.DocumentId,
                                        Title = _documentReturnedFromRepository.Title,
                                    };
        }
Ejemplo n.º 4
0
        private ProcessedDocument MapDocument(Document document,
                                              CustomerDocumentFieldValues customerDocumentFieldValues)
        {
            string documentBody = document.Body;
            const string pattern = @"\$\((?'property'\S+?)\)";

            Func<Match, Dictionary<String, String>, String> RegexMatchEvaluator =
                (Match match, Dictionary<String, String> customerFieldValues) =>
                    {
                        string propertyName = match.Groups["property"].Value;
                        return customerFieldValues[propertyName];
                    };

            documentBody = Regex.Replace(documentBody, pattern,
                                         new MatchEvaluator(
                                             match =>
                                             RegexMatchEvaluator(match, customerDocumentFieldValues.DocumentFields)),
                                         RegexOptions.ExplicitCapture);

            return new ProcessedDocument
                       {
                           Title = document.Title,
                           Body = documentBody,
                       };
        }
Ejemplo n.º 5
0
        private IEnumerable<string> GetDocumentFields(Document document)
        {
            if (document.Body != null)
            {
                const string pattern = @"\$\((?'property'\S+?)\)";
                IEnumerable<string> documentVariableKeys = from Match match in Regex.Matches(document.Body, pattern)
                                                           select match.Groups[1].Value;

                return documentVariableKeys.ToList();
            }
            return new List<string>();
        }
Ejemplo n.º 6
0
        public JsonResult SendAll(Document doc)
        {
            int id = doc.DocumentId;
            Document document = _documentRepository.GetById(id);

            List<CustomerDocumentURL> curls = _documentRepository.GetCustomerDocumentURLs(id);
            IEnumerable<Customer> customers =
                _customerRepository.GetByCustomersByIds(curls.Select(c => c.CustomerId).ToList());
            bool result = true;
            foreach (CustomerDocumentURL curl in curls)
            {
                Customer customer = customers.FirstOrDefault(c => c.CustomerId == curl.CustomerId);
                result = SendCURL(curl, customer) && result;
            }

            var res = new Dictionary<String, Object> {{"success", true}};
            return Json(res);
        }
 protected override void BecauseOf()
 {
     _result = DocumentSaver.Execute(Username, _document);
 }