public void ShouldRenderDetailViewCorrectly()
        {
            // Arrange
            Mock <IMealRepository>    mealMock    = new Mock <IMealRepository>();
            Mock <IStudentRepository> studentMock = new Mock <IStudentRepository>();

            mealMock.Setup(m => m.Meals).Returns(new List <Meal>()
            {
                new Meal()
                {
                    Id = 100, Title = "Compound - Strawberry", Description = " ", Price = 1.50, Date = DateTime.Now.AddDays(1)
                },
                new Meal()
                {
                    Id = 1, Title = "Chicken - White Meat With Tender", Description = "部落格", Price = 1.00, Date = DateTime.Now.AddDays(2)
                },
                new Meal()
                {
                    Id = 2, Title = "Amarula Cream", Description = "1.00E+02", Price = 1.00, Date = DateTime.Now.AddDays(4)
                },
                new Meal()
                {
                    Id = 3, Title = "Cake - Cheese Cake 9 Inch", Description = "<>?:\"{}|_+", Price = 1.00, Date = DateTime.Now.AddDays(8)
                },
                new Meal()
                {
                    Id = 4, Title = "Crawfish", Description = "𠜎𠜱𠝹𠱓𠱸𠲖𠳏", Price = 1.00, Date = DateTime.Now.AddDays(16)
                },
                new Meal()
                {
                    Id = 5, Title = "Ham - Proscuitto", Description = " ", Price = 1.00, Date = DateTime.Now.AddDays(32)
                },
                new Meal()
                {
                    Id = 6, Title = "Soup - Campbells Bean Medley", Description = "1.00E+02", Price = 1.00, Date = DateTime.Now.AddDays(-1)
                },
                new Meal()
                {
                    Id = 7, Title = "Beef - Kobe Striploin", Description = "NULL", Price = 1.00, Date = DateTime.Now.AddDays(-4)
                },
                new Meal()
                {
                    Id = 8, Title = "Muffin Batt - Choc Chk", Description = "社會科學院語學研究所", Price = 1.50, Date = DateTime.Now.AddDays(-8)
                },
                new Meal()
                {
                    Id = 9, Title = "Bread - Italian Roll With Herbs", Description = "123", Price = 1.00, Date = DateTime.Now.AddDays(-16)
                }
            });

            MealController controller = new MealController(mealMock.Object, studentMock.Object);

            // Act
            Meal model = (controller.Detail(100) as ViewResult)?.ViewData.Model as Meal;

            // Assert
            Assert.Equal("Compound - Strawberry", model.Title);
            Assert.Equal(" ", model.Description);
            Assert.Equal(1.50, model.Price);
        }
Пример #2
0
        public void DetailPageWorks()
        {
            Mock <IMealRepository> mock     = new Mock <IMealRepository>();
            Mock <IUserRepository> UserMock = new Mock <IUserRepository>();

            ApplicationUser User = new ApplicationUser()
            {
                Firstname = "Arno", Lastname = "Broeders"
            };
            Meal Meal5 = new Meal()
            {
                ID   = 5,
                Cook = User,
                Date = DateTime.Now.AddDays(2)
            };

            User.MealsAsCook.Add(Meal5);
            mock.Setup(m => m.Meals).Returns(new List <Meal>()
            {
                new Meal()
                {
                    ID = 0, Title = "Prachtmaaltijd", Description = "Prachtbeschrijving", Price = 0.25, Date = DateTime.Now.AddDays(4)
                },
                new Meal()
                {
                    ID = 1, Title = "Supermaaltijd", Description = "Superbeschrijving", Price = 0.85, Date = DateTime.Now.AddDays(2)
                },
                new Meal()
                {
                    ID = 2, Title = "Machtige maaltijd", Description = "Machtige beschrijving", Price = 0.55, Date = DateTime.Now.AddDays(7)
                },
                new Meal()
                {
                    ID = 3, Title = "Z maaltijd", Description = "Z beschrijving", Price = 0.45, Date = DateTime.Now.AddDays(5)
                },
                new Meal()
                {
                    ID = 4, Title = "Maaltijd van lang geleden", Date = DateTime.Now.AddDays(-1)
                },
                Meal5
            });

            MealController meals = new MealController(mock.Object, UserMock.Object);
            Meal           Meal  = meals.Detail(0).ViewData.Model as Meal;

            Assert.Equal("Prachtmaaltijd", Meal.Title);
            Assert.Equal("Prachtbeschrijving", Meal.Description);
            Assert.Equal(0.25, Meal.Price);
        }