public void GetAll_ReturnsListWithCorrectNumberOfRooms() { // Act var result = controller.Get() as List <Room>; var noOfRooms = result.Count; // Assert Assert.Equal(2, noOfRooms); }
public async void Get_Returns_NotFound() { _roomService .Setup(s => s.GetAsync(It.IsAny <Guid>())) .Returns(Task.FromResult <RoomDto>(null)); var result = await _roomsController.Get(Guid.NewGuid()); Assert.IsType <NotFoundResult>(result); }
public async Task GetById_WhenCalled_UnknownId_ReturnsNotFound() { var mockedRepo = new Mock <IHomeRepository>(); var rooms = new List <Room> { new Room() { Id = Guid.Empty } }; mockedRepo.Setup(repo => repo.GetRoom(Guid.Parse("00000000-0000-0000-0000-000000000001"))).ReturnsAsync(rooms[0]); var mockedListenerClient = new Mock <ISensorListenerAPI>(); mockedListenerClient.Setup(client => client.NotifyHomeyTopic <double>("test", 0)); var controller = new RoomsController(mockedRepo.Object, mockedListenerClient.Object); var result = await controller.Get("00000000-0000-0000-0000-000000000002"); var contentResult = result as NotFoundResult; Assert.NotNull(contentResult); }
public void TestGetWithDateParameter() { List <Room> rooms = new List <Room>(); rooms.Add(new Room() { Id = 1, Description = "Lorem lorem", Name = "Test Chamber", OpenFrom = 4, OpenTo = 16, Reservations = null }); rooms.Add(new Room() { Id = 2, Description = "Lorem lorem", Name = "UCL Room 1.1", OpenFrom = 0, OpenTo = 24, Reservations = null }); rooms.Add(new Room() { Id = 3, Description = "Lorem lorem", Name = "2 hour room", OpenFrom = 10, OpenTo = 12, Reservations = null }); var mockReservationRepo = new Mock <IReservationRepository>(); var mockRoomRepo = new Mock <IRoomRepository>(); mockRoomRepo.Setup(repo => repo.GetAllWithReservations()).Returns(rooms); var mockService = new Mock <IReservationService>(); mockService.Setup(s => s.GetReservationDateTimes(DateTime.Today.AddHours(6), DateTime.Today.AddHours(10), new List <DateTime>())) .Returns(new List <ReservationDateTime>() { new ReservationDateTime(DateTime.Today.AddHours(6), true), new ReservationDateTime(DateTime.Today.AddHours(7), true), new ReservationDateTime(DateTime.Today.AddHours(8), true), new ReservationDateTime(DateTime.Today.AddHours(9), true), }); RoomsController roomsController = new RoomsController(mockRoomRepo.Object, mockReservationRepo.Object, mockService.Object); ActionResult <IEnumerable <RoomInfoDto> > result = roomsController.Get(DateTime.Today); Assert.IsInstanceOfType(result, typeof(ActionResult <IEnumerable <RoomInfoDto> >)); }
public void getting_all_rooms_Then_status_code_is_200() { var facade = Substitute.For <IRoomFacade>(); var controller = new RoomsController(facade); var returnedRooms = controller.Get(); returnedRooms.As <OkObjectResult>().StatusCode.Should().Be(200); }
public async Task GetSingle_404() { var mock = new Mock <IReadOnlyRepository <Room> >(); mock.Setup(x => x.GetSingleAsync(It.IsAny <int>())).ReturnsAsync((Room)null); var controller = new RoomsController(mock.Object); var actionResult = await controller.Get(new Random().Next(0, int.MaxValue)); var modelResult = Assert.IsType <NotFoundResult>(actionResult); }
public async Task GetAll_404() { var mock = new Mock <IReadOnlyRepository <Room> >(); mock.Setup(x => x.GetAllAsync()).ReturnsAsync(new List <Room>()); var controller = new RoomsController(mock.Object); var actionResult = await controller.Get(); var modelResult = Assert.IsType <NotFoundResult>(actionResult); }
public void GetUsers() { var repo = new Mock <RoomsRep>(db); RoomsController controller = new RoomsController(repo.Object); var data = controller.Get(); var result = data as ObjectResult; Assert.AreEqual(200, result.StatusCode); }
public void GetAllRooms_ShouldReturnOk_WhenSuccessful() { mockRepo.Setup(r => r.GetAllRooms()) .Returns(new List <Room>() { kitchen }); var result = controller.Get(); result.Should().BeOfType <OkObjectResult>(); }
public async Task GetSingle_200() { var mock = new Mock <IReadOnlyRepository <Room> >(); mock.Setup(x => x.GetSingleAsync(It.IsAny <int>())).ReturnsAsync(TestData.First()); var controller = new RoomsController(mock.Object); var actionResult = await controller.Get(this.TestData.First().RoomId); var modelResult = Assert.IsType <OkObjectResult>(actionResult); var model = Assert.IsType <Room>(modelResult.Value); Assert.Equal(TestData.First().RoomId, model.RoomId); }
public async Task GetAll_200() { var mock = new Mock <IReadOnlyRepository <Room> >(); mock.Setup(x => x.GetAllAsync()).ReturnsAsync(TestData); var controller = new RoomsController(mock.Object); var actionResult = await controller.Get(); var modelResult = Assert.IsType <OkObjectResult>(actionResult); var model = Assert.IsType <List <Room> >(modelResult.Value); Assert.True(model.Any()); Assert.Equal(2, model.Count()); Assert.Equal(TestData.First().RoomId, model.First().RoomId); }
public void TestRoomsControllerGetById() { var mock = new Mock <IRoomsService>(); var room = new Room { Id = "test id", Name = "test name", Description = "test description" }; mock.Setup(p => p.GetById("test")).Returns(room); var controller = new RoomsController(mock.Object); var result = controller.Get("test"); Assert.AreEqual("test name", result.Value.Name); }
public void getting_all_rooms_Then_all_rooms_are_returned() { var facade = Substitute.For <IRoomFacade>(); var rooms = new[] { new Room { Name = "Küche" }, new Room { Name = "Wohnzimmer" } }; facade.GetAll().Returns(rooms); var controller = new RoomsController(facade); var returnedRooms = controller.Get(); var roomsDynamic = returnedRooms.As <OkObjectResult>().Value.As <IEnumerable <dynamic> >().ToArray(); roomsDynamic.Should().NotBeNullOrEmpty(); roomsDynamic[0].Name.Should().Be("Küche"); roomsDynamic[1].Name.Should().Be("Wohnzimmer"); }
public void GetForDateTest() { IList <Room> rooms = new List <Room> { new Room { RoomId = 1, Description = "", From = new TimeSpan(10, 0, 0), To = new TimeSpan(18, 0, 0), Reservations = new List <Reservation> { new Reservation { Description = "Testing", Email = "*****@*****.**", FirstName = "Sam", LastName = "", From = DateTime.Today.AddHours(11), To = DateTime.Today.AddHours(12), PhoneNumber = "+420 788 900", ReservationId = 1, RoomId = 1 } } } }; var mock = new Mock <IRoomRepository>(); mock.Setup(i => i.GetRoomWithReservations(1, DateTime.Today)).Returns(rooms.First()); mock.Setup(i => i.GetAllRoomsWithReservation(DateTime.Today)).Returns(rooms); var controller = new RoomsController(mock.Object); IActionResult result = controller.Get(1, DateTime.Today); Assert.NotNull(result as JsonResult); Assert.True(((JsonResult)result).Value == rooms.First()); }