Ejemplo n.º 1
0
        public BookingsControllerTests(ITestOutputHelper output)
        {
            var mockCatalogRepo = new Mock <ICatalogRepository>();

            mockCatalogRepo.Setup(repo => repo.GetTenantAsync("testTenant")).Returns(GetTenantModel());

            var mockUtilities     = new Mock <IUtilities>();
            var mockTenantRepo    = new Mock <ITenantRepository>();
            var mockDnsClient     = new Mock <ILookupClient>();
            var mockConfig        = new Mock <IConfiguration>();
            var mockBaseLocalizer = new Mock <IStringLocalizer <BaseController> >();

            //var mocklogger = new Mock<ILogger<BookingsController>>();

            logger = new XunitLogger <BookingsController>(output);

            var mockLocalizer = new Mock <IStringLocalizer <BaseController> >();
            IStringLocalizer <BaseController> stringLocalizer = mockLocalizer.Object;

            mockTenantRepo.Setup(repo => repo.GetHotelDetailsAsync(12345)).Returns(GetHotel());
            mockTenantRepo.Setup(repo => repo.GetHotelTypeAsync("Classic", 12345)).Returns(GetHotelType());
            mockTenantRepo.Setup(repo => repo.GetAllCitiesAsync(12345)).Returns(GetCities());
            mockTenantRepo.Setup(repo => repo.GetRoomsAsync(new List <int> {
                506, 503
            }, 1)).Returns(GetRooms());
            mockTenantRepo.Setup(repo => repo.GetRoomAsync(506, 1)).Returns(GetRoom);
            mockTenantRepo.Setup(repo => repo.GetCityAsync("HYD", 1)).Returns(GetCity);
            mockTenantRepo.Setup(repo => repo.GetGuest("*****@*****.**", 1)).Returns(GetGuest);
            mockTenantRepo.Setup(repo => repo.GetOffer(1, 1)).Returns(GetOffer);
            mockTenantRepo.Setup(repo => repo.GetOffersForTenant(1)).Returns(GetOffersForTenant);
            mockTenantRepo.Setup(repo => repo.GetRoomPricesAsync(506, 1)).Returns(GetRoomPrices);
            mockTenantRepo.Setup(repo => repo.GetBookingsSold(506, 1, 1)).Returns(GetBookingsSolds);

            _bookingsController = new BookingsController(mockTenantRepo.Object, mockCatalogRepo.Object, stringLocalizer, logger, mockConfig.Object, mockDnsClient.Object, mockUtilities.Object);
        }
        public FindRoomsControllerTests(ITestOutputHelper output)
        {
            var mockTenantRepo   = new Mock <ITenantRepository>();
            var mockCatalogRepo  = new Mock <ICatalogRepository>();
            var mockConfig       = new Mock <IConfiguration>();
            var mockDnsClient    = new Mock <ILookupClient>();
            var mockEmailService = new Mock <IEmailService>();

            var mock = new Mock <ILogger <FindRoomsController> >();
            ILogger <FindRoomsController> mocklogger = mock.Object;

            _logger = new XunitLogger <FindRoomsController>(output);

            var mockLocalizer = new Mock <IStringLocalizer <BaseController> >();
            IStringLocalizer <BaseController> stringLocalizer = mockLocalizer.Object;

            var mockFindRoomsLocalizer = new Mock <IStringLocalizer <FindRoomsController> >();
            IStringLocalizer <FindRoomsController> roomsStringLocalizer = mockFindRoomsLocalizer.Object;

            var roomPrices = GetRoomPrices();

            mockTenantRepo.Setup(repo => repo.GetRoomAsync(1, 1)).Returns(GetRoomModel());
            mockTenantRepo.Setup(repo => repo.GetRoomPricesAsync(1, 1)).Returns(roomPrices);

            var seatSectionIds = roomPrices.Result.ToList().Select(i => i.RoomId).ToList();

            mockTenantRepo.Setup(r => r.GetRoomsAsync(seatSectionIds, 1)).Returns(GetRooms());
            mockTenantRepo.Setup(r => r.GetRoomAsync(1, 1)).Returns(GetRoomModel());
            mockTenantRepo.Setup(r => r.GetBookingsSold(1, 1, 1)).Returns(GetBookingsPurchased());
            mockTenantRepo.Setup(r => r.AddBookings(GetBookingsModel(), 1)).Returns(GetBooleanValue());
            mockTenantRepo.Setup(r => r.AddBookingPurchase(GetBookingPurchaseModel(), 1)).Returns(GetBookingId());
            mockTenantRepo.Setup(r => r.GetHotelDetailsAsync(1)).Returns(GetHotelDetails());

            mockCatalogRepo.Setup(cat => cat.GetTenantAsync("tenantName")).Returns(GetTenant());

            var mockUtilities   = new Mock <IUtilities>();
            var mockHttpContext = new Mock <HttpContext>();

            httpContext = mockHttpContext.Object;

            _findRoomsController = new FindRoomsController(mockTenantRepo.Object, mockCatalogRepo.Object, roomsStringLocalizer, stringLocalizer,
                                                           _logger, mockConfig.Object, mockDnsClient.Object, mockEmailService.Object);

            _findRoomsController.ControllerContext             = new ControllerContext();
            _findRoomsController.ControllerContext.HttpContext = new DefaultHttpContext();
        }
Ejemplo n.º 3
0
        public HomeControllerTests(ITestOutputHelper output)
        {
            // Arrange
            var mockCatalogRepo = new Mock <ICatalogRepository>();
            var mockTenantRepo  = new Mock <ITenantRepository>();
            var mockUtilities   = new Mock <IUtilities>();

            _logger = new XunitLogger <HomeController>(output);

            mockCatalogRepo.Setup(repo => repo.GetAllTenantsAsync()).Returns(GetTenants());
            mockTenantRepo.Setup(repo => repo.GetHotelDetailsAsync(1)).Returns(GetHotelDetails());
            mockUtilities.Setup(utl => utl.GetTenantStatus(1)).Returns(GetTenantStatus());

            _homeController = new HomeController(mockCatalogRepo.Object, mockTenantRepo.Object, _logger, mockUtilities.Object);
            _homeController.ControllerContext             = new ControllerContext();
            _homeController.ControllerContext.HttpContext = new DefaultHttpContext();
        }
Ejemplo n.º 4
0
        public AccountControllerTests(ITestOutputHelper output)
        {
            var mockTenantRepo = new Mock <ITenantRepository>();
            var mockConfig     = new Mock <IConfiguration>();
            var mockDnsClient  = new Mock <ILookupClient>();

            var mockLocalizer = new Mock <IStringLocalizer <BaseController> >();
            IStringLocalizer <BaseController> stringLocalizer = mockLocalizer.Object;

            var mockAccountLocalizer = new Mock <IStringLocalizer <AccountController> >();
            IStringLocalizer <AccountController> accountStringLocalizer = mockAccountLocalizer.Object;

            logger = new XunitLogger <AccountController>(output);

            mockTenantRepo.Setup(repo => repo.GetGuest("*****@*****.**", 1)).Returns(GetCustomerAsync());
            mockTenantRepo.Setup(repo => repo.AddGuestAsync(GetCustomer(), 1)).Returns(GetCustomerId());

            var mockCatalogRepo = new Mock <ICatalogRepository>();

            mockCatalogRepo.Setup(repo => repo.GetAllTenantsAsync()).Returns(GetAllTenants());
            mockCatalogRepo.Setup(repo => repo.GetTenantAsync("tenantName")).Returns(GetTenants());

            var mockUtilities = new Mock <IUtilities>();

            mockUtilities.Setup(utl => utl.GetTenantStatus(1)).Returns(GetTenantStatus());

            _accountController = new AccountController(accountStringLocalizer, stringLocalizer, mockTenantRepo.Object, mockCatalogRepo.Object,
                                                       logger, mockConfig.Object, mockDnsClient.Object);

            _accountController.ControllerContext             = new ControllerContext();
            _accountController.ControllerContext.HttpContext = new DefaultHttpContext();
            MockHttpSession mockHttpSession = new MockHttpSession();

            mockHttpSession["SessionUsers"] = JsonConvert.SerializeObject(GetGuests());
            _accountController.ControllerContext.HttpContext.Session = mockHttpSession;
        }