Ejemplo n.º 1
0
        /// <summary>
        /// The create anonymous customer with key.
        /// </summary>
        /// <returns>
        /// The <see cref="IAnonymousCustomer"/>.
        /// </returns>
        public IAnonymousCustomer CreateAnonymousCustomerWithKey()
        {
            var anonymous = new AnonymousCustomer();

            if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs<IAnonymousCustomer>(anonymous), this))
            {
                anonymous.WasCancelled = true;
                return anonymous;
            }

            using (new WriteLock(Locker))
            {
                var uow = _uowProvider.GetUnitOfWork();
                using (var repository = _repositoryFactory.CreateAnonymousCustomerRepository(uow))
                {
                    repository.AddOrUpdate(anonymous);
                    uow.Commit();
                }
            }

            Created.RaiseEvent(new Events.NewEventArgs<IAnonymousCustomer>(anonymous), this);

            return anonymous;
        }
 public static IAnonymousCustomer AnonymousCustomerForInserting()
 {
     var anonymous = new AnonymousCustomer();
     return anonymous;
 }
Ejemplo n.º 3
0
        public void NewInvoiceReturnsCorrectInvoice()
        {
            //// Arrange
            Guid key = Guid.NewGuid();
            bool wasCalled = false;
            int id = 1;
            Invoice invoice = CreateFakeInvoice(id, key);

            var customer = new AnonymousCustomer(100.00m, 100.00m, DateTime.Now);
                customer.FirstName = "John";
                customer.LastName = "Jones";
                customer.Email = "*****@*****.**";
                customer.MemberId = 1004;

            var address = new CustomerAddress(customer, "Address")
            {
                Address1 = "123 Test St.",
                Address2 = "Apt 1",
                Locality = "USA",
                Region = "USA",
                PostalCode = "97333-0123",
                CountryCode = "US",
                Phone = "555-555-5555",
                Company = "Test Company"
            };
            var invoiceStatus = new InvoiceStatus()
            {
                Alias = "unpaid",
                Name = "Unpaid",
                Active = true,
                Reportable = true,
                SortOrder = 1
            };
            var MockInvoiceService = new Mock<IInvoiceService>();
            MockInvoiceService.Setup(cs => cs.CreateInvoice(customer, address, invoiceStatus, "Test Invoice 1")).Returns(invoice).Callback(() => wasCalled = true);

            MerchelloContext merchelloContext = GetMerchelloContext(MockInvoiceService.Object);

            InvoiceApiController ctrl = new InvoiceApiController(merchelloContext, tempUmbracoContext);

            //// Act
            Invoice result = null;
            //Invoice result = ctrl.NewInvoice(customer, address, invoiceStatus, "Test Invoice 1");

            //// Assert
            Assert.AreEqual(invoice, result);
            Assert.True(wasCalled);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create a fake product with fake data for testing
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        private Invoice CreateFakeInvoice(int id, Guid key)
        {
            var customer = new AnonymousCustomer(100.00m, 100.00m, DateTime.Now)
            {
                FirstName = "John",
                LastName = "Jones",
                Email = "*****@*****.**",
                MemberId = 1004,
                Key = key,
                Id = 1001
            };
            var address = new CustomerAddress(customer, "Address")
            {
                Address1 = "123 Test St.",
                Address2 = "Apt 1",
                Locality = "USA",
                Region = "USA",
                PostalCode = "97333-0123",
                CountryCode = "US",
                Phone = "555-555-5555",
                Company = "Test Company"
            };

            var invoiceStatus = new InvoiceStatus()
            {
                Alias = "unpaid",
                Name = "Unpaid",
                Active = true,
                Reportable = true,
                SortOrder = 1
            };
            return new Invoice(customer, address, invoiceStatus, 100.00m)
            {
                Id = id
            };
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Crates an <see cref="IAnonymousCustomer"/> and saves it to the database
 /// </summary>
 /// <returns><see cref="IAnonymousCustomer"/></returns>
 public IAnonymousCustomer CreateAnonymousCustomerWithKey()
 {
     var anonymous = new AnonymousCustomer();
     using (new WriteLock(Locker))
     {
         var uow = _uowProvider.GetUnitOfWork();
         using (var repository = _repositoryFactory.CreateAnonymousCustomerRepository(uow))
         {
             repository.AddOrUpdate(anonymous);
             uow.Commit();
         }
     }
     return anonymous;
 }