示例#1
0
        public void MapEventGroup_EntityWithNoAssociated_SomeMapped()
        {
            var entity = new EventGroup
            {
                Id            = 1,
                EventParentId = 1,
                UserId        = "foo",
                Name          = "bar",
                Description   = "baz"
            };
            var expected = new EventGroupModel
            {
                Id            = 1,
                EventParentId = 1,
                Name          = "bar",
                Description   = "baz"
            };

            var actual = target.Map <EventGroupModel>(entity);

            Assert.AreEqual(expected.Id, actual.Id);
            Assert.AreEqual(expected.EventParentId, actual.EventParentId);
            Assert.AreEqual(expected.EventParentName, actual.EventParentName);
            Assert.AreEqual(expected.Name, actual.Name);
            Assert.AreEqual(expected.Description, actual.Description);
        }
示例#2
0
        public int Add(EventGroupModel model)
        {
            try
            {
                var user = new EventGroup()
                {
                    EventId   = model.EventId,
                    GroupId   = model.GroupId,
                    CreatedBy = model.CreatedBy,
                    CreatedOn = UnixTimeBaseClass.UnixTimeNow
                };

                _db.EventGroups.Add(user);
                _db.SaveChanges();

                return(user.EventGroupId);
            }
            catch (Exception ex)
            {
                JavaScriptSerializer js = new JavaScriptSerializer();
                string json             = js.Serialize(model);
                Log.Error("EventGroup - Add - " + json, ex);
                throw;
            }
        }
示例#3
0
 public IActionResult Create([FromBody][CustomizeValidator(RuleSet = Constants.RuleSetNameForInsert)] EventGroupModel model)
 {
     if (ModelState.IsValid)
     {
         service.Insert(model);
         return(CreatedAtRoute("GetEventGroup", new { id = model.Id }, model));
     }
     return(BadRequest(ModelState));
 }
        public void Insert_ThrowsException_HandledByCatchBlock()
        {
            var model       = new EventGroupModel();
            var contextMock = new Mock <IOnTaskDbContext>();

            contextMock.Setup(x => x.InsertEventGroup(It.IsAny <EventGroup>())).Throws <Exception>();
            var target = InitializeTarget(contextMock.Object);

            target.Insert(model);
        }
        public void Update_ThrowsException_HandledByCatchBlock()
        {
            var model = new EventGroupModel {
                Id = 1
            };
            var contextMock = new Mock <IOnTaskDbContext>();

            contextMock.Setup(x => x.GetEventGroupByIdTracked(It.IsAny <int>())).Throws <Exception>();
            var target = InitializeTarget(contextMock.Object);

            target.Update(model);
        }
示例#6
0
 public IActionResult Update(int id, [FromBody][CustomizeValidator(RuleSet = Constants.RuleSetNameForUpdate)] EventGroupModel model)
 {
     if (ModelState.IsValid)
     {
         if (id == model.Id)
         {
             service.Update(model);
             return(NoContent());
         }
         return(BadRequest());
     }
     return(BadRequest(ModelState));
 }
        public void Update_InvalidId_ContextSaveChangesNotCalled()
        {
            var model = new EventGroupModel {
                Id = 1
            };
            var contextMock = new Mock <IOnTaskDbContext>();

            contextMock.Setup(x => x.GetEventGroupByIdTracked(It.Is <int>(y => y == model.Id))).Returns <EventGroup>(null).Verifiable();
            var target = InitializeTarget(contextMock.Object);

            target.Update(model);

            contextMock.Verify();
            contextMock.Verify(x => x.SaveChanges(), Times.Never());
        }
        public void Validate_ValidModel(int?id, int eventParentId, string name, string ruleSet)
        {
            var model = new EventGroupModel
            {
                Id            = id,
                EventParentId = eventParentId,
                Name          = name
            };

            var result = target.Validate(model, ruleSet);

            Assert.IsTrue(result.IsValid);
            target.ShouldNotHaveValidationErrorFor(x => x.Id, model, ruleSet);
            target.ShouldNotHaveValidationErrorFor(x => x.EventParentId, model, ruleSet);
            target.ShouldNotHaveValidationErrorFor(x => x.Name, model, ruleSet);
        }
示例#9
0
 /// <summary>
 /// Inserts an <see cref="EventGroupModel"/> class.
 /// </summary>
 /// <param name="model">The <see cref="EventGroupModel"/> class to insert.</param>
 public void Insert(EventGroupModel model)
 {
     try
     {
         var entity = (EventGroup) new EventGroup
         {
             UserId    = ApplicationUser.Id,
             CreatedOn = DateTime.Now
         }.InjectFrom <SmartInjection>(model);
         context.InsertEventGroup(entity);
         model.InjectFrom <SmartInjection>(GetById(entity.Id));
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#10
0
 /// <summary>
 /// Updates an <see cref="EventGroupModel"/> class.
 /// </summary>
 /// <param name="model">The <see cref="EventGroupModel"/> class to update.</param>
 public void Update(EventGroupModel model)
 {
     try
     {
         var entity = context.GetEventGroupByIdTracked(model.Id.Value);
         if (entity != null &&
             entity.UserId == ApplicationUser.Id)
         {
             entity.InjectFrom <SmartInjection>(model);
             entity.UpdatedOn = DateTime.Now;
             context.SaveChanges();
             model.InjectFrom <SmartInjection>(GetById(entity.Id));
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#11
0
        public void Update_ValidIdAndUserId_ContextSaveIsCalled()
        {
            var model = new EventGroupModel {
                Id = 1
            };
            var entity = new EventGroup {
                Id = model.Id.Value, UserId = User.Id
            };
            var contextMock = new Mock <IOnTaskDbContext>();

            contextMock.Setup(x => x.GetEventGroupByIdTracked(It.Is <int>(y => y == model.Id))).Returns(entity).Verifiable();
            contextMock.Setup(x => x.SaveChanges()).Verifiable();
            contextMock.Setup(x => x.GetEventGroupById(model.Id.Value)).Returns(entity).Verifiable();
            var mapperMock = new Mock <IMapperService>();

            mapperMock.Setup(x => x.Map <EventGroupModel>(entity, It.IsAny <string>())).Returns(model).Verifiable();
            var target = InitializeTarget(contextMock.Object, mapperMock.Object);

            target.Update(model);

            contextMock.Verify();
        }
示例#12
0
        public void GetById_ValidIdAndUserId_ReturnsModel()
        {
            int id     = 1;
            var entity = new EventGroup {
                Id = id, UserId = User.Id
            };
            var expected = new EventGroupModel {
                Id = id
            };
            var contextMock = new Mock <IOnTaskDbContext>();

            contextMock.Setup(x => x.GetEventGroupById(It.Is <int>(y => y == id))).Returns(entity).Verifiable();
            var mapperMock = new Mock <IMapperService>();

            mapperMock.Setup(x => x.Map <EventGroupModel>(It.Is <EventGroup>(y => y == entity), It.IsAny <object>())).Returns(expected).Verifiable();
            var target = InitializeTarget(contextMock.Object, mapperMock.Object);

            var actual = target.GetById(id);

            contextMock.Verify();
            Assert.AreEqual(expected.Id, actual.Id);
        }
示例#13
0
文件: EventService.cs 项目: ivdmi/psp
        // получить события по ячейкам для всех пользователей
        public List <EventGroupModel> GetGroupsEventList(DateTime startDate)
        {
            _startDate = startDate;
            _endDate   = DateTimeUtils.GetEndDateOfMonth(_startDate);
            List <EventGroupModel> eventList = new List <EventGroupModel>();

            foreach (var gr in groupService.GetAllGroups())
            {
                var group = new EventGroupModel()
                {
                    GroupName = gr.Name
                };

                foreach (var us in gr.users.Where(u => u.Hidden == 0).OrderBy(u => u.Name))
                {
                    var user = GetUserEventsInCells(us.Name, us.ID);
                    group.Users.Add(user);
                }
                eventList.Add(group);
            }

            return(eventList);
        }
示例#14
0
        public void Insert_ModelIsProvided_InsertsEntity()
        {
            int id     = 1;
            var entity = new EventGroup {
                Id = id, UserId = User.Id
            };
            var model         = new EventGroupModel();
            var insertedModel = new EventGroupModel {
                Id = id
            };
            var contextMock = new Mock <IOnTaskDbContext>();

            contextMock.Setup(x => x.InsertEventGroup(It.IsAny <EventGroup>())).Callback <EventGroup>(x => x.Id = id).Verifiable();
            contextMock.Setup(x => x.GetEventGroupById(id)).Returns(entity).Verifiable();
            var mapperMock = new Mock <IMapperService>();

            mapperMock.Setup(x => x.Map <EventGroupModel>(entity, It.IsAny <string>())).Returns(insertedModel).Verifiable();
            var target = InitializeTarget(contextMock.Object, mapperMock.Object);

            target.Insert(model);

            contextMock.Verify();
            Assert.AreEqual(id, model.Id);
        }