public int CreateProjectSource(ProjectSourceObj item, string username)
        {
            using (var db = GetInnerTrackContext())
            {
                item.CreatedBy = username;
                item.CreatedOn = DateTime.Now;

                db.ProjectSources.Add(item);

                db.SaveChanges();

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

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

            //assert
            Assert.AreEqual(expected, actual);
        }
        public void GetAll_ProjectSources_Found()
        {
            //arrange
            var mockRepository = new Mock<IInnerTrackRepository>();
            var expected = new ProjectSourceObj() { Id = 2 };
            mockRepository.Setup(m => m.GetProjectSources(It.Is<ProjectSourceFilter>(f => !f.Id.HasValue))).Returns(new List<ProjectSourceObj>() { expected });
            var logic = new ProjectSourceLogic(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 ProjectSourceObj();
            var user = "******";
            mockRepository.Setup(m => m.CreateProjectSource(obj, user)).Returns(expected);
            var logic = new ProjectSourceLogic(mockRepository.Object);

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

            //assert
            Assert.AreEqual(expected, actual);
        }
示例#5
0
        internal static ShowProjectSourceModel ConvertToShow(ProjectSourceObj obj)
        {
            var model = new ShowProjectSourceModel
            {
                Id = obj.Id.Value
                /*
                 * Copy other properties here
                 */
            };

            return model;
        }
示例#6
0
 internal static EditProjectSourceModel ConvertToEdit(ProjectSourceObj obj)
 {
     return new EditProjectSourceModel
     {
         Id = obj.Id
         /*
          * Copy other properties here
          */
     };
 }
        public bool UpdateProjectSource(ProjectSourceObj item, string username)
        {
            if (!item.Id.HasValue)
            {
                return false;
            }
            using (var db = GetInnerTrackContext())
            {
                var dbItem = db.ProjectSources.SingleOrDefault(i => i.Id == item.Id.Value);
                if (dbItem == null)
                {
                    return false;
                }

                dbItem.UpdatedBy = username;
                dbItem.UpdatedOn = DateTime.Now;
                db.SaveChanges();

                return true;
            }
        }
        public void Update_Id_Not_Found()
        {
            //arrange
            bool expected = false;
            var mockRepository = new Mock<IInnerTrackRepository>();
            var updateObj = new ProjectSourceObj { Id = 2 };
            var user = "******";
            mockRepository.Setup(m => m.UpdateProjectSource(updateObj, user)).Returns(expected);
            var logic = new ProjectSourceLogic(mockRepository.Object);

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

            //assert
            Assert.AreEqual(expected, actual);
        }
 public bool Update(ProjectSourceObj obj, string username)
 {
     return Repository.UpdateProjectSource(obj, username);
 }
 public int Create(ProjectSourceObj obj, string username)
 {
     return Repository.CreateProjectSource(obj, username);
 }