Exemple #1
0
            public void ModifyRoomExpectSuccessUpdate()
            {
                // Arrange
                var updatedRoom = new Room { Name = "TestUserName", IsAvailableOnline = true, RoomStatusCode = "X", BusinessId = VALID_BUSINESS_ID, Id = VALID_ROOM_ID };
                var mockRoomDao = MockRepository.GenerateMock<IRoomDao>();
                mockRoomDao.Expect(
                    rd =>
                    rd.GetByName(Arg<string>.Is.Equal(updatedRoom.Name), Arg<long>.Is.Equal(updatedRoom.BusinessId)))
                           .Return(new Room {Id = updatedRoom.Id});

                var mockBusinessEventDao = MockRepository.GenerateMock<IEventTrackingManager>();
                IBookingManager bookingManager = MockRepository.GenerateMock<IBookingManager>();
                bookingManager.Expect(bm => bm.GetByRoom(Arg<int>.Is.Equal(VALID_ROOM_ID), Arg<string>.Is.Anything))
                              .Return(new List<Booking>
                                          {
                                              // booking in past
                                              new Booking
                                              {
                                                  EndDate = DateTime.UtcNow.AddDays(-5),
                                                  StartDate = DateTime.UtcNow.AddDays(-15)
                                              }
                                          });

                mockRoomDao.Expect(rt => rt.Modify(updatedRoom)).Return(true);
                mockBusinessEventDao.Expect(be => be.CreateBusinessEventAsync(VALID_BUSINESS_ID, BusinessEventTypesEnum.RoomModified, updatedRoom.Id.ToString(CultureInfo.DefaultThreadCurrentCulture)));

                var roomManager = new RoomManager
                {
                    RoomDao = mockRoomDao,
                    EventTrackingManager = mockBusinessEventDao,
                    BookingManager = bookingManager
                };

                // Act
                roomManager.Modify(updatedRoom);

                // Assert
                mockRoomDao.VerifyAllExpectations();
                mockBusinessEventDao.VerifyAllExpectations();
                bookingManager.VerifyAllExpectations();
            }
Exemple #2
0
            public void ModifyRoomWithNullRoomExpectExceptionThrown()
            {
                // Arrange
              var roomManager = new RoomManager();

                try
                {
                    // Act
                    roomManager.Modify(null);

                    // Assert
                    Assert.Fail("An exception SRVEX30068 of type ValidationException should have been thrown");
                }
                catch (ValidationException ex)
                {
                    // Assert
                    Assert.AreEqual(Errors.SRVEX30068.ToString(), ex.Code,
                                    "The Validation exception is not returning the right error code");
                }
            }
Exemple #3
0
            public void ModifyRoomWithExistingNameInBusinessThrowsException()
            {
                // Arrange
                const string EXISTING_ROOM_NAME = "Room A";

                var updatedRoom = new Room { Name = EXISTING_ROOM_NAME, IsAvailableOnline = true, RoomStatusCode = "X", BusinessId = VALID_BUSINESS_ID, Id = VALID_ROOM_ID };
                var mockRoomDao = MockRepository.GenerateMock<IRoomDao>();
                mockRoomDao.Stub(r => r.GetByName(EXISTING_ROOM_NAME, VALID_BUSINESS_ID)).Return(new Model.Room.Room
                    {
                        Id = VALID_ROOM_ID + 1,
                        BusinessId = VALID_BUSINESS_ID,
                        Name = EXISTING_ROOM_NAME,
                        RoomStatusCode = RoomStatusCodes.ACTIVE
                    });
                IBookingManager bookingManager = MockRepository.GenerateMock<IBookingManager>();
                //verify this isn't called
                bookingManager.Expect(bm => bm.GetByRoom(Arg<int>.Is.Equal(VALID_ROOM_ID), Arg<string>.Is.Anything))
                              .Return(new List<Booking>()).Repeat.Never();

                var roomManager = new RoomManager 
                { 
                    RoomDao = mockRoomDao, 
                    BookingManager = bookingManager
                };

                try
                {
                    // Act
                    roomManager.Modify(updatedRoom);

                    // Assert
                    Assert.Fail("An exception SRVEX30085 of type ValidationException should have been thrown");
                }
                catch (ValidationException ex)
                {
                    // Assert
                    Assert.AreEqual("SRVEX30085", ex.Code, "The Validation exception is not returning the right error code");
                    mockRoomDao.VerifyAllExpectations();
                    bookingManager.VerifyAllExpectations();
                }
            }
Exemple #4
0
            public void ModifyRoomWithForwardBookingsStartDateThrowsException()
            {
                // Arrange

                Room roomToModify = new Room
                {
                    Id = VALID_ROOM_ID,
                    BusinessId = VALID_BUSINESS_ID,
                    RoomStatusCode = RoomStatusCodes.INACTIVE,
                    Name = "newName"
                };

                IBookingManager bookingManager = MockRepository.GenerateMock<IBookingManager>();
                bookingManager.Expect(bm => bm.GetByRoom(Arg<int>.Is.Equal(VALID_ROOM_ID), Arg<string>.Is.Anything))
                              .Return(new List<Booking>
                                          {
                                              new Booking
                                              {
                                                  EndDate = DateTime.UtcNow.AddDays(15),
                                                  StartDate = DateTime.UtcNow.AddDays(5)
                                              }
                                          });

                RoomManager roomManager = new RoomManager
                {
                    BookingManager = bookingManager
                };

                try
                {
                    // Act
                    roomManager.Modify(roomToModify);
                    Assert.Fail("Validation exception should have been thrown");
                }
                catch (ValidationException vex)
                {
                    // Assert
                    Assert.AreEqual(Errors.SRVEX30097.ToString(), vex.Code,
                                    "Validation exception SRVEX30097 should have been thrown because of bookings");
                    bookingManager.VerifyAllExpectations();
                }
            }