コード例 #1
0
        public async void Test_Create_Visitors()
        {
            //Arrange
            var db = MockDb.CreateMockDb();
            var v  = new VisitorsController(db);

            var visitor = new Visitor {
                FirstName = "Alex", LastName = "Coa", PhoneNumber = "6476666888", ParkingId = 5, TimeOfEntry = System.DateTime.Today, TimeOfExit = System.DateTime.Today
            };

            //Act
            var r = await v.Create(visitor);

            //Assert
            var result = Assert.IsType <RedirectToActionResult>(r);

            Assert.Equal("Index", result.ActionName);
            // Each one can be used
            Assert.Equal(2, db.visitor.Count());
            Assert.Equal(1, db.visitor.Where(x => x.FirstName == visitor.FirstName && x.LastName == visitor.LastName && x.PhoneNumber == visitor.PhoneNumber && x.TimeOfEntry == visitor.TimeOfEntry && x.TimeOfExit == visitor.TimeOfExit).Count());
        }
コード例 #2
0
        public async void Test_Create_Invalid_Visitor_TimeOut()
        {
            //Arrange
            var db = MockDb.CreateMockDb();
            var c  = new VisitorsController(db);

            var visitor = new Visitor {
                FirstName = "Alex", LastName = "Coa", PhoneNumber = "6476666888", ParkingId = 5, TimeOfEntry = System.DateTime.Today
            };

            c.ModelState.AddModelError("Description", "MaxWords(4)");

            //Act
            var r = await c.Create(visitor);

            //Assert
            var result = Assert.IsType <ViewResult>(r);
            var model  = Assert.IsAssignableFrom <Visitor>(result.ViewData.Model);

            Assert.Equal(visitor, model);
            Assert.IsType <SelectList>(result.ViewData["parkingId"]);
        }