Exemplo n.º 1
0
        public void GetVolunteerListAdvancedSearch_Success_Test()
        {
            // Arrange
            string name   = null;
            int?   gender = null;

            System.DateTime?birthDateFrom         = null;
            System.DateTime?birthDateTo           = null;
            string          occupation            = null;
            string          employer              = null;
            string          phone                 = null;
            string          email                 = null;
            string          identityCardNumber    = null;
            int?            countryId             = null;
            string          friendOrFamilyContact = null;
            int?            photo                 = null;
            int?            addressId             = null;
            bool?           hasCar                = null;
            bool?           hasDriverLicense      = null;
            bool?           hasBike               = null;
            string          vehicleMake           = null;
            string          vehicleModel          = null;
            bool?           active                = null;

            //int pageIndex = 0;
            int pageSize = 10;

            // list
            IList <R_Volunteer> list = new List <R_Volunteer>();

            for (int i = 1; i <= pageSize; i++)
            {
                list.Add(SampleVolunteer(i));
            }

            // create mock for repository
            var mock = new Mock <IVolunteerRepository>();

            mock.Setup(s => s.GetVolunteerListAdvancedSearch(
                           Moq.It.IsAny <string>()             // name
                           , Moq.It.IsAny <int?>()             // gender
                           , Moq.It.IsAny <System.DateTime?>() // birthDateFrom
                           , Moq.It.IsAny <System.DateTime?>() // birthDateTo
                           , Moq.It.IsAny <string>()           // occupation
                           , Moq.It.IsAny <string>()           // employer
                           , Moq.It.IsAny <string>()           // phone
                           , Moq.It.IsAny <string>()           // email
                           , Moq.It.IsAny <string>()           // identityCardNumber
                           , Moq.It.IsAny <int?>()             // countryId
                           , Moq.It.IsAny <string>()           // friendOrFamilyContact
                           , Moq.It.IsAny <int?>()             // photo
                           , Moq.It.IsAny <int?>()             // addressId
                           , Moq.It.IsAny <bool?>()            // hasCar
                           , Moq.It.IsAny <bool?>()            // hasDriverLicense
                           , Moq.It.IsAny <bool?>()            // hasBike
                           , Moq.It.IsAny <string>()           // vehicleMake
                           , Moq.It.IsAny <string>()           // vehicleModel
                           , Moq.It.IsAny <bool?>()            // active
                           )).Returns(list);

            // service
            VolunteerService volunteerService = new VolunteerService();

            VolunteerService.Repository = mock.Object;

            // Act
            var resultList = volunteerService.GetVolunteerListAdvancedSearch(
                name
                , gender
                , birthDateFrom
                , birthDateTo
                , occupation
                , employer
                , phone
                , email
                , identityCardNumber
                , countryId
                , friendOrFamilyContact
                , photo
                , addressId
                , hasCar
                , hasDriverLicense
                , hasBike
                , vehicleMake
                , vehicleModel
                , active
                );

            VolunteerDTO result = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.VolunteerId);
        }