示例#1
0
        public async Task Loading_assigns_a_real_world_current_time()
        {
            // Arrange
            int currentRealWorldHour = DateTime.Now.Hour;

            var realWorldTimeOfDayMock = new Mock<ITimeOfDay>();
            realWorldTimeOfDayMock.SetupGet(timeOfDay => timeOfDay.Hour)
                .Returns(currentRealWorldHour);
            realWorldTimeOfDayMock.SetupGet(timeOfDay => timeOfDay.Minute)
                .Returns(0);
            ITimeOfDay realWorldTimeOfDay = realWorldTimeOfDayMock.Object;

            var currentTimePeriodMock = new Mock<ITimePeriod>();
            currentTimePeriodMock.SetupGet(period => period.CurrentTime)
                .Returns(realWorldTimeOfDay);
            currentTimePeriodMock.SetupGet(period => period.StateStartTime)
                .Returns(realWorldTimeOfDay);
            ITimePeriod currentTimePeriod = currentTimePeriodMock.Object;

            var timePeriods = new List<ITimePeriod> { currentTimePeriod, };
            var world = new MudWorld(Mock.Of<IRealmFactory>(), timePeriods);

            // Act
            await world.Initialize();

            // Assert
            Assert.IsNotNull(world.CurrentTimeOfDay);
            Assert.AreEqual(currentRealWorldHour, world.CurrentTimeOfDay.CurrentTime.Hour);
        }
示例#2
0
        public void Ctor_sets_default_hours_per_day()
        {
            // Act
            var world = new MudWorld(Mock.Of<IRealmFactory>());

            // Assert
            Assert.IsTrue(world.HoursPerDay > 0);
        }
示例#3
0
        public void Ctor_sets_default_GameDayToRealHourRatio()
        {
            // Act
            var world = new MudWorld(Mock.Of<IRealmFactory>());

            // Assert
            Assert.IsTrue(world.GameDayToRealHourRatio > 0);
        }
示例#4
0
        /// <summary>
        /// Creates an uninitialized world
        /// Each realm provided will be initialized during the worlds initialization.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="gameDayToRealWorldHoursRatio">The game day to real world hours ratio.</param>
        /// <param name="hoursPerDay">The number of hours per day.</param>
        /// <param name="timePeriods">The time periods available to the world.</param>
        /// <param name="realms">The realms being added to the world.</param>
        /// <returns>Returns an IWorld instance</returns>
        public async Task<IWorld> CreateWorld(string name, double gameDayToRealWorldHoursRatio, int hoursPerDay, IEnumerable<ITimePeriod> timePeriods, IEnumerable<IRealm> realms)
        {
            var world = new MudWorld(this.realmFactory, timePeriods);

            world.SetName(name);
            world.GameDayToRealHourRatio = gameDayToRealWorldHoursRatio;
            world.SetHoursPerDay(hoursPerDay);

            if (realms.Count() > 0)
            {
                await world.AddRealmsToWorld(realms);
            }

            return world;
        }
示例#5
0
        public void Ctor_creates_time_manager_with_time_periods()
        {
            // Arrange
            var timePeriods = new List<ITimePeriod>
            {
                Mock.Of<ITimePeriod>(mock => mock.StateStartTime == Mock.Of<ITimeOfDay>())
            };

            // Act
            var world = new MudWorld(Mock.Of<IRealmFactory>(), timePeriods);

            // Assert
            Assert.IsNotNull(world.TimePeriodManager.GetTimePeriodForDay(
                Mock.Of<ITimeOfDay>(mock => mock.Hour == 0 && mock.Minute == 0)));
        }
示例#6
0
        /// <summary>
        /// Clones the properties of this instance to a new instance.
        /// </summary>
        /// <returns>
        /// Returns a new instance with the properties of this instance copied to it.
        /// </returns>
        /// <para>
        /// Cloning does not guarantee that the internal state of an object will be cloned nor
        /// does it guarantee that the clone will be a deep clone or a shallow.
        /// </para>
        public IWorld Clone()
        {
            var clone = new MudWorld(this.realmFactory)
            {
                Id = this.Id,
                CurrentTimeOfDay = this.CurrentTimeOfDay,
                GameDayToRealHourRatio = this.GameDayToRealHourRatio,
                HoursPerDay = this.HoursPerDay,
                IsEnabled = this.IsEnabled,
                Name = this.Name,
                realms = this.realms,
                timePeriods = this.timePeriods,
            };

            clone.TimePeriodManager = new TimePeriodManager(this.timePeriods);
            return clone;
        }
示例#7
0
        public void World_returns_available_time_periods()
        {
            // Arrange
            var timePeriods = new List<ITimePeriod>
            {
                Mock.Of<ITimePeriod>(mock => mock.StateStartTime == Mock.Of<ITimeOfDay>())
            };

            // Act
            var world = new MudWorld(Mock.Of<IRealmFactory>(), timePeriods);

            // Assert
            Assert.AreEqual(1, world.GetTimePeriodsForWorld().Count());
        }
示例#8
0
        public async Task Adding_realm_sets_its_enabled_flag()
        {
            // Arrange
            IRealmFactory factory = Mock.Of<IRealmFactory>(mock => 
            mock.CreateRealm(It.IsAny<string>(), It.IsAny<IWorld>()) == Task.FromResult(
                    Mock.Of<IRealm>(r => r.Name == "Unit Test" && r.IsEnabled == true)));

            var world = new MudWorld(factory);
            var realmName = "Test Realm";
            IRealm realm = await world.CreateRealm(realmName);

            // Act
            await world.AddRealmToWorld(realm);

            // Assert
            Assert.IsTrue(realm.IsEnabled);
        }
示例#9
0
        public async Task World_does_not_add_same_realm_twice()
        {
            // Arrange
            IRealmFactory factory = Mock.Of<IRealmFactory>(
                mock => mock.CreateRealm(It.IsAny<string>(), It.IsAny<IWorld>()) == Task.FromResult(
                    Mock.Of<IRealm>(r => r.Name == "Unit Test")));

            var world = new MudWorld(factory);
            var realmName = "Test Realm";
            IRealm realm = await world.CreateRealm(realmName);

            // Act
            await world.AddRealmToWorld(realm);
            await world.AddRealmToWorld(realm);

            // Assert
            Assert.AreEqual(1, world.GetRealmsInWorld().Count());
        }
示例#10
0
        public async Task World_can_add_collection_of_realms()
        {
            // Arrange
            var world = new MudWorld(Mock.Of<IRealmFactory>());
            var realms = new List<IRealm>() { Mock.Of<IRealm>(r => r.Name == "R1"), Mock.Of<IRealm>(r => r.Name == "R2") };

            // Act
            await world.AddRealmsToWorld(realms);

            // Assert
            Assert.AreEqual(2, world.GetRealmsInWorld().Count());
        }
示例#11
0
        public async Task Adding_realm_to_world_without_a_name_throws_exception()
        {
            // Arrange
            IRealmFactory factory = Mock.Of<IRealmFactory>(
                mock => mock.CreateRealm(It.IsAny<string>(), It.IsAny<IWorld>()) == Task.FromResult(Mock.Of<IRealm>()));

            var world = new MudWorld(factory);
            var realmName = "Test Realm";
            IRealm realm = await world.CreateRealm(realmName);

            // Act
            await world.AddRealmToWorld(realm);

            // Assert
            Assert.Fail();
        }
示例#12
0
        public async Task World_can_create_a_realm()
        {
            // Arrange
            IRealmFactory factory = Mock.Of<IRealmFactory>(
                mock => mock.CreateRealm(It.IsAny<string>(), It.IsAny<IWorld>()) == Task.FromResult(Mock.Of<IRealm>()));

            var world = new MudWorld(factory);
            var realmName = "Test Realm";

            // Act
            IRealm realm = await world.CreateRealm(realmName);

            // Assert
            Assert.IsNotNull(realm);
        }