public void CreateTest() { var result = _roomsController.Create() as ViewResult; var room = result.Model; Assert.AreEqual("Create", result.ViewName); Assert.AreEqual(null, result.Model); }
public void Create_HttpPost_ValidModel_SavesNewRoom_RedirectsToRoomView() { //Arrange var mockDal = new Mock <IRoomDAL>(); var mockSession = new Mock <HttpSessionStateBase>(); mockSession.SetupGet(m => m["Username"]).Returns("test-user"); var mockContext = new Mock <HttpContextBase>(); mockContext.SetupGet(m => m.Session).Returns(mockSession.Object); var room = new RoomModel { Name = "test-room", Description = "test description", }; // Set the Id after calling CreateChatRoom on the DAL mockDal.Setup(m => m.CreateChatRoom(room)).Callback(() => { room.Id = 1; }).Returns(room); var controller = new RoomsController(mockDal.Object, null); controller.ControllerContext = new ControllerContext(mockContext.Object, new RouteData(), controller); //Act var result = controller.Create(room) as RedirectToRouteResult; //Assert Assert.IsNotNull(result); Assert.AreEqual("View", result.RouteValues["action"]); Assert.AreEqual("Rooms", result.RouteValues["controller"]); Assert.AreEqual(1, result.RouteValues["id"]); mockDal.Verify(m => m.CreateChatRoom(room)); }
public void Create_WithAnyCreate_ReturnTrue() { // Act controller.Create(It.IsAny <Room>()); // Assert Id Room fakeRoomRepository.Verify(x => x.Add(It.IsAny <Room>()), Times.Once); }
public void Create_ReturnsCreateView() { var controller = new RoomsController(null, null); var result = controller.Create() as ViewResult; Assert.AreEqual("Create", result.ViewName); Assert.IsNotNull(result.Model); }
public void Create() { // Arrange RoomsController controller = new RoomsController(); // Act ViewResult result = controller.Create() as ViewResult; // Assert Assert.IsNotNull(result); }
public void Create_HttpPost_InValidModel_RedirectsToCreateView() { //Arrange var controller = new RoomsController(null, null); controller.ModelState.AddModelError("error", "error"); var room = new RoomModel { Name = "test-room" }; //Act var result = controller.Create(room) as ViewResult; //Assert Assert.IsNotNull(result); Assert.AreEqual("Create", result.ViewName); Assert.IsNotNull(result.ViewName); }
public async Task IntegrationTest() { var loginResponse = await authController.Login(new PunsApi.Requests.Authentication.LoginRequest { Email = "*****@*****.**", Password = "******" }); Assert.True(((Microsoft.AspNetCore.Mvc.ObjectResult)loginResponse).StatusCode == 200); var createRoomRespose = await controller.Create(new PunsApi.Requests.Rooms.CreateRoomRequest { PlayerMaxCount = 5, PlayerMinCount = 2, RoomName = "Testowy Pokoj" }); Assert.True(((Microsoft.AspNetCore.Mvc.ObjectResult)createRoomRespose).StatusCode == 200); var createGameResponse = await games_controller.Create(new CreateGameRequest { GameName = "Gra Testowa" }); Assert.True(((Microsoft.AspNetCore.Mvc.ObjectResult)createRoomRespose).StatusCode == 200); var fetchGameResponse = await games_controller.FetchGame(); Assert.True(((Microsoft.AspNetCore.Mvc.ObjectResult)fetchGameResponse).StatusCode == 200); }
public void Create_ReturnsView() { ViewResult result = _controller.Create() as ViewResult; Assert.AreEqual("Create", result.ViewName); }