protected override void Context()
        {
            base.Context();

            _createCustomerRequest = Builder<CreateCustomerRequest>.CreateNew().Build();

            AuthorizationService.Stub(
                x => x.CanExecute(Arg<string>.Is.Equal(Username), Arg<Type>.Is.Equal(typeof (CreateCustomerRequest)))).
                Return(true);

            CreateCustomerRequestValidator.Stub(
                x => x.Validate(Arg<CreateCustomerRequest>.Is.Equal(_createCustomerRequest)))
                .Return(new ValidationResult());

            CustomerRepository.Stub(x => x.NameExists(Arg<string>.Is.Equal(_createCustomerRequest.Name)))
                .Return(false);

            CustomerRepository.Stub(
                x => x.Create(Arg<CreateCustomerRequest>.Is.Equal(_createCustomerRequest)));

            _expectedResponse = new CreateCustomerResponse
                                    {
                                        Success = true,
                                    };
        }
Example #2
0
        public CreateCustomerResponse Execute(string username, CreateCustomerRequest createCustomerRequest)
        {
            if (!_authorizationService.CanExecute(username, "CreateCustomers"))
                return new CreateCustomerResponse(new List<string>
                                                      {
                                                          "User is not authorized to Create Customers.",
                                                      })
                           {
                               Success = false,
                           };

            var validationResult = _createCustomerRequestValidator.Validate(createCustomerRequest);
            if(!validationResult.IsValid)
                return new CreateCustomerResponse(validationResult.Errors.Select(x=>x.ErrorMessage))
                {
                    Success = false,
                };

            if (_customerRepository.NameExists(createCustomerRequest.Name))
                return
                    new CreateCustomerResponse(new List<string>
                                                   {
                                                       "The username " + createCustomerRequest.Name + " is unavailable."
                                                   })
                        {
                            Success = false,
                        };

            _customerRepository.Create(createCustomerRequest);

            return new CreateCustomerResponse {Success = true,};
        }
        public void Create(CreateCustomerRequest createCustomerRequest)
        {
            using (var context = new PRToolsEntities())
            {
                var customerEntity = new Customer
                                         {

                                             FacebookURL = createCustomerRequest.FacebookUrl,
                                             ZLastName = createCustomerRequest.ZLastName,
                                             ZFirstName = createCustomerRequest.ZFirstName,
                                             WebsiteURL = createCustomerRequest.WebsiteUrl,
                                             TwitterHandle = createCustomerRequest.TwitterHandle,
                                             Phone = createCustomerRequest.Phone,
                                             Name = createCustomerRequest.Name,
                                             ListName = createCustomerRequest.ListName,
                                             GooglePlacesURL = createCustomerRequest.GooglePlacesUrl,
                                         };

                if (createCustomerRequest.ParentCustomerId > 0)
                    customerEntity.ParentCustomerId = createCustomerRequest.ParentCustomerId;

                if (createCustomerRequest.AccountManagerId > 0)
                    customerEntity.AccountManagerId = createCustomerRequest.AccountManagerId;

                if (createCustomerRequest.CustomerType != Domain.CustomerType.Undefined)
                {
                    string customerTypeKey = createCustomerRequest.CustomerType.ToString();
                    CustomerType customerType =
                        context.CustomerTypes.FirstOrDefault(
                            x => x.CustomerTypeKey == customerTypeKey);

                    customerEntity.CustomerType = customerType;
                }

                customerEntity.Addresses.Add(new Address
                                                 {
                                                     Street = createCustomerRequest.MailingAddress.Street,
                                                     AdditionalInfo =
                                                         createCustomerRequest.MailingAddress.AdditionalInfo,
                                                     City = createCustomerRequest.MailingAddress.City,
                                                     State = createCustomerRequest.MailingAddress.State,
                                                     Zipcode = createCustomerRequest.MailingAddress.Zipcode,
                                                     AddressType = "Mailing",
                                                 });

                foreach (Domain.Contact contact in createCustomerRequest.Contacts)
                {
                    customerEntity.Contacts.Add(new Contact
                                                    {
                                                        FirstName = contact.FirstName,
                                                        LastName = contact.LastName,
                                                        Phone = contact.Phone,
                                                        Email = contact.Email,
                                                    });
                }

                context.Customers.AddObject(customerEntity);
                context.SaveChanges();
            }
        }
        protected override void Context()
        {
            base.Context();

            _createCustomerRequest = Builder<CreateCustomerRequest>.CreateNew().Build();

            AuthorizationService.Stub(
                x => x.CanExecute(Arg<string>.Is.Equal(Username), Arg<Type>.Is.Equal(typeof (CreateCustomerRequest)))).
                Return(false);

            _expectedResponse =
                new CreateCustomerResponse(new List<string>
                                               {
                                                   "User is not authorized to Create Franchise",
                                               })
                    {
                        Success = false,
                    };
        }
        protected override void Context()
        {
            base.Context();

            _createCustomerRequest = Builder<CreateCustomerRequest>.CreateNew().Build();

            AuthorizationService.Stub(
                x => x.CanExecute(Arg<string>.Is.Equal(Username), Arg<Type>.Is.Equal(typeof (CreateCustomerRequest)))).
                Return(true);

            _validationResponse = new ValidationResult(new List<ValidationFailure>
                                                           {
                                                               new ValidationFailure("some property", "some error")
                                                           });
            CreateCustomerRequestValidator.Stub(
                x => x.Validate(Arg<CreateCustomerRequest>.Is.Equal(_createCustomerRequest)))
                .Return(_validationResponse);

            _expectedResponse = new CreateCustomerResponse(_validationResponse.Errors.Select(x => x.ErrorMessage))
                                    {
                                        Success = false,
                                    };
        }
        protected override void Context()
        {
            Username = "******";
            base.Context();

            _createCustomerInputModel = Builder<CreateCustomerInputModel>.CreateNew().Build();
            _createCustomerRequestReturnedFromMappingEngine = new CreateCustomerRequest
                                                                  {
                                                                      CustomerType = _createCustomerInputModel.CustomerType,
                                                                      FacebookUrl = _createCustomerInputModel.FacebookUrl,
                                                                      GooglePlacesUrl = _createCustomerInputModel.GooglePlacesUrl,
                                                                      ListName = _createCustomerInputModel.ListName,
                                                                      Name = _createCustomerInputModel.Name,
                                                                      ParentCustomerId = _createCustomerInputModel.ParentCustomerId,
                                                                      Phone = _createCustomerInputModel.Phone,
                                                                      TwitterHandle = _createCustomerInputModel.TwitterHandle,
                                                                      WebsiteUrl = _createCustomerInputModel.WebsiteUrl,
                                                                      MailingAddress = new Address
                                                                                           {
                                                                                               City = _createCustomerInputModel.City,
                                                                                               State = _createCustomerInputModel.State,
                                                                                               Street = _createCustomerInputModel.Street,
                                                                                               AdditionalInfo = _createCustomerInputModel.AdditionalInfo,
                                                                                               Zipcode = _createCustomerInputModel.Zipcode,
                                                                                           },
                                                                  };

            MappingEngine.Stub(
                x =>
                x.Map<CreateCustomerInputModel, CreateCustomerRequest>(
                    Arg<CreateCustomerInputModel>.Is.Equal(_createCustomerInputModel)))
                .Return(_createCustomerRequestReturnedFromMappingEngine);

            _contactReturnedFromMappingEngine = new Contact
                                                    {
                                                        Email = _createCustomerInputModel.ContactEmail,
                                                        FirstName = _createCustomerInputModel.ContactFirstName,
                                                        IsPrimary = true,
                                                        LastName = _createCustomerInputModel.ContactLastName,
                                                        Phone = _createCustomerInputModel.ContactPhone,
                                                    };
            MappingEngine.Stub(
                x =>
                x.Map<CreateCustomerInputModel, Contact>(
                    Arg<CreateCustomerInputModel>.Is.Equal(_createCustomerInputModel)))
                .Return(_contactReturnedFromMappingEngine);

            CustomerCreator.Stub(
                x => x.Execute(Arg<string>.Is.Equal(Username), Arg<CreateCustomerRequest>.Is.Equal(_createCustomerRequestReturnedFromMappingEngine)))
                .WhenCalled(x => _requestPassedToCustomerService = x.Arguments[1] as CreateCustomerRequest)
                .Return(new CreateCustomerResponse
                            {
                                Success = true,
                            });

            _expectedRequest = new CreateCustomerRequest
                                   {
                                       Name = _createCustomerInputModel.Name,
                                       Phone = _createCustomerInputModel.Phone,
                                       MailingAddress = new Address
                                                            {
                                                                Street = _createCustomerInputModel.Street,
                                                                AdditionalInfo =
                                                                    _createCustomerInputModel.AdditionalInfo,
                                                                City = _createCustomerInputModel.City,
                                                                State = _createCustomerInputModel.State,
                                                                Zipcode = _createCustomerInputModel.Zipcode,
                                                            },
                                       CustomerType = _createCustomerInputModel.CustomerType,
                                       ListName = _createCustomerInputModel.ListName,
                                       TwitterHandle = _createCustomerInputModel.TwitterHandle,
                                       GooglePlacesUrl = _createCustomerInputModel.GooglePlacesUrl,
                                       WebsiteUrl = _createCustomerInputModel.WebsiteUrl,
                                       ParentCustomerId = _createCustomerInputModel.ParentCustomerId,
                                       FacebookUrl = _createCustomerInputModel.FacebookUrl
                                   };

            _expectedRequest.AddContact(new Contact
                                            {
                                                FirstName = _createCustomerInputModel.ContactFirstName,
                                                LastName = _createCustomerInputModel.ContactLastName,
                                                Phone = _createCustomerInputModel.ContactPhone,
                                                Email = _createCustomerInputModel.ContactEmail,
                                                IsPrimary = true,
                                            });
        }