Exemplo n.º 1
0
        public void GetAll_Projects_Found()
        {
            //arrange
            var mockRepository = new Mock<IInnerTrackRepository>();
            var expected = new ProjectObj() { Id = 2 };
            mockRepository.Setup(m => m.GetProjects(It.Is<ProjectFilter>(f => !f.Id.HasValue))).Returns(new List<ProjectObj>() { expected });
            var logic = new ProjectLogic(mockRepository.Object);

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

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

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

            //assert
            Assert.AreEqual(expected, actual);
        }
        public int CreateProject(ProjectObj item, string username)
        {
            using (var db = GetInnerTrackContext())
            {
                var user = GetOrCreateCreateUser(username, db);
                item.Members = new List<UserObj>();
                item.Members.Add(user);
                item.CreatedBy = username;
                item.CreatedOn = DateTime.Now;

                db.Projects.Add(item);

                db.SaveChanges();

                return item.Id.Value;
            }
        }
        public void Show_Id_Found()
        {
            //arrange
            var mockLogic = new Mock<IProjectLogic>();
            var id = 2;
            var obj = new ProjectObj()
            {
                Id = id,
                Feeds = new List<FeedObj>()
            };
            mockLogic.Setup(l => l.Get(id)).Returns(obj);
            var controller = new ProjectController(mockLogic.Object);

            //act
            var actual = controller.Show(id) as ViewResult;

            //assert
            Assert.IsNotNull(actual);
            var model = actual.Model as ShowProjectModel;
            Assert.IsNotNull(model);
        }
        public void Edit_Update_Id_Found()
        {
            //arrange
            var id = 0;
            var mockLogic = new Mock<IProjectLogic>();
            var obj = new ProjectObj { Id = id };
            mockLogic.Setup(l => l.Get(id)).Returns(obj);
            var controller = new ProjectController(mockLogic.Object);

            //act
            var actual = controller.Edit(0) as ViewResult;

            //assert
            Assert.IsNotNull(actual);
            var model = actual.Model as EditProjectModel;
            Assert.IsNotNull(model);
        }
Exemplo n.º 6
0
        internal static ShowProjectModel ConvertToShow(ProjectObj obj)
        {
            var model =  new ShowProjectModel
            {
                Id = obj.Id.Value,
                Name = obj.Name,
                Description = obj.Description,
                Feeds = Convert(obj.Feeds),
                Tags = Convert(obj.Tags)
            };

            return model;
        }
Exemplo n.º 7
0
 internal static EditProjectModel ConvertToEdit(ProjectObj obj)
 {
     return new EditProjectModel
     {
         Id = obj.Id,
         Name = obj.Name,
         Description = obj.Description,
         Tags = Convert(obj.Tags)
     };
 }
        public bool UpdateProject(ProjectObj item, string username)
        {
            if (!item.Id.HasValue)
            {
                return false;
            }
            using (var db = GetInnerTrackContext())
            {
                var dbItem = db.Projects.SingleOrDefault(i => i.Id == item.Id.Value);
                if (dbItem == null)
                {
                    return false;
                }

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

                return true;
            }
        }
Exemplo n.º 9
0
        public void Create_Project_Found()
        {
            //arrange
            var projectId = 2;
            var project = new ProjectObj() { Id = projectId };
            var mockProjectLogic = new Mock<IProjectLogic>();
            mockProjectLogic.Setup(l => l.Get(projectId)).Returns(project);
            var mockFeedLogic = new Mock<IFeedLogic>();
            mockFeedLogic.Setup(l => l.GetFeedTypes()).Returns(new List<FeedType>() { FeedType.News });
            var controller = new FeedController(mockFeedLogic.Object, mockProjectLogic.Object);

            //act
            var actual = controller.Create(projectId) as ViewResult;

            //assert
            Assert.IsNotNull(actual);
            var model = actual.Model as EditFeedModel;
            Assert.IsNotNull(model);
            Assert.AreEqual(1, model.AvailableTypes.Count());
            Assert.AreEqual(((int)FeedType.News).ToString(), model.AvailableTypes.First().Value);
        }
Exemplo n.º 10
0
 public int Create(ProjectObj proj, string username)
 {
     return Repository.CreateProject(proj, username);
 }
Exemplo n.º 11
0
 public bool Update(ProjectObj proj, string username)
 {
     return Repository.UpdateProject(proj, username);
 }
Exemplo n.º 12
0
        public void GetByOwner_Projects_Found()
        {
            //arrange
            var mockRepository = new Mock<IInnerTrackRepository>();
            var username = "******";
            var expected = new ProjectObj() { Id = 2 };
            mockRepository.Setup(m => m.GetProjects(It.Is<ProjectFilter>(f => f.OwnersUserName == username))).Returns(new List<ProjectObj>() { expected });
            var logic = new ProjectLogic(mockRepository.Object);

            //act
            var actual = logic.GetByOwner(username);

            //assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(2, actual[0].Id);
        }
Exemplo n.º 13
0
        public void Update_Id_Not_Found()
        {
            //arrange
            bool expected = false;
            var mockRepository = new Mock<IInnerTrackRepository>();
            var updateProj = new ProjectObj { Id = 2 };
            var user = "******";
            mockRepository.Setup(m => m.UpdateProject(updateProj, user)).Returns(expected);
            var logic = new ProjectLogic(mockRepository.Object);

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

            //assert
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 14
0
        public void Get_Id_Found()
        {
            //arrange
            int id = 0;
            var expected = new ProjectObj { Id = id };
            var mockRepository = new Mock<IInnerTrackRepository>();
            mockRepository.Setup(m => m.GetProjects(It.Is<ProjectFilter>(f => f.Id == id))).Returns(new List<ProjectObj> { expected });
            var logic = new ProjectLogic(mockRepository.Object);

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

            //assert
            Assert.AreEqual(expected, actual);
        }