예제 #1
0
 public PersonalInformationsController(ILog logger, IPersonalInformationBL personalinformationBL, ICommonBL commonBL)
     : base(logger)
 {
     _logger = logger;
     _personalinformationBL = personalinformationBL;
     _commonBL = commonBL;
 }
        public void SetUp()
        {
            _fixture = new Fixture();
            var mockBL       = new Mock <IPersonalInformationBL>();
            var mockCommonBL = new Mock <ICommonBL>();
            var mockLog      = new Mock <ILog>();

            _entities = _fixture.Build <PersonalInformation>().CreateMany(100).ToList();

            if (_entities.All(x => x.Id != 1))
            {
                _entities.Add(_fixture.Build <PersonalInformation>().With(x => x.Id, 1).Create());
            }

            List <FilterOption> filters = new List <FilterOption>();


            List <string> selectColumnsList = new List <string>
            {
                "Id",
                "FirstName",
                "LastName",
                "SiteName",
                "Email",
                "Country",
                "PhoneNumber",
                "IdPhoto",
                "Description",
                "FaceBook",
                "Twitter",
                "GooglePlus"
            };

            int page           = 1;
            int pageSize       = 10;
            var paginationList = _entities.Skip((page - 1) * pageSize).Take(pageSize).ToList();

            mockBL.Setup(mr => mr.GetAll(filters, page, pageSize, "id", "asc", selectColumnsList))
            .Returns(paginationList);
            mockBL.Setup(mr => mr.CountGetAll(filters, page, pageSize))
            .Returns(paginationList.Count);
            mockBL.Setup(mr => mr.GetAll()).Returns(_entities);
            mockBL.Setup(mr => mr.Get(It.IsAny <int>()))
            .Returns((int id) => { return(_entities.FirstOrDefault(p => p.Id == id)); });

            mockBL.Setup(r => r.Insert(It.IsAny <PersonalInformation>()))
            .Callback <PersonalInformation>(newEntity =>
            {
                int maxEntityId            = _entities.Max(x => x.Id);
                int nextEntityId           = maxEntityId + 1;
                newEntity.Id               = nextEntityId;
                newEntity.CreationDate     = DateTime.Now;
                newEntity.LastActivityDate = DateTime.Now;
                _entities.Add(newEntity);
            });

            mockBL.Setup(r => r.Update(It.IsAny <PersonalInformation>()))
            .Callback <PersonalInformation>(x =>
            {
                x.LastActivityDate = DateTime.Now;
            });
            List <Setting> states = new List <Setting>
            {
                new Setting {
                    Id = 1, Name = "Active"
                },
                new Setting {
                    Id = 2, Name = "Inactive"
                }
            };

            mockCommonBL.Setup(r => r.GetByIdCategorySetting((int)EnumCategorySetting.States))
            .Returns(states);

            _commonBL = mockCommonBL.Object;
            _entityBL = mockBL.Object;
            _logger   = mockLog.Object;

            Mapper.Initialize(cfg => { cfg.CreateMap <PersonalInformationModel, PersonalInformation>(); });
        }