Ejemplo n.º 1
0
        public void TestRoomAdd_ValidateRoom_ShouldPresent()
        {
            string expected = "The room with ID 2 has been created successfully.";

            var user = new User("admin", "admin123", Roles.VenueAdmin);

            int nextId = 1;

            var roomsRepoMock = new Mock <IRepository <Room> >();

            roomsRepoMock.Setup(b => b.Add(It.IsAny <Room>())).Callback((Room r) => r.Id = nextId++);

            var vanueRepo = new Mock <IRepository <Venue> >();

            vanueRepo.Setup(v => v.Get(It.IsAny <int>())).Returns(new Venue("Venue1", "Sofia", "Descr", user));

            var mockData = new Mock <IHotelBookingSystemData>();

            mockData.Setup(d => d.RoomsRepository).Returns(roomsRepoMock.Object);

            mockData.Setup(d => d.VenuesRepository).Returns(vanueRepo.Object);

            var controller = new RoomsController(mockData.Object, user);

            controller.Add(1, 100, 100M);

            var result = controller.Add(2, 100, 100M).Display();

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 2
0
        public void AddRoom_ToVenueWithNotLoggedInUser_ShouldThrowException()
        {
            var admin = new User(UsernameOne, PasswordOne, Roles.VenueAdmin);
            var mock  = new Mock <IHotelBookingSystemData>();

            mock.Setup(db => db.Venues.Get(1))
            .Returns(new Venue("dddd", "dddb", "check", admin));
            mock.Setup(db => db.Rooms.Add(It.IsAny <Room>()));

            var roomsController = new RoomsController(mock.Object, null);
            var view            = roomsController.Add(2, 2, 10M);
        }
        public async Task Add_WhenValid_ShouldCallServiceAndRedirect()
        {
            var controller = new RoomsController(bedServiceMock.Object, roomServiceMock.Object, hotelServiceMock.Object);
            var hotelId    = 1;
            var room       = new Room();

            var result = await controller.Add(hotelId, room);

            var redirectResult = Assert.IsType <RedirectToActionResult>(result);
            var resultHotelId  = (int)redirectResult.RouteValues["id"];

            Assert.Equal("Hotels", redirectResult.ControllerName);
            Assert.Equal(hotelId, resultHotelId);
            Assert.Equal(nameof(HotelsController.Hotel), redirectResult.ActionName);
            roomServiceMock.Verify(s => s.AddRoom(hotelId, room), Times.Once);
        }
Ejemplo n.º 4
0
        public void AddRoom_ToVenueWithNegativeID_ShouldReturnWarningMessage()
        {
            var admin = new User(UsernameOne, PasswordOne, Roles.VenueAdmin);
            var mock  = new Mock <IHotelBookingSystemData>();

            mock.Setup(db => db.Venues.Get(1))
            .Returns(new Venue("dddd", "dddb", "check", admin));
            mock.Setup(db => db.Rooms.Add(It.IsAny <Room>()));

            var roomsController = new RoomsController(mock.Object, admin);
            var view            = roomsController.Add(-7, 2, 10M);
            var actualResult    = view.Display();

            var expectedResult = $"Something happened!!1\r\nThe venue with ID {-7} does not exist.";

            Assert.AreEqual(expectedResult, actualResult, "Adding a room to not existing venue should return error message!");
        }
Ejemplo n.º 5
0
        public void RoomsAddInvalidVenue_ShouldThrowExceptionWithCorrectMessage()
        {
            // Arrange
            Mock<IHotelBookingSystemData> dataMoq = new Mock<IHotelBookingSystemData>();
            User user = new User("test user", "password", Roles.User);
            RoomsController controller = new RoomsController(dataMoq as IHotelBookingSystemData, user);

            // Act
            string result = string.Empty;
            try
            {
                IView view = controller.Add(1, 1, "30.00");
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }

            string expected = "The currently logged in user doesn't have sufficient rights to perform this operation.";

            // Assert
            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 6
0
        public void AddRoom_ToVenueByAdmin_ShouldReturnExpectedViewAndReturnProperCount()
        {
            var user = new User(UsernameOne, PasswordOne, Roles.VenueAdmin);
            var mock = new Mock <IHotelBookingSystemData>();

            mock.Setup(db => db.Venues.Get(It.IsAny <int>()))
            .Returns(new Venue("dddd", "dddb", "check", user));
            mock.Setup(db => db.Rooms.Add(It.IsAny <Room>()));

            var roomsController = new RoomsController(mock.Object, user);
            var view            = roomsController.Add(3, 2, 10M);
            var actualResult    = view.Display();

            var expectedResult = $"The room with ID {0} has been created successfully.";

            Assert.AreEqual(expectedResult, actualResult, "Did not add new room to venue!");

            var venue = mock.Object.Venues.Get(231);

            var actualRoomCount   = venue.Rooms.Count;
            var expectedRoomCount = 1;

            Assert.AreEqual(expectedRoomCount, actualRoomCount, "Rooms count of the venue is invalid!");
        }
        public void TestRoomAdd_ValidRoomDetails_RoomShouldBePresent()
        {
            const string expected = "The room with ID 2 has been created successfully.";

            var userMock = new Mock<User>();
            var user = new User("admin", "admin423", Roles.VenueAdmin);
            int nextid = 1;

            var roomRepositoryMock = new Mock<IRepository<Room>>();
            roomRepositoryMock.Setup(
                b => b.Add(It.IsAny<Room>())).Callback((Room r) => r.Id = nextid++);
            var venueRepository = new Mock<IRepository<Venue>>();
            venueRepository.Setup(v => v.Get(It.IsAny<int>()))
                .Returns(new Venue("Venue1", "Sofiq", "Descr", user));

            var mockData = new Mock<IHotelBookingSystemData>();
            mockData.Setup(d => d.RepositoryWithRooms).Returns(roomRepositoryMock.Object);
            mockData.Setup(d => d.RepositoryWithVenues).Returns(venueRepository.Object);

            var controller = new RoomsController(mockData.Object, user);

            controller.Add(1, 100, 100M);
            var result = controller.Add(2, 100, 100M);

            Assert.AreEqual(expected, result.Display());
        }