public int Create(ProjectSourceTypeObj obj, string username)
 {
     if (!obj.NextRun.HasValue)
     {
         obj.NextRun = DateTime.Now.AddMinutes(obj.Interval);
     }
     return Repository.CreateProjectSourceType(obj, username);
 }
Ejemplo n.º 2
0
        public int CreateProjectSourceType(ProjectSourceTypeObj item, string username)
        {
            using (var db = GetInnerTrackContext())
            {
                item.CreatedBy = username;
                item.CreatedOn = DateTime.Now;

                db.ProjectSourceTypes.Add(item);

                db.SaveChanges();

                return item.Id.Value;
            }
        }
        public void Get_Id_Found()
        {
            //arrange
            int id = 0;
            var expected = new ProjectSourceTypeObj { Id = id };
            var mockRepository = new Mock<IInnerTrackRepository>();
            mockRepository.Setup(m => m.GetProjectSourceTypes(It.Is<ProjectSourceTypeFilter>(f => f.Id == id))).Returns(new List<ProjectSourceTypeObj> { expected });
            var logic = new ProjectSourceTypeLogic(mockRepository.Object);

            //act
            var actual = logic.Get(id);

            //assert
            Assert.AreEqual(expected, actual);
        }
        public void GetAll_ProjectSourceTypes_Found()
        {
            //arrange
            var mockRepository = new Mock<IInnerTrackRepository>();
            var expected = new ProjectSourceTypeObj() { Id = 2 };
            mockRepository.Setup(m => m.GetProjectSourceTypes(It.Is<ProjectSourceTypeFilter>(f => !f.Id.HasValue))).Returns(new List<ProjectSourceTypeObj>() { expected });
            var logic = new ProjectSourceTypeLogic(mockRepository.Object);

            //act
            var actual = logic.GetAll();

            //assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(2, actual[0].Id);
        }
        public void Create_Successfully_Made()
        {
            //arrange
            int expected = 4;
            var mockRepository = new Mock<IInnerTrackRepository>();
            var obj = new ProjectSourceTypeObj();
            var user = "******";
            mockRepository.Setup(m => m.CreateProjectSourceType(obj, user)).Returns(expected);
            var logic = new ProjectSourceTypeLogic(mockRepository.Object);

            //act
            var actual = logic.Create(obj, user);

            //assert
            Assert.AreEqual(expected, actual);
        }
 public bool Update(ProjectSourceTypeObj obj, string username)
 {
     return Repository.UpdateProjectSourceType(obj, username);
 }
Ejemplo n.º 7
0
        internal static ShowProjectSourceTypeModel ConvertToShow(ProjectSourceTypeObj obj)
        {
            var model = new ShowProjectSourceTypeModel
            {
                Id = obj.Id.Value,
                Name = obj.Name,
                FullClassName = obj.FullClassName,
                Interval = obj.Interval,
                LastRun = obj.LastRun,
                NextRun = obj.NextRun.Value,
                Enabled = obj.Enabled
            };

            return model;
        }
Ejemplo n.º 8
0
 internal static EditProjectSourceTypeModel ConvertToEdit(ProjectSourceTypeObj obj)
 {
     return new EditProjectSourceTypeModel
     {
         Id = obj.Id,
         Name = obj.Name,
         FullClassName = obj.FullClassName,
         Interval = obj.Interval,
         Enabled = obj.Enabled
     };
 }
        public void Update_Id_Not_Found()
        {
            //arrange
            bool expected = false;
            var mockRepository = new Mock<IInnerTrackRepository>();
            var updateObj = new ProjectSourceTypeObj { Id = 2 };
            var user = "******";
            mockRepository.Setup(m => m.UpdateProjectSourceType(updateObj, user)).Returns(expected);
            var logic = new ProjectSourceTypeLogic(mockRepository.Object);

            //act
            var actual = logic.Update(updateObj, user);

            //assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 10
0
        public bool UpdateProjectSourceType(ProjectSourceTypeObj item, string username)
        {
            if (!item.Id.HasValue)
            {
                return false;
            }
            using (var db = GetInnerTrackContext())
            {
                var dbItem = db.ProjectSourceTypes.SingleOrDefault(i => i.Id == item.Id.Value);
                if (dbItem == null)
                {
                    return false;
                }

                dbItem.Name = item.Name;
                dbItem.FullClassName = item.FullClassName;

                if (item.NextRun.HasValue)
                {
                    dbItem.NextRun = item.NextRun.Value < SqlDateTime.MinValue.Value ? SqlDateTime.MinValue.Value : item.NextRun.Value;
                }
                if (item.LastRun.HasValue)
                {
                    dbItem.LastRun = item.LastRun.Value;
                }
                dbItem.Enabled = item.Enabled;
                dbItem.Interval = item.Interval;
                dbItem.UpdatedBy = username;
                dbItem.UpdatedOn = DateTime.Now;
                db.SaveChanges();

                return true;
            }
        }