示例#1
0
        public void AddBug_WhenBugTextIsValid_ShouldBeAddedToRepoWithLogDateAndStatusPending()
        {
            var bugs = new List<Bug>();

            var bug = new BugModel()
            {
                Text = "NEW TEST BUG"
            };

            var data = Mock.Create<IBugLoggerData>();

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

            Mock.Arrange(() => data.SaveChanges())
                .DoInstead(() => bugs.Add(new Bug() { Text = "NEW TEST BUG" }));

            var controller = new BugsController(data);
            this.SetupController(controller);

            //act
            controller.PostBug(bug);

            //assert
            Assert.AreEqual(data.Bugs.All().Count(), 1);
            var bugInDb = data.Bugs.All().FirstOrDefault();
            Assert.AreEqual(bug.Text, bugInDb.Text);
            Assert.IsNotNull(bugInDb.LogDate);
            Assert.AreEqual(Status.Pending, bugInDb.Status);
        }
示例#2
0
        public void GetAll_WhenValid_ShouldReturnBugsCollection()
        {
            Bug[] bugs =
            {
                new Bug() { Text = "First bug" },
                new Bug() { Text = "Second bug" }
            };

            var data = Mock.Create<IBugLoggerData>();

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

            var controller = new BugsController(data);
            this.SetupController(controller);

            var actionResult = controller.Get();
            var response = actionResult.ExecuteAsync(CancellationToken.None).Result;
            var actual = response.Content.ReadAsAsync<IEnumerable<BugModel>>().Result.Select(a => a.Id).ToList();

            var expected = bugs.AsQueryable().Select(a => a.Id).ToList();

            CollectionAssert.AreEquivalent(expected, actual);
        }
示例#3
0
        public void GetByDate_WhenValid_ShouldReturnCollectionMemberWithCorrespondingStatus()
        {
            Bug[] bugs =
            {
                new Bug()
                {
                    Text = "First bug",
                    LogDate = DateTime.Now
                },
                new Bug()
                {
                    Text = "Second bug",
                    LogDate = DateTime.Now.AddDays(2)
                }
            };

            var data = Mock.Create<IBugLoggerData>();

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

            var controller = new BugsController(data);
            this.SetupController(controller);

            var actionResult = controller.Get(DateTime.Now.ToString());
            var response = actionResult.ExecuteAsync(CancellationToken.None).Result;
            var actual = response.Content.ReadAsAsync<IEnumerable<BugModel>>().Result.Select(b => b.LogDate).ToList();

            var expected = bugs.AsQueryable()
                               .Where(b => b.LogDate.Day == DateTime.Now.Day &&
                                           b.LogDate.Month == DateTime.Now.Month &&
                                           b.LogDate.Year == DateTime.Now.Year)
                               .Select(b => b.LogDate)
                               .ToList();

            CollectionAssert.AreEquivalent(expected, actual);
        }