public void SaveRetroFamily(RetroFamily retroFamily)
        {
            if (retroFamily.Id == 0)
            {
                _context.RetroFamilies.Add(retroFamily);
            }
            else
            {
                RetroFamily dbEntry = _context.RetroFamilies
                                      .FirstOrDefault(c => c.Id == retroFamily.Id);

                if (dbEntry != null)
                {
                    dbEntry.Position      = retroFamily.Position;
                    dbEntry.RetroColumnId = retroFamily.RetroColumnId;
                    dbEntry.Content       = retroFamily.Content;

                    foreach (RetroCard r in retroFamily.RetroCards)
                    {
                        this.SaveRetroCard(r);
                    }
                }
            }

            _context.SaveChanges();
        }
Exemple #2
0
        public void CanDeleteRetroFamily()
        {
            //Arrange
            IRetroRespectiveRepository repo = _mockRetrospectiveRepo.Object;
            var controller = new RetroFamiliesController(repo, _hubContext.Object);

            IList <RetroFamily> retroFamilies = new List <RetroFamily>();

            RetroFamily f = new RetroFamily {
                Content  = "Okay",
                Id       = 0,
                Position = 0,
            };

            retroFamilies.Add(f);

            void Action(RetroFamily retroFamily)
            {
                RetroFamily y = retroFamilies.FirstOrDefault(x => x.Id == retroFamily.Id);

                retroFamilies.Remove(y);
            }

            _mockRetrospectiveRepo.Setup(m => m.RetroFamilies).Returns(retroFamilies.AsQueryable());

            _mockRetrospectiveRepo.Setup(m => m.RemoveRetroFamily(It.IsAny <RetroFamily>()))
            .Callback((Action <RetroFamily>)Action);

            //Act
            controller.Delete(0);

            //Assert
            Assert.False(retroFamilies.Any());
            Assert.True(retroFamilies.IsNullOrEmpty());
        }
Exemple #3
0
        public void CanAddPostRetroFamily()
        {
            //Arrange
            IRetroRespectiveRepository repo = _mockRetrospectiveRepo.Object;
            var controller = new RetroFamiliesController(repo, _hubContext.Object);

            IList <RetroFamily> retroFamilies = new List <RetroFamily>();

            void Action(RetroFamily retroFamily)
            {
                retroFamilies.Add(retroFamily);
            }

            _mockRetrospectiveRepo.Setup(m => m.SaveRetroFamily(It.IsAny <RetroFamily>()))
            .Callback((Action <RetroFamily>)Action);

            //Act
            controller.Post(new RetroFamily()
            {
                Id      = 5,
                Content = "RetroFamily 1"
            });

            //Assert
            Assert.True(retroFamilies.Any());
            RetroFamily createdRetroCard =
                retroFamilies.FirstOrDefault(r => r.Content.Equals("RetroFamily 1") && r.Id == 5);

            Assert.NotNull(createdRetroCard);
        }
Exemple #4
0
        public void CanGetRetroFamily()
        {
            //Arrange
            IRetroRespectiveRepository repo = _mockRetrospectiveRepo.Object;
            var controller = new RetroFamiliesController(repo, _hubContext.Object);

            IList <RetroFamily> retroFamilies = new List <RetroFamily>();

            RetroFamily f = new RetroFamily {
                Content  = "Okay",
                Id       = 0,
                Position = 0,
            };

            retroFamilies.Add(f);

            _mockRetrospectiveRepo.Setup(r => r.RetroFamilies).Returns(retroFamilies.AsQueryable());

            //Act
            RetroFamily family = controller.Get(0).Value;

            //Assert
            Assert.NotNull(family);
            Assert.Equal("Okay", family.Content);
            Assert.Equal(0, family.Position);
        }
        public void RemoveRetroFamily(RetroFamily retroFamily)
        {
            IList <RetroCard> RetroCards = _context.RetroCards.Where(x => x.RetroFamilyId == retroFamily.Id).ToList();

            foreach (RetroCard r in RetroCards)
            {
                this.RemoveRetroCard(r);
            }

            _context.RetroFamilies.Remove(retroFamily);
            _context.SaveChanges();
        }
Exemple #6
0
        public void Put([FromBody] RetroFamily retroFamily)
        {
            _repo.SaveRetroFamily(retroFamily);

            RetroColumn retroColumn = _repo.RetroColumns.FirstOrDefault(x => x.Id == retroFamily.RetroColumnId);

            if (_hubContext.Clients != null)
            {
                try
                {
                    _hubContext.Clients.All.BroadcastMessage(true, retroColumn.RetrospectiveId);
                }
                catch
                {
                    _hubContext.Clients.All.BroadcastMessage(false, retroColumn.RetrospectiveId);
                }
            }
        }
Exemple #7
0
        public ActionResult <RetroFamily> Post([FromBody] RetroFamily retroFamily)
        {
            _repo.SaveRetroFamily(retroFamily);

            RetroColumn retroColumn = _repo.RetroColumns.FirstOrDefault(x => x.Id == retroFamily.RetroColumnId);

            if (_hubContext.Clients != null)
            {
                try
                {
                    _hubContext.Clients.All.BroadcastMessage(true, retroColumn.RetrospectiveId);
                }
                catch (Exception)
                {
                    _hubContext.Clients.All.BroadcastMessage(false, retroColumn.RetrospectiveId);
                }
            }

            return(retroFamily);
        }
Exemple #8
0
        public async void CanGetAllRetroFamilies()
        {
            //Arrange
            IRetroRespectiveRepository repo = _mockRetrospectiveRepo.Object;
            var controller = new RetroFamiliesController(repo, _hubContext.Object);

            IList <RetroFamily> retroFamilies = new List <RetroFamily>();

            {
                RetroFamily f = new RetroFamily
                {
                    Content  = "Okay",
                    Id       = 0,
                    Position = 0,
                };

                retroFamilies.Add(f);
            }
            {
                RetroFamily f = new RetroFamily {
                    Content  = "Okay2",
                    Id       = 1,
                    Position = 1,
                };

                retroFamilies.Add(f);
            }

            _mockRetrospectiveRepo.Setup(r => r.RetroFamilies).Returns(retroFamilies.AsQueryable());

            //Act
            var entries = await controller.Get();

            //Arrange
            var test = entries.Value;

            Assert.Equal(2, test.Count());
        }
Exemple #9
0
        public void CanUpdateRetroFamily()
        {
            //Arrange
            IRetroRespectiveRepository repo = _mockRetrospectiveRepo.Object;
            var controller = new RetroFamiliesController(repo, _hubContext.Object);

            IList <RetroFamily> retroFamilies = new List <RetroFamily>();

            RetroFamily f = new RetroFamily
            {
                Content  = "Okay",
                Id       = 0,
                Position = 0,
            };

            retroFamilies.Add(f);

            void Action(RetroFamily retroFamily)
            {
                RetroFamily entry = retroFamilies.FirstOrDefault(x => x.Id == retroFamily.Id);

                entry.Content = retroFamily.Content;
            }

            _mockRetrospectiveRepo.Setup(m => m.SaveRetroFamily(It.IsAny <RetroFamily>()))
            .Callback((Action <RetroFamily>)Action);

            //Act
            f.Content = "Wow!";

            controller.Put(f);

            //Assert
            Assert.True(retroFamilies.Any());
            Assert.True(retroFamilies.Count == 1);
            Assert.True(retroFamilies.ElementAt(0).Content.Equals("Wow!"));
        }