Exemplo n.º 1
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.º 2
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());
        }