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);
        }
        public void Ctor_sets_default_hours_per_day()
        {
            // Act
            var world = new MudWorld(Mock.Of <IRealmFactory>());

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

            // Assert
            Assert.IsTrue(world.GameDayToRealHourRatio > 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());
        }
        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)));
        }
        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());
        }
        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);
        }
        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();
        }
        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);
        }
        public async Task World_can_add_new_realm()
        {
            // 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);

            // Assert
            Assert.AreEqual(1, world.GetRealmsInWorld().Count());
        }