Exemplo n.º 1
0
        public void Null_logging_service_throws_exception()
        {
            // Arrange
            var worldService = this.container.Resolve<IWorldService>();

            // Act
            var game = new DefaultGame(null, worldService);

            // Assert
            Assert.Fail();
        }
Exemplo n.º 2
0
        public void Null_world_service_throws_exception()
        {
            // Arrange
            var logService = this.container.Resolve<ILoggingService>();

            // Act
            var game = new DefaultGame(logService, null);

            // Assert
            Assert.Fail();
        }
Exemplo n.º 3
0
        public async Task Initialize_loads_worlds()
        {
            // Arrange
            var logService = this.container.Resolve<ILoggingService>();
            var worldService = this.container.Resolve<IWorldService>();
            var game = new DefaultGame(logService, worldService);

            // Act
            await game.Initialize();

            // Assert
            Assert.IsNotNull(game.Worlds);
            Assert.IsTrue(game.Worlds.Length == 1);
        }
Exemplo n.º 4
0
        public async Task Initializes_loaded_worlds()
        {
            // Arrange
            var world = new DefaultWorld();
            bool worldLoaded = false;
            world.Loaded += (sender, args) => worldLoaded = true;
            world.AddTimeOfDayState(new TimeOfDayState());

            // Set up the world service to return our mocked World.
            var worldServiceMock = new Mock<IWorldService>();
            worldServiceMock
                .Setup(service => service.GetAllWorlds())
                .ReturnsAsync(new List<DefaultWorld> { world });

            var logService = this.container.Resolve<ILoggingService>();

            // Provide our custom service for this test instead of the shared 
            // world service generated by the unit test set up code.
            var game = new DefaultGame(logService, worldServiceMock.Object);

            // Act
            await game.Initialize();

            // Assert
            Assert.IsTrue(worldLoaded);
        }
Exemplo n.º 5
0
        public async Task Delete_stops_autosaver()
        {
            // Arrange
            var logService = this.container.Resolve<ILoggingService>();
            // A DefaultWorld mock is needed so we can verify DefaultWorld.Delete is called.
            var worldMock = new Mock<DefaultWorld>();

            // Get our mocked instance and set up the time of day states needed
            // by the Initialize method call.
            var world = worldMock.Object;
            world.AddTimeOfDayState(new TimeOfDayState());

            // Set up the world service to return our mocked World
            // and allow us to verify that save was called.
            var worldServiceMock = new Mock<IWorldService>();
            worldServiceMock
                .Setup(service => service.GetAllWorlds())
                .ReturnsAsync(new List<DefaultWorld> { worldMock.Object });

            var game = new DefaultGame(logService, this.container.Resolve<IWorldService>());
            await game.Initialize();

            // Act
            await game.Delete();

            // Assert
            Assert.IsFalse(game.Autosave.IsAutosaveRunning, "Autosave is still running.");
        }
Exemplo n.º 6
0
        public async Task Delete_clears_worlds()
        {
            // Arrange
            // A DefaultWorld mock is needed so we can verify DefaultWorld.Delete is called.
            var worldMock = new Mock<DefaultWorld>();

            // Get our mocked instance and set up the time of day states needed
            // by the Initialize method call.
            var world = worldMock.Object;
            world.AddTimeOfDayState(new TimeOfDayState());

            // Set up the world service to return our mocked World
            // and allow us to verify that save was called.
            var worldServiceMock = new Mock<IWorldService>();
            worldServiceMock
                .Setup(service => service.GetAllWorlds())
                .ReturnsAsync(new List<DefaultWorld> { worldMock.Object });
            worldServiceMock
                .Setup(service => service.SaveWorld(It.IsAny<DefaultWorld>()))
                .Returns(Task.FromResult(0))
                .Verifiable();

            var logService = this.container.Resolve<ILoggingService>();
            
            var game = new DefaultGame(logService, worldServiceMock.Object);
            await game.Initialize();

            // Act
            await game.Delete();

            // Assert
            Assert.AreEqual(0, game.Worlds.Length, "Worlds not cleared.");
            worldServiceMock.Verify(service => service.SaveWorld(It.IsAny<DefaultWorld>()));

            // TODO: Verify DefaultWorld.Delete is called.
            //worldMock.Verify(world => world.Delete());
        }
Exemplo n.º 7
0
        public async Task World_loaded_event_fired()
        {
            // Arrange
            var logService = this.container.Resolve<ILoggingService>();
            var worldService = this.container.Resolve<IWorldService>();

            var game = new DefaultGame(logService, worldService);

            bool worldProvided = false;
            game.WorldLoaded += (sender, args) =>
            {
                worldProvided = args.World != null;
                return Task.FromResult(true);
            };

            // Act
            await game.Initialize();

            // Assert
            Assert.IsTrue(worldProvided, "World not provided.");
        }
Exemplo n.º 8
0
        public async Task Initialize_without_autosave()
        {
            // Arrange
            var logService = this.container.Resolve<ILoggingService>();
            var worldService = this.container.Resolve<IWorldService>();

            var game = new DefaultGame(logService, worldService);
            game.Autosave.AutoSaveFrequency = 0;

            // Act
            await game.Initialize();

            // Assert
            Assert.IsFalse(game.Autosave.IsAutosaveRunning);
        }