コード例 #1
0
        public void Index_shows_most_expensive_first()
        {
            // Arrange
            var data = new List<Bike>
            {
                new Bike { Retail = 100M },
                new Bike { Retail = 200M },
                new Bike { Retail = 50M }
            };

            var set = new MockDbSet<Bike>()
                .SetupSeedData(data)
                .SetupLinq();

            var context = new Mock<CycleContext>();
            context.Setup(c => c.Bikes).Returns(set.Object);

            var controller = new BikesController(context.Object);

            // Act
            var result = controller.Index() as ViewResult;

            // Assert
            var bikes = result.Model as IEnumerable<Bike>;
            Assert.AreEqual(200M, bikes.First().Retail);
        }
コード例 #2
0
        public void Index_shows_most_expensive_first()
        {
            // Arrange
            var testData = new List<Bike>
            {
                new Bike { Retail = 100M },
                new Bike { Retail = 200M },
                new Bike { Retail = 50M }
            };

            // TODO Setup a mock context

            // Act
            var controller = new BikesController(/* TODO Pass in mock context*/);
            var result = controller.Index() as ViewResult;

            // Assert
            var bikes = result.Model as IEnumerable<Bike>;
            Assert.AreEqual(200M, bikes.First().Retail);
        }