public void GetRandomSafeRoomType_AllPossibleGenerations_NoUnsafeRooms()
        {
            // Figure out how many safe room types there are.
            int safeTypesCount = 0;

            RoomType[] roomTypes = (RoomType[])Enum.GetValues(typeof(RoomType));

            foreach (var type in roomTypes)
            {
                var room = rf.Create(type);
                if (room.BehaviourThreshold == 1)
                {
                    safeTypesCount++;
                }
            }

            // Generate every such room and make sure they all have a threshold of 1.
            bool allSafe = true;

            for (int i = 0; i < safeTypesCount; i++)
            {
                rg = new MockRandomGeneratorConst(intAnswer: i);
                // MockRandomGeneratorConst always gives the constructor argument back with Generate().
                // Using that with a loop index checks all room types deemed safe by GetRandomSafeRoomType.

                IRoom room = rf.Create(mg.GetRandomSafeRoomType(rg));
                if (room.BehaviourThreshold < 1.0)
                {
                    allSafe = false;
                    break;
                }
            }

            Assert.True(allSafe);
        }
        public IRoom CreateNewRoom(int roomNumber, double price, int capacity)
        {
            var room = _factory.Create(roomNumber, capacity, price);

            _repository.Add(room);
            return(room);
        }
        public void ItCanCreateARoom()
        {
            var room = _roomFactory.Create();

            Assert.IsAssignableFrom <IRoom>(room);
            Assert.Equal(0, room.X);
            Assert.Equal(0, room.Y);
        }
Esempio n. 4
0
 public void Validate(IWorld world, IRoomFactory roomFactory, string title)
 {
     foreach (var blue in roomFactory.Blueprints)
     {
         try
         {
             var room = roomFactory.Create(world, blue);
             world.Map[new Point3(0, 0, 0)] = room;
             world.Player.CurrentLocation   = room;
             ValidateRoom(world, room);
         }
         catch (Exception e)
         {
             AddError($"Error creating RoomBlueprint for RoomFactory '{title}'.  Error was in {blue.Identifier?.ToString() ?? "Unamed Blueprint"}", e);
         }
     }
 }
        public async Task <RoomId> HandleAsync(IRemoteDevice remoteDevice, NewRoomRequest request)
        {
            // Currently anyone can create rooms,
            // TODO: add some security here
            var isNewRoomCreated = false;
            var roomId           = RoomId.FromString(request.NewRoomName);
            var room             = await _centralDispatchQueue.ExecuteAsync(() =>
            {
                var existingRoom = _roomRepository.GetRoomById(roomId);
                if (existingRoom != null)
                {
                    if (existingRoom.State != RoomState.Ok)
                    {
                        throw new InvalidProgramException(
                            "Clients should not be able to join rooms while they are being initialised"
                            );
                    }
                    return(existingRoom);
                }

                var newRoom = _roomFactory.Create(roomId);
                _roomRepository.AddRoom(newRoom);
                _logger.Info($"New room created: {newRoom}");
                isNewRoomCreated = true;
                return(newRoom);
            });


            // The device that creates the room is responsible for initializing the room.
            if (isNewRoomCreated)
            {
                room.Initialize();
                room.VideoRouter.Subscribe(_transceiverMetadataUpdatedObserver);
            }

            return(roomId);
        }
Esempio n. 6
0
        public void Create_RoomTypeForest_ReturnsForest()
        {
            IRoom room = rf.Create(RoomType.Forest);

            Assert.IsType <Forest>(room);
        }