Ejemplo n.º 1
0
        public void GetByIdBadId()
        {
            //Arrange
            int customerIdGood = 1;
            int customerIdBad  = 2;

            var mock     = new Mock <ICustomerRepository>();
            var customer = new API.DAL.Models.Customer
            {
                Id           = 1,
                PersonTypeId = 2,
                ClinicId     = 1,
                FirstName    = "Admin",
                LastName     = "Jensen",
                PhoneNo      = "22222222",
                Email        = "*****@*****.**",
                PasswordHash = "password",
                CityName     = "Karup J",
            };

            mock.Setup(x => x.GetById(customerIdGood)).Returns(customer);
            var customerController = new CustomerController(mock.Object);
            var expectedCustomer   = mock.Object.GetById(customerIdBad);

            //Act
            var actionResult = customerController.GetById(customerIdBad);
            var result       = actionResult as OkNegotiatedContentResult <API.Models.Customer>;

            //Assert
            //Assert.AreEqual(actionResult, (int)HttpStatusCode.OK);
            Assert.IsNull(expectedCustomer);
            Assert.IsNull(result);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new customer
 /// </summary>
 /// <param name="customer">The customer that is being created</param>
 // POST: api/Customer
 public IHttpActionResult Post([FromBody] API.DAL.Models.Customer customer)
 {
     try
     {
         _customerRepository.Create(customer);
     }
     catch (DataAccessException)
     {
         return(NotFound());
     }
     return(Ok());
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Converts customer DAL model to  customer API model, and adds api urls instead of ids
 /// </summary>
 /// <param name="customer">Customer to convert</param>
 /// <returns>Converted Customer</returns>
 private Customer BuildCustomer(API.DAL.Models.Customer customer)
 {
     return(new Customer
     {
         Id = customer.Id,
         Clinic = customer.ClinicId != 0 ? ApiHelper.BuildClinicURL(customer.ClinicId) : null,
         Practitioner = customer.PractitionerId != 0 ? ApiHelper.BuildPractitionerURL(customer.PractitionerId) : null,
         RehabProgram = customer.RehabProgramId != 0 ? ApiHelper.BuildRehabProgramURL(customer.RehabProgramId) : null,
         City = customer.CityName,
         FirstName = customer.FirstName,
         LastName = customer.LastName,
         PhoneNo = customer.PhoneNo,
         Email = customer.Email,
         Address = customer.Address,
         ZipCode = customer.ZipCode
     });
 }
Ejemplo n.º 4
0
        public void CustomerLoginSuccess()
        {
            //Arrange
            string customerEmailGood    = "*****@*****.**";
            string customerPasswordGood = "password";

            var mock     = new Mock <ICustomerRepository>();
            var customer = new API.DAL.Models.Customer
            {
                Id           = 1,
                PersonTypeId = 2,
                ClinicId     = 1,
                FirstName    = "Admin",
                LastName     = "Jensen",
                PhoneNo      = "22222222",
                Email        = "*****@*****.**",
                PasswordHash = "password",
                CityName     = "Karup J",
            };

            mock.Setup(x => x.IsAuthorized(customerEmailGood, customerPasswordGood)).Returns(customer);
            var customerController = new CustomerController(mock.Object);
            var expectedCustomer   = mock.Object.IsAuthorized(customerEmailGood, customerPasswordGood);

            //Act

            LoginInfo login = new LoginInfo();

            login.Email    = customerEmailGood;
            login.Password = customerPasswordGood;

            var actionResult = customerController.Login(login);
            var result       = actionResult as OkNegotiatedContentResult <API.Models.Customer>;

            //Assert
            //Assert.AreEqual(actionResult, (int)HttpStatusCode.OK);
            Assert.IsNotNull(result);
            Assert.AreEqual(expectedCustomer.Id, result.Content.Id);
        }
Ejemplo n.º 5
0
 public void Put([FromBody] API.DAL.Models.Customer customer)
 {
     _customerRepository.Update(customer);
 }