Exemple #1
0
        //  Creates a new customer

        /* Unused, CustomerUpdateOrAdd does what we want.
         * public int CustomerCreate(Customers customer)
         * {
         *  using (var connection = this.getConnection())
         *  {
         *      DynamicParameters ParamsForProc = ConvertCustomerToParams(customer);
         *      ParamsForProc.Add("@newid", DbType.Int32, direction: ParameterDirection.ReturnValue);
         *      connection.Execute("Customer_Create", ParamsForProc, commandType: CommandType.StoredProcedure);
         *      return ParamsForProc.Get<int>("@newid");
         *  }
         * }
         */

        /// <summary>
        ///     Updates an existing customer
        /// </summary>
        /// <param name="customer">Customer Object To Update</param>
        /// <returns>Returns TRUE</returns>
        public int CustomerUpdateOrAdd(Customers customer)
        {
            int newId = this.CustomerUpdateOrAddLocal(customer);

            // Put a customer create message into the queue
            if (customer.CustomerGuid == null)
            {
                // New customer!
                CustomerCreateHandler msg = new CustomerCreateHandler();
                msg.customer = customer;
                msg.EnqueueSelfAsMessage(WorkerRole.privateQueue);
            }
            else
            {
                CustomerUpdateHandler msg = new CustomerUpdateHandler();
                msg.customer = customer;
                msg.EnqueueSelfAsMessage(WorkerRole.privateQueue);
            }
            //
            return(newId);
        }
Exemple #2
0
        public async Task Handle_CreateNonExistingCustomer_ShouldReturnNewCustomer()
        {
            var handler = new CustomerCreateHandler(Mapper, _mockRepo.Object);

            var name  = "pedro";
            var email = "*****@*****.**";

            var customer = new Customer
            {
                Email = email,
                Id    = 1,
                Name  = name
            };

            MockRepo(customer);

            var result = await handler.Handle(new CustomerCreateRequest { Email = email, Name = name }, default);

            Assert.Equal(email, result.Email);
            Assert.Equal(name, result.Name);
            Assert.Equal(5, result.Id);
            Assert.IsType <CustomerModel>(result);
        }
Exemple #3
0
        public async Task Handle_CreateExistingCustomer_ShouldReturnBusinessException()
        {
            var handler = new CustomerCreateHandler(Mapper, _mockRepo.Object);

            var name  = "pedro";
            var email = "*****@*****.**";

            var customer = new Customer
            {
                Email = email,
                Id    = 1,
                Name  = name
            };

            _mockRepo
            .Setup(repo => repo.Customer.FindSingle(It.IsAny <Expression <Func <Customer, bool> > >(), It.IsAny <List <string> >()))
            .Returns(customer)
            .Verifiable();

            await Assert.ThrowsAsync <BusinessException>(() => handler.Handle(new CustomerCreateRequest {
                Email = email, Name = name
            }, default));
        }