public void PutCustomerUpdatesRepository()
		{
			//// Arrange
			bool wasCalled = false;
			Guid customerKey = Guid.NewGuid();

			AnonymousCustomer anonymousCustomer = CreateFakeCustomer(customerKey);

			var MockCustomerService = new Mock<ICustomerService>();														   
			MockCustomerService.Setup(cs => cs.Save(anonymousCustomer, It.IsAny<bool>())).Callback(() => wasCalled = true);

			MerchelloContext merchelloContext = GetMerchelloContext(MockCustomerService.Object);

			CustomerApiController ctrl = new CustomerApiController(merchelloContext, tempUmbracoContext);
			ctrl.Request = new HttpRequestMessage();
			ctrl.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

			//// Act
			HttpResponseMessage response = ctrl.PutCustomer(anonymousCustomer);

			//// Assert
			Assert.AreEqual(System.Net.HttpStatusCode.OK, response.StatusCode);

			Assert.True(wasCalled);
		}
        public async Task <IActionResult> PostAnonymousCustomer([FromBody] AnonymousCustomer anonymousCustomer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.AnonymousCustomer.Add(anonymousCustomer);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (AnonymousCustomerExists(anonymousCustomer.AnonymousCustomerId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetAnonymousCustomer", new { id = anonymousCustomer.AnonymousCustomerId }, anonymousCustomer));
        }
Exemplo 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);
        }
Exemplo n.º 4
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);
        }
        public void GetCustomerByKeyReturnsCorrectItemFromRepository()
        {
            // Arrange
            int customerId = 20;

			AnonymousCustomer anonymousCustomer = CreateFakeCustomer(customerId);

            var MockCustomerService = new Mock<ICustomerService>();
            MockCustomerService.Setup(cs => cs.GetById(customerId)).Returns(anonymousCustomer);

			MerchelloContext merchelloContext = GetMerchelloContext(MockCustomerService.Object);

            CustomerApiController ctrl = new CustomerApiController(merchelloContext, tempUmbracoContext);

            //// Act
            var result = ctrl.GetCustomer(customerId);

            //// Assert
			Assert.AreEqual(anonymousCustomer, result);
        }
		/// <summary>
		/// Test to verify that the proper error response is returned on an error
		/// </summary>
		//[Test]
		public void PutCustomerReturns500WhenRepositoryUpdateReturnsError()
		{
			//// Arrange
			Guid customerKey = Guid.NewGuid();

			AnonymousCustomer anonymousCustomer = CreateFakeCustomer(customerKey);

			var MockCustomerService = new Mock<ICustomerService>();
			MockCustomerService.Setup(cs => cs.Save(anonymousCustomer, It.IsAny<bool>())).Throws<InvalidOperationException>();

			MerchelloContext merchelloContext = GetMerchelloContext(MockCustomerService.Object);

			CustomerApiController ctrl = new CustomerApiController(merchelloContext, tempUmbracoContext);
			ctrl.Request = new HttpRequestMessage();
			ctrl.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

			//// Act
			HttpResponseMessage response = ctrl.PutCustomer(anonymousCustomer);

			//// Assert
			Assert.AreEqual(System.Net.HttpStatusCode.NotFound, response.StatusCode);
		}
Exemplo n.º 7
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
            });
        }
Exemplo n.º 8
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);
        }
        public async Task <IActionResult> PutAnonymousCustomer([FromRoute] string id, [FromBody] AnonymousCustomer anonymousCustomer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != anonymousCustomer.AnonymousCustomerId)
            {
                return(BadRequest());
            }

            _context.Entry(anonymousCustomer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AnonymousCustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }