public void Init() { MockCommandAgent mockCommander = new MockCommandAgent(); MockListFactory mockListFactory = new MockListFactory(); controller = new VisitorsController(mockCommander, mockListFactory); }
public async void IndexTest() { //Arrange var dbContext = MockDb.CreateMockDb(); var sc = new VisitorsController(dbContext); //Act var r = await sc.Index(); //Assert var result = Assert.IsType <ViewResult>(r); var model = Assert.IsAssignableFrom <List <Visitor> >(result.ViewData.Model); Assert.Single(model); }
public async Task VisitorsController_GetCount_Test() { bool called = false; var visitorRepository = new Data.Repositories.Fakes.StubIVisitorRepository(); visitorRepository.GetCountAsyncString = (filter) => { called = true; return(Task.FromResult(10)); }; var target = new VisitorsController(visitorRepository); var result = await target.GetCount(string.Empty); Assert.IsNotNull(result); Assert.IsTrue(called); }
public async Task VisitorsController_GetVisitors_Test() { bool called = false; var visitorRepository = new Data.Repositories.Fakes.StubIVisitorRepository(); visitorRepository.GetVisitorsAsyncStringPictureTypeInt32Int32 = (id, picture, pageSize, pageCount) => { called = true; return(Task.FromResult(new List <Visitor>().AsEnumerable())); }; var target = new VisitorsController(visitorRepository); var result = await target.GetVisitors(string.Empty, PictureType.Small, 1, 1); Assert.IsNotNull(result); Assert.IsTrue(called); }
public async Task VisitorsController_Get_Test() { bool called = false; var visitorRepository = new Data.Repositories.Fakes.StubIVisitorRepository(); visitorRepository.GetCompleteInfoAsyncInt32PictureType = (id, picture) => { called = true; return(Task.FromResult(new Visitor())); }; var target = new VisitorsController(visitorRepository); var result = await target.Get(0, PictureType.Small); Assert.IsNotNull(result); Assert.IsTrue(called); }
public async void Test_Delete_Visitor() { //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, TimeOfExit = System.DateTime.Today }; //Act var r = await c.Delete(1); //Assert var result = Assert.IsType <ViewResult>(r); var model = Assert.IsAssignableFrom <Visitor>(result.Model); Assert.Equal(visitor, model); }
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()); }
public async Task VisitorsController_Add_Test() { bool called = false; var visitorRepository = new Data.Repositories.Fakes.StubIVisitorRepository(); var newVisitor = new Visitor() { VisitorId = 1, }; visitorRepository.AddAsyncVisitor = (visitor) => { Assert.IsTrue(visitor.VisitorId == newVisitor.VisitorId); called = true; return(Task.FromResult(10)); }; var target = new VisitorsController(visitorRepository); await target.Add(newVisitor); Assert.IsTrue(called); }
public async Task VisitorsController_Delete_Test() { bool called = false; var visitorRepository = new Data.Repositories.Fakes.StubIVisitorRepository(); var visitor = new Visitor() { VisitorId = 1, }; visitorRepository.DeleteAsyncInt32 = (id) => { Assert.IsTrue(id == visitor.VisitorId); called = true; return(Task.FromResult(string.Empty)); }; var target = new VisitorsController(visitorRepository); await target.Delete(visitor.VisitorId); Assert.IsTrue(called); }
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"]); }
public void VisitorsController_Constructor_Failed_FirstArgument_test() { var target = new VisitorsController(null); }
public async Task VisitorsController_Update_Failed_Test() { var visitorRepository = new Data.Repositories.Fakes.StubIVisitorRepository(); var target = new VisitorsController(visitorRepository); await target.Update(null); }
/// <summary> /// Initializes a new instance of the <see cref="VisitorsControllerTests"/> class. /// </summary> public VisitorsControllerTests() { this.visitorManager = new Mock<IVisitorManager>(); this.visitorController = new VisitorsController(this.visitorManager.Object); }