Пример #1
0
        public void GetWorkItemsTest()
        {
            //given
            var testData = new List <WorkItem> {
                new WorkItem {
                    Item = "item 1", Price = 1000
                },
                new WorkItem {
                    Item = "item 2", Price = 1000
                },
                new WorkItem {
                    Item = "item 3", Price = 1000
                }
            };

            _context.WorkItems.AddRange(testData);
            _context.SaveChanges();
            WorkItemsController underTest = new WorkItemsController(_context);

            //when
            var result = underTest.GetWorkItems();

            //then
            Assert.IsNotNull(result);
            var okResult = result as OkObjectResult;

            Assert.IsInstanceOf <OkObjectResult>(okResult, result.GetType().ToString());
            var collectionResult = okResult.Value as IEnumerable <WorkItem>;

            Assert.IsInstanceOf <IEnumerable <WorkItem> >(collectionResult, result.GetType().ToString());
            Assert.AreEqual(3, collectionResult.Count());
            Assert.AreEqual(testData, collectionResult);
        }
Пример #2
0
        public void GetWorkItemsTest_Empty()
        {
            //given
            var testData = new List <WorkItem>();
            WorkItemsController underTest = new WorkItemsController(_context);

            //when
            var result = underTest.GetWorkItems();

            //then
            Assert.IsNotNull(result);
            var okResult = result as OkObjectResult;

            Assert.IsInstanceOf <OkObjectResult>(okResult, result.GetType().ToString());
            var collectionResult = okResult.Value as IEnumerable <WorkItem>;

            Assert.IsInstanceOf <IEnumerable <WorkItem> >(collectionResult, result.GetType().ToString());
            Assert.AreEqual(0, collectionResult.Count());
        }