Esempio n. 1
0
        public object GetFameInfo(string gameId)
        {
            int        enemyCardsCount = 0;
            List <int> cards           = new List <int>();
            Game       game            = RoomsService.GetInstance().GetGame(Guid.Parse(gameId));

            if (game.GetAttacker().Id.Equals(Guid.Parse(User.Identity.GetUserId())))
            {
                enemyCardsCount = game.GetDefender().Cards.Count;
                cards           = game.GetAttacker().Cards;
            }
            if (game.GetDefender().Id.Equals(Guid.Parse(User.Identity.GetUserId())))
            {
                enemyCardsCount = game.GetAttacker().Cards.Count;
                cards           = game.GetDefender().Cards;
            }

            return(new
            {
                Trump = game.Trump,
                EnemyCardsCount = enemyCardsCount,
                Attacker = game.IsFirstPlayerAttack,
                AllCardsOnTable = game.GetAllCardsOnTable(),
                CardsOnColode = game.GetCardsCountInColode(),
                Cards = cards
            });
        }
        public async Task TestGetRoomByIdFromHotel()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var roomRepository        = new EfDeletableEntityRepository <Room>(new ApplicationDbContext(options.Options));
            var reservationRepository = new EfDeletableEntityRepository <Reservation>(new ApplicationDbContext(options.Options));

            await roomRepository.AddAsync(new Room
            {
                Id      = 1,
                Number  = "100",
                HotelId = 1,
            });

            await roomRepository.AddAsync(new Room
            {
                Id      = 2,
                Number  = "200",
                HotelId = 2,
            });

            await roomRepository.SaveChangesAsync();

            var roomsService = new RoomsService(roomRepository, reservationRepository);

            AutoMapperConfig.RegisterMappings(typeof(MyTestRoom).Assembly);
            var room = await roomsService.GetByIdAsync <MyTestRoom>(1);

            Assert.Equal("100", room.Number);
        }
Esempio n. 3
0
        private RoomsService GetRoomsService(EfDeletableEntityRepository <Room> roomRepository, EfDeletableEntityRepository <RoomType> roomTypeRepository, HotelDbContext context)
        {
            var roomsService = new RoomsService(
                roomRepository,
                roomTypeRepository);

            return(roomsService);
        }
Esempio n. 4
0
 void Application_Start(object sender, EventArgs e)
 {
     // Код, выполняемый при запуске приложения
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     GlobalConfiguration.Configure(WebApiConfig.Register);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     RoomsService.GetInstance();
 }
Esempio n. 5
0
        public Room Post()
        {
            var             context      = ApplicationDbContext.Create();
            var             usersContext = context.Users;
            ApplicationUser user         = usersContext.Find(User.Identity.GetUserId());
            Room            room         = new Room(Guid.Parse(User.Identity.GetUserId()), User.Identity.Name, Guid.Parse(User.Identity.GetUserId()), user.Games, user.Wins);

            RoomsService.GetInstance().AddRoom(room);
            return(room);
        }
 public CalculatorViewModel(CalculatorRepository calculatorRepository, RoomsService roomsService)
 {
     _strings              = new Strings();
     _roomsService         = roomsService;
     _calculatorRepository = calculatorRepository;
     _calculatorModel      = calculatorRepository.GetModelFromXml();
     SaveCommand           = new DelegateCommand(executeAction => this.Save(), canExecute => true);
     CalculateCommand      = new DelegateCommand(executeAction => this.Calculate(), canExecute => true);
     Change = new DelegateCommand(executeAction => this.ChangeLanguage(), canExecute => true);
 }
Esempio n. 7
0
        public async Task Get_All_Reservations_Should_Return_All_Reservations()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            this.dbContext = new ApplicationDbContext(options);

            var roomRepository            = new EfDeletableEntityRepository <Room>(this.dbContext);
            var roomReservationRepository = new EfDeletableEntityRepository <RoomReservation>(this.dbContext);
            var pictureRepository         = new EfDeletableEntityRepository <Picture>(this.dbContext);
            var pictureService            = new PictureService(pictureRepository);
            var moqCloudinaryService      = new Mock <ICloudinaryService>();

            await roomRepository.AddAsync(new Room
            {
                Id                = "1",
                RoomType          = (RoomType)Enum.Parse(typeof(RoomType), "SingleRoom"),
                Price             = 10,
                Pictures          = null,
                HasAirConditioner = true,
                HasBathroom       = true,
                HasHeater         = false,
                HasMountainView   = false,
                HasPhone          = false,
                HasRoomService    = false,
                HasSeaView        = false,
                HasTv             = false,
                HasWifi           = false,
                NumberOfBeds      = 3,
            });

            await roomRepository.SaveChangesAsync();

            await roomReservationRepository.AddAsync(new RoomReservation
            {
                Id             = "1",
                RoomType       = (RoomType)Enum.Parse(typeof(RoomType), "SingleRoom"),
                CheckIn        = DateTime.Now.AddDays(1),
                CheckOut       = DateTime.Now.AddDays(3),
                NumberOfGuests = 2,
                RoomId         = "1",
                UserId         = "1",
            });

            await roomReservationRepository.SaveChangesAsync();

            this.roomService = new RoomsService(roomRepository, roomReservationRepository, pictureService, moqCloudinaryService.Object);

            int expectedResult = 1;

            var actualResult = await this.roomService.GetAllReservationsAsync <ReservationsAllViewModel>("1");

            Assert.Equal(actualResult.Count(), expectedResult);
        }
Esempio n. 8
0
        public void ShouldThrowArgumentNullException_WhenNullRoomIsPassed()
        {
            // Arrange
            var mockedUnitOfWork        = new Mock <IUnitOfWork>();
            var mockedGenericRepository = new Mock <IGenericRepository <Room> >();

            var roomsService = new RoomsService(mockedUnitOfWork.Object, mockedGenericRepository.Object);

            // Act and Assert
            Assert.Throws <ArgumentNullException>(() => roomsService.AddRoom(null));
        }
Esempio n. 9
0
        public async Task Reserve_Room_Should_Make_One_Reservation()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            this.dbContext = new ApplicationDbContext(options);

            var roomRepository            = new EfDeletableEntityRepository <Room>(this.dbContext);
            var roomReservationRepository = new EfDeletableEntityRepository <RoomReservation>(this.dbContext);
            var pictureRepository         = new EfDeletableEntityRepository <Picture>(this.dbContext);
            var pictureService            = new PictureService(pictureRepository);
            var moqCloudinaryService      = new Mock <ICloudinaryService>();

            await roomRepository.AddAsync(new Room
            {
                Id                = "1",
                RoomType          = (RoomType)Enum.Parse(typeof(RoomType), "SingleRoom"),
                Price             = 10,
                Pictures          = null,
                HasAirConditioner = true,
                HasBathroom       = true,
                HasHeater         = false,
                HasMountainView   = false,
                HasPhone          = false,
                HasRoomService    = false,
                HasSeaView        = false,
                HasTv             = false,
                HasWifi           = false,
                NumberOfBeds      = 3,
            });

            await roomRepository.SaveChangesAsync();

            this.roomService = new RoomsService(roomRepository, roomReservationRepository, pictureService, moqCloudinaryService.Object);


            var reservation = new ReserveRoomInputModel
            {
                CheckIn       = DateTime.Now.AddDays(1),
                CheckOut      = DateTime.Now.AddDays(3),
                CountOfPeople = 2,
                RoomId        = "1",
                Email         = "*****@*****.**",
                FirstName     = "Marian",
                LastName      = "Kyuchukov",
                PhoneNumber   = "0888186978",
            };

            var actualResult = await this.roomService.ReserveRoom(reservation);

            Assert.True(actualResult);
        }
        public RestfulBookerClient(string username, string password, string baseUrl = "https://restful-booker.herokuapp.com")
        {
            var client = new RestClient(baseUrl)
            {
                Authenticator = new HttpBasicAuthenticator(username, password)
            };

            client.UseSerializer(() => new JsonNetSerializer());
            client.AddDefaultHeader("Accept", "application/json");

            Bookings = new BookingsService(client);
            Rooms    = new RoomsService(client);
        }
Esempio n. 11
0
        public void DoSmth(string gameId, int attackCard, int defendCard)
        {
            Game game = RoomsService.GetInstance().GetGame(Guid.Parse(gameId));

            if (game.GetAttacker().Id.Equals(Guid.Parse(User.Identity.GetUserId())))
            {
                game.Attack(attackCard);
            }
            if (game.GetDefender().Id.Equals(Guid.Parse(User.Identity.GetUserId())))
            {
                game.Defend(attackCard, defendCard);
            }
        }
Esempio n. 12
0
        public int GetEnemyCardsCount(string gameId)
        {
            Game game = RoomsService.GetInstance().GetGame(Guid.Parse(gameId));

            if (game.GetAttacker().Id.Equals(Guid.Parse(User.Identity.GetUserId())))
            {
                return(game.GetDefender().Cards.Count);
            }
            if (game.GetDefender().Id.Equals(Guid.Parse(User.Identity.GetUserId())))
            {
                return(game.GetAttacker().Cards.Count);
            }
            return(-1);
        }
Esempio n. 13
0
        public List <int> GetCards(string gameId)
        {
            Game game = RoomsService.GetInstance().GetGame(Guid.Parse(gameId));

            if (game.GetAttacker().Id.Equals(Guid.Parse(User.Identity.GetUserId())))
            {
                return(game.GetAttacker().Cards);
            }
            if (game.GetDefender().Id.Equals(Guid.Parse(User.Identity.GetUserId())))
            {
                return(game.GetDefender().Cards);
            }
            return(null);
        }
Esempio n. 14
0
        public void ShouldThrowArgumentNullExceptionWithCorrectMessage_WhenNullRoomIsPassed()
        {
            // Arrange
            var expectedExMessage = "Room cannot be null.";

            var mockedUnitOfWork        = new Mock <IUnitOfWork>();
            var mockedGenericRepository = new Mock <IGenericRepository <Room> >();

            var roomsService = new RoomsService(mockedUnitOfWork.Object, mockedGenericRepository.Object);

            // Act and Assert
            var exception = Assert.Throws <ArgumentNullException>(() => roomsService.AddRoom(null));

            StringAssert.Contains(expectedExMessage, exception.Message);
        }
Esempio n. 15
0
        public void ShouldCallGetAllMethodOfRoomsRepositoryOnce()
        {
            // Arrange
            var mockedUnitOfWork        = new Mock <IUnitOfWork>();
            var mockedGenericRepository = new Mock <IGenericRepository <Room> >();

            mockedGenericRepository.Setup(gr => gr.GetAll()).Verifiable();

            var roomsService = new RoomsService(mockedUnitOfWork.Object, mockedGenericRepository.Object);

            // Act
            roomsService.GetRooms();

            // Assert
            mockedGenericRepository.Verify(gr => gr.GetAll(), Times.Once);
        }
Esempio n. 16
0
        public async Task ManualCreateRoom_WithInValidPrice_ShouldNotReturnRoom()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var expectedRoom = 0;

            this.dbContext = new ApplicationDbContext(options);

            var roomRepository            = new EfDeletableEntityRepository <Room>(this.dbContext);
            var roomReservationRepository = new EfDeletableEntityRepository <RoomReservation>(this.dbContext);
            var pictureRepository         = new EfDeletableEntityRepository <Picture>(this.dbContext);
            var pictureService            = new PictureService(pictureRepository);
            var moqCloudinaryService      = new Mock <ICloudinaryService>();


            this.roomService = new RoomsService(roomRepository, roomReservationRepository, pictureService, moqCloudinaryService.Object);

            var room = new Room
            {
                RoomType          = (RoomType)Enum.Parse(typeof(RoomType), "SingleRoom"),
                Price             = 0,
                Pictures          = null,
                HasAirConditioner = true,
                HasBathroom       = true,
                HasHeater         = false,
                HasMountainView   = false,
                HasPhone          = false,
                HasRoomService    = false,
                HasSeaView        = false,
                HasTv             = false,
                HasWifi           = false,
                NumberOfBeds      = 1,
            };

            if (room != null && room.Price > 0 && room.NumberOfBeds < 10)
            {
                await this.dbContext.AddAsync(room);

                await this.dbContext.SaveChangesAsync();
            }

            var actual = this.dbContext.Rooms.Count();

            Assert.Equal(expectedRoom, actual);
        }
Esempio n. 17
0
        public void ShouldCallAddMethodOfCategoryRepositoryOnce_WhenARoomIsPassed()
        {
            // Arrange
            var room                    = new Mock <Room>();
            var mockedUnitOfWork        = new Mock <IUnitOfWork>();
            var mockedGenericRepository = new Mock <IGenericRepository <Room> >();

            mockedGenericRepository.Setup(gr => gr.Add(room.Object)).Verifiable();

            var roomsService = new RoomsService(mockedUnitOfWork.Object, mockedGenericRepository.Object);

            // Act
            roomsService.AddRoom(room.Object);

            // Assert
            mockedGenericRepository.Verify(gr => gr.Add(room.Object), Times.Once);
        }
Esempio n. 18
0
        public void ShouldCallCommitMethodOfUnitOfWorkOnce_WhenARoomIsPassed()
        {
            // Arrange
            var room                    = new Mock <Room>();
            var mockedUnitOfWork        = new Mock <IUnitOfWork>();
            var mockedGenericRepository = new Mock <IGenericRepository <Room> >();

            mockedUnitOfWork.Setup(uow => uow.Commit()).Verifiable();

            var roomsService = new RoomsService(mockedUnitOfWork.Object, mockedGenericRepository.Object);

            // Act
            roomsService.AddRoom(room.Object);

            // Assert
            mockedUnitOfWork.Verify(uow => uow.Commit(), Times.Once);
        }
        public async Task TestCreateRoom()
        {
            var rooms        = new List <Room>();
            var mockRoomRepo = new Mock <IDeletableEntityRepository <Room> >();

            mockRoomRepo.Setup(x => x.All()).Returns(rooms.AsQueryable());
            mockRoomRepo.Setup(x => x.AddAsync(It.IsAny <Room>())).Callback(
                (Room room) => rooms.Add(room));

            var mockReservationRepo = new Mock <IDeletableEntityRepository <Reservation> >();

            var service = new RoomsService(mockRoomRepo.Object, mockReservationRepo.Object);

            await service.CreateAsync(1, "100", 1, 100.00M, 2, 0, null, 1);

            Assert.Single(rooms);
        }
Esempio n. 20
0
        public void TestRoomsServiceGetById()
        {
            var mock = new Mock <IRoomsRepository>();
            var room = new Room
            {
                Id          = "test id",
                Name        = "test name",
                Description = "test description"
            };
            var service = new RoomsService(mock.Object);

            mock.Setup(p => p.GetById("test")).Returns(room);

            var result = service.GetById("test");

            Assert.AreEqual("test name", result.Name);
        }
        public async Task TestDeleteRoom()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var roomRepository        = new EfDeletableEntityRepository <Room>(new ApplicationDbContext(options.Options));
            var reservationRepository = new EfDeletableEntityRepository <Reservation>(new ApplicationDbContext(options.Options));

            await roomRepository.AddAsync(new Room { Id = 1 });

            await roomRepository.SaveChangesAsync();

            var roomsService = new RoomsService(roomRepository, reservationRepository);

            await roomsService.DeleteAsync(1);

            Assert.Equal(0, reservationRepository.All().Count());
        }
Esempio n. 22
0
        public async Task DeleteRoom_ShouldDelete()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            this.dbContext = new ApplicationDbContext(options);

            var roomRepository            = new EfDeletableEntityRepository <Room>(this.dbContext);
            var roomReservationRepository = new EfDeletableEntityRepository <RoomReservation>(this.dbContext);
            var pictureRepository         = new EfDeletableEntityRepository <Picture>(this.dbContext);
            var pictureService            = new PictureService(pictureRepository);
            var moqCloudinaryService      = new Mock <ICloudinaryService>();


            this.roomService = new RoomsService(roomRepository, roomReservationRepository, pictureService, moqCloudinaryService.Object);

            var room = new Room
            {
                RoomType          = (RoomType)Enum.Parse(typeof(RoomType), "SingleRoom"),
                Price             = 10,
                Pictures          = null,
                HasAirConditioner = true,
                HasBathroom       = true,
                HasHeater         = false,
                HasMountainView   = false,
                HasPhone          = false,
                HasRoomService    = false,
                HasSeaView        = false,
                HasTv             = false,
                HasWifi           = false,
                NumberOfBeds      = 1,
            };

            await this.dbContext.AddAsync(room);

            await this.dbContext.SaveChangesAsync();

            var deletingRoom = this.dbContext.Rooms.FirstOrDefault(x => x.Id == room.Id);

            var actual = await this.roomService.DeleteRoom(deletingRoom.Id);

            Assert.True(actual);
        }
Esempio n. 23
0
        public Game Connect(string roomId)
        {
            Room room   = RoomsService.GetInstance().GetRoom(Guid.Parse(roomId));
            Guid userId = Guid.Parse(User.Identity.GetUserId());

            if (room.SecondPlayerConnected)
            {
                if (room.FirstPlayerId.Equals(userId) || room.SecondPlayerId.Equals(userId))
                {
                    return(GetGame(roomId));
                }
                throw new Exception("В эту игру уже играют");
            }
            else
            {
                room.SecondPlayerId = Guid.Parse(User.Identity.GetUserId());
                return(RoomsService.GetInstance().CreateGame(room).Item2);
            }
        }
Esempio n. 24
0
        public async Task AdministratorCreateRoom_WithValidData_ShouldReturnRoom()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            this.dbContext = new ApplicationDbContext(options);

            var roomRepository            = new EfDeletableEntityRepository <Room>(this.dbContext);
            var roomReservationRepository = new EfDeletableEntityRepository <RoomReservation>(this.dbContext);
            var pictureRepository         = new EfDeletableEntityRepository <Picture>(this.dbContext);
            var pictureService            = new PictureService(pictureRepository);
            var moqCloudinaryService      = new Mock <ICloudinaryService>();
            var moqIFormFile = new Mock <IFormFile>();

            this.roomService = new RoomsService(roomRepository, roomReservationRepository, pictureService, moqCloudinaryService.Object);

            var room = new CreateRoomInputModel
            {
                RoomType = (RoomType)Enum.Parse(typeof(RoomType), "SingleRoom"),
                Price    = 10,
                Pictures = new List <IFormFile>
                {
                    moqIFormFile.Object
                },
                HasAirConditioner = true,
                HasBathroom       = true,
                HasHeater         = false,
                HasMountainView   = false,
                HasPhone          = false,
                HasRoomService    = false,
                HasSeaView        = false,
                HasTv             = false,
                HasWifi           = false,
                NumberOfBeds      = 1,
            };

            var actual = await this.roomService.CreateRoomAsync(room);

            Assert.True(actual);
        }
Esempio n. 25
0
        static void Main(string[] args)
        {
            var roomsBusiness    = new RoomsBusiness();
            var roomtypeBusiness = new RoomTypeBusiness();

            var roomsService    = new RoomsService(roomsBusiness);
            var roomtypeService = new RoomTypeService(roomtypeBusiness);

            var roomqty  = new VwRoomQty();
            var qtyrooms = roomqty.GetRoomQty();

            int id = 1;

            while (id != qtyrooms)
            {
                roomsService.Insert(new Room {
                    Id = id, RoomNumber = "Room_" + id, RoomType = 0, RoomStatus = 0
                });
                id = id + 1;
            }
        }
Esempio n. 26
0
        public void ShouldReturnAllRoomsFromRoomsRepository()
        {
            // Arrange
            var mockedRoom  = new Mock <Room>();
            var mockedRooms = new List <Room>
            {
                mockedRoom.Object,
                mockedRoom.Object
            };
            var mockedUnitOfWork        = new Mock <IUnitOfWork>();
            var mockedGenericRepository = new Mock <IGenericRepository <Room> >();

            mockedGenericRepository.Setup(gr => gr.GetAll()).Returns(mockedRooms);

            var roomsService = new RoomsService(mockedUnitOfWork.Object, mockedGenericRepository.Object);

            // Act
            var result = roomsService.GetRooms();

            // Assert
            Assert.AreSame(mockedRooms, result);
        }
        public async Task TestGetAllAvailableRoomFromHotel()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var roomRepository        = new EfDeletableEntityRepository <Room>(new ApplicationDbContext(options.Options));
            var reservationRepository = new EfDeletableEntityRepository <Reservation>(new ApplicationDbContext(options.Options));

            var reservationsList = new List <Reservation>();

            var reservation = new Reservation
            {
                ArrivalDate = DateTime.UtcNow,
                ReturnDate  = DateTime.UtcNow.AddDays(2),
            };

            reservationsList.Add(reservation);

            await roomRepository.AddAsync(new Room { HotelId = 1 });

            await roomRepository.AddAsync(new Room
            {
                HotelId      = 1,
                Reservations = reservationsList,
            });

            await roomRepository.AddAsync(new Room { HotelId = 2 });

            await roomRepository.SaveChangesAsync();

            var roomsService = new RoomsService(roomRepository, reservationRepository);

            AutoMapperConfig.RegisterMappings(typeof(MyTestRoom).Assembly);
            var rooms = roomsService.AvailableRooms <MyTestRoom>(1, DateTime.UtcNow.AddDays(-1), DateTime.UtcNow.AddDays(1));

            Assert.Single(rooms);
        }
        public async Task TestEditReservation()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var reservationRepository = new EfDeletableEntityRepository <Reservation>(new ApplicationDbContext(options.Options));
            var roomRepository        = new EfDeletableEntityRepository <Room>(new ApplicationDbContext(options.Options));

            await roomRepository.AddAsync(new Room
            {
                Id     = 1,
                Number = "100",
            });

            await roomRepository.SaveChangesAsync();

            var roomsService = new RoomsService(roomRepository, reservationRepository);

            await roomsService.UpdateAsync(1, 2, "105B", 1, 100.00M, 2, 0, null);

            var result = roomRepository.All().FirstOrDefault();

            Assert.Equal("105B", result.Number);
        }
Esempio n. 29
0
        public async Task Get_All_Rooms_Should_Return_Zero()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            this.dbContext = new ApplicationDbContext(options);

            var roomRepository            = new EfDeletableEntityRepository <Room>(this.dbContext);
            var roomReservationRepository = new EfDeletableEntityRepository <RoomReservation>(this.dbContext);
            var pictureRepository         = new EfDeletableEntityRepository <Picture>(this.dbContext);
            var pictureService            = new PictureService(pictureRepository);
            var moqCloudinaryService      = new Mock <ICloudinaryService>();


            this.roomService = new RoomsService(roomRepository, roomReservationRepository, pictureService, moqCloudinaryService.Object);

            var actualResult = await this.roomService
                               .GetAllRoomsAsync <RoomsAllViewModel>();

            int expectedResult = 0;

            Assert.Equal(actualResult.Count(), expectedResult);
        }
Esempio n. 30
0
 public RoomsController(RoomsService rs, CategoriesService cs)
 {
     _rs = rs;
     _cs = cs;
 }