public void CannotUpdateRoomWithWrongSignature() { // Arrange Everything We Need For Our Unit Tests options = new DbContextOptionsBuilder <ApplicationDBContext>() .UseInMemoryDatabase(databaseName: "TestRevatureHousingData") .Options; testContext = new ApplicationDBContext(options); dummyRoomsData = new RoomDummyData(); dummyRooms = dummyRoomsData.RoomsList; testRoomRepository = new RoomRepository(testContext); testRoomController = new RoomsController(testRoomRepository); dummyConstantRoom = new Room() { RoomID = 12728 }; //Arrange Room room = new Room() { RoomID = 5 }; var postResponse = testRoomController.PostRoom(room); //Act var putResponse = testRoomController.PutRoom(128923, room).Result; //Assert Assert.IsInstanceOfType(putResponse, typeof(BadRequestResult)); // Clearing Changes ClearAllChanges(); }
public async void Put_ShouldAddNewRoom() { ClearRoomsFromDatabase(); var controller = new RoomsController(context); var room = new Room { id = 1, name = "Pokój świeżo dodany" }; var result = await controller.PutRoom(room); var typeResult = Assert.IsType <CreatedAtActionResult>(result); Assert.NotNull(typeResult.StatusCode); Assert.Equal(201, typeResult.StatusCode.Value); Assert.Contains(context.Room, p => p.name.Equals("Pokój świeżo dodany") && p.id.Equals(1)); }
public void ShouldNot_PutRoom_IdMismatch() { Room testRoom = new Room { Id = 1, Name = "Test5", Description = "Test", VenueId = 1, Columns = 10, Rows = 10, Isles = "{}" }; Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>(); mock.Setup(f => f.Rooms.Update(testRoom)).Returns(true); RoomsController controller = new RoomsController(mock.Object); var rooms = controller.PutRoom(2, testRoom); Assert.IsType <BadRequestResult>(rooms); }