예제 #1
0
        public void GetPhoneNumber_FindNumbers_ReturnListOfPhoneNumber()
        {
            //Arrange
            var mockRepo = new Mock <IPhoneNumber>();

            var numbers = new List <PhoneNumber>()
            {
                new PhoneNumber()
                {
                    TelePhoneNumber = "0411111111", IsActivate = true
                },
                new PhoneNumber()
                {
                    TelePhoneNumber = "0411111112", IsActivate = true
                }
            };

            mockRepo.Setup(repo => repo.GetPhoneNumbers())
            .Returns(numbers);

            var controller = new PhoneNumberController(mockRepo.Object);

            //Act
            var result = controller.GetPhoneNumber();

            //Assert
            var okObjectResult = Assert.IsType <OkObjectResult>(result.Result);
            var numberList     = Assert.IsType <List <PhoneNumber> >(okObjectResult.Value);

            Assert.Equal("0411111111", numberList[0].TelePhoneNumber);
            Assert.True(numberList[0].IsActivate);
        }
예제 #2
0
        public Dictionary<string, object> GetPhoneByForeignId( string foreignId )
        {
            PhoneNumberController controller = new PhoneNumberController( Service );

            var phoneNumber = controller.GetByForeignId( foreignId );

            return ToDictionary( phoneNumber );
        }
예제 #3
0
        public void GetPhoneNumber_CouldNotFindNumbers_ReturnNotFound()
        {
            //Arrange
            var mockRepo = new Mock <IPhoneNumber>();

            mockRepo.Setup(repo => repo.GetPhoneNumbers())
            .Returns((IList <PhoneNumber>)null);

            var controller = new PhoneNumberController(mockRepo.Object);

            //Act
            var result = controller.GetPhoneNumber();

            //Assert
            var notFoundObjectResult = Assert.IsType <NotFoundResult>(result.Result);
        }
예제 #4
0
        public void ActivatePhoneNumber_InCorrectNumber_ReturnFalse()
        {
            //Arrange
            var mockRepo = new Mock <IPhoneNumber>();

            mockRepo.Setup(repo => repo.ActivePhoneNumber(It.IsAny <string>()))
            .Returns(false);

            var controller = new PhoneNumberController(mockRepo.Object);

            //Act
            var result = controller.ActivatePhoneNumber("test");

            //Assert
            var okObjectResult = Assert.IsType <OkObjectResult>(result.Result);
            var isActivate     = Assert.IsType <bool>(okObjectResult.Value);

            Assert.False(isActivate);
        }
예제 #5
0
        public int? SavePhone(string number, int personId, int numbertypeValueId, string extension = null, bool isSystem = false, bool isMessagingEnabled = false, 
                bool isUnlisted = false, string description = null, string countryCode = "1", string foreignId = null, int? phoneNumberId = null )
        {
            PhoneNumber phone = null;
            PhoneNumberController controller = new PhoneNumberController( Service );

            if ( phoneNumberId != null )
            {
                phone = controller.GetById( (int)phoneNumberId );

                if ( phone == null )
                {
                    return null;
                }
            }
            else
            {
                phone = new PhoneNumber();
            }

            string cleanPhone = PhoneNumber.CleanNumber( number );

            phone.PersonId = personId;
            phone.Number = cleanPhone;
            phone.Extension = extension;
            phone.CountryCode = countryCode;
            phone.NumberTypeValueId = numbertypeValueId;
            phone.IsSystem = isSystem;
            phone.IsMessagingEnabled = isMessagingEnabled;
            phone.IsUnlisted = isUnlisted;
            phone.Description = description;
            phone.ForeignId = foreignId;
            var ncc = phone.NumberFormattedWithCountryCode;
            //phone.NumberFormatted = System.Text.RegularExpressions.Regex.Replace( cleanPhone, @"^(\d{3})(\d{3})(\d{4})$", @"($1) $2-$3" );

            return SavePhone( phone );
        }
 public PhoneNumerControllerTest()
 {
     serviceMock = new Mock <IPhoneService>();
     controller  = new PhoneNumberController(serviceMock.Object);
 }
 public static void SetUpClass()
 {
     controller = GetClient().PhoneNumber;
 }
예제 #8
0
        private int? SavePhone( PhoneNumber p )
        {
            PhoneNumberController controller = new PhoneNumberController( Service );

            if ( p.Id == 0 )
            {
                p.CreatedByPersonAliasId = Service.LoggedInPerson.PrimaryAliasId;
                controller.Add( p );
            }
            else
            {
                p.ModifiedByPersonAliasId = Service.LoggedInPerson.PrimaryAliasId;
                controller.Update( p );
            }

            return controller.GetByGuid( p.Guid ).Id;
        }
예제 #9
0
        private PhoneNumber GetPhoneById( int id )
        {
            PhoneNumberController controller = new PhoneNumberController( Service );

            return controller.GetById( id );
        }