public void GetAll_WhenValid_ShouldReturnBugsCollection()
        {
            //arrange
            FakeRepository<Bug> fakeRepo = new FakeRepository<Bug>();

            var bugs = new List<Bug>()
            {
                new Bug()
                {
                    Text = "TEST NEW BUG 1"
                },
                new Bug()
                {
                    Text = "TEST NEW BUG 2"
                },
                new Bug()
                {
                    Text = "TEST NEW BUG 3"
                }
            };            
            
            fakeRepo.Entities = bugs;

            var controller = new BugsController(fakeRepo as IRepository<Bug>);

            //act

            var result = controller.GetAll();

            //assert

            CollectionAssert.AreEquivalent(bugs, result.ToList<Bug>());
        }
        public void GetAll_WhenValid_ShouldReturnBugsCollection_WithMocks()
        {
            //arrange
            var repo = Mock.Create<IRepository<Bug>>();

            Bug[] bugs = { new Bug() { Text = "Bug1" }, new Bug() { Text = "Bug2" } };

            Mock.Arrange(() => repo.All()).Returns(() => bugs.AsQueryable());

            var controller = new BugsController(repo);
            //act
            var result = controller.GetAll();

            //assert
            CollectionAssert.AreEquivalent(bugs, result.ToArray<Bug>());
        }
        public void AddBug_WhenBugTextIsValid_ShouldBeAddedToRepoWithLogDateAndStatusPending()
        {
            //arrange
            var repo = new FakeRepository<Bug>();
            repo.IsSaveCalled = false;
            repo.Entities = new List<Bug>();
            var bug = new Bug() { Text = "NEW TEST BUG" };
            var controller = new BugsController(repo);
            this.SetupController(controller);

            //act
            controller.PostBug(bug);

            //assert
            Assert.AreEqual(repo.Entities.Count, 1);
            var bugInDb = repo.Entities.First();
            Assert.AreEqual(bug.Text, bugInDb.Text);
            Assert.IsNotNull(bugInDb.LogDate);
            Assert.AreEqual(Status.Pending, bugInDb.Status);
            Assert.IsTrue(repo.IsSaveCalled);
        }
        public void UpdateBugStatus_WhenStatusIsPending_ShouldReturnStatusFixed_WithMocks()
        {
            //arrange
            var repo = new FakeRepository<Bug>();
            repo.IsSaveCalled = false;
            repo.Entities = new List<Bug>();
            var bug = new Bug()
            {
                Text = "NEW TEST BUG",
                Status =Status.Pending
            };
            repo.Entities.Add(bug);
            var controller = new BugsController(repo);
            this.SetupController(controller);

            //act
            var result = controller.UpdateBugStatus(0, Status.Fixed);

            //assert
            Assert.AreEqual(Status.Fixed, repo.Entities[0].Status, "The status of the bug should be changed from Pending to Fixed.");
        }
        public void GetAllWithStatus_WhenTwoPending_ShouldReturnBugCollectionWithTwo_WithMocks()
        {
            //arrage
            var repo = Mock.Create<IRepository<Bug>>();

            Bug[] bugs =
            {
                new Bug() { Status = Status.Pending },
                new Bug() { Status = Status.Fixed },
                new Bug() { Status = Status.Pending },
            };

            Mock.Arrange(() => repo.All())
                .Returns(() => bugs.AsQueryable());

            var controller = new BugsController(repo);

            //act
            var result = controller.GetBugsByStatus(Status.Pending);

            //assert
            Assert.AreEqual(2, result.Count(), "The number of returned bugs should be 2.");
        }
        public void GetAllAfterDate_WhenOneAfterDate_ShouldReturnBugCollectionWithOne_WithMocks()
        {
            //arrage
            var repo = Mock.Create<IRepository<Bug>>();

            Bug[] bugs =
            {
                new Bug() { LogDate = DateTime.Parse("2013-01-01") },
                new Bug() { LogDate = DateTime.Parse("2014-01-01") }
            };

            Mock.Arrange(() => repo.All())
                .Returns(() => bugs.AsQueryable());

            var controller = new BugsController(repo);

            //act
            var result = controller.GetBugsAfterSpecificDate(DateTime.Parse("2013-06-06"));

            //assert
            Assert.AreEqual(1, result.Count(), "The number of returned bugs should be 1.");
        }
        public void GetAllByDate_WhenValid_ShouldReturnBugsCollection()
        {
            var repo = Mock.Create<IRepository<Bug>>();
            var bugs =
                new List<Bug> { new Bug() { LogDate = DateTime.Now, Status = Status.Pending, Text = "Tralala 1" } }
                    .AsQueryable();

            Mock.Arrange(() => repo.All()).Returns(() => bugs);

            var controller = new BugsController(repo);
            var result = controller.GetAfterDate("20-02-2014");
            CollectionAssert.AreEqual(
                                      bugs.ToList(),
                                      (result as OkNegotiatedContentResult<IQueryable<Bug>>).Content.ToList());
        }