示例#1
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);
        }
示例#2
0
 private static void Main()
 {
     using (DefaultGame game = new DefaultGame())
     {
         game.Run();
     }
 }
示例#3
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.");
        }
示例#4
0
        public void TestSimulateComputerVsComputerGame()
        {
            var playerOne = new ComputerPlayer();
            var playerTwo = new ComputerPlayer();
            var game      = new DefaultGame();

            game.Play(playerOne, playerTwo, _Rules);
        }
示例#5
0
        public void TestSimulateComputerVsHumanGame()
        {
            var playerOne = new ComputerPlayer();
            var playerTwo = new HumanPlayer((p) => Core.Rules.RockPaperScissors.Scissors);
            var game      = new DefaultGame();

            game.Play(playerOne, playerTwo, _Rules);
        }
示例#6
0
        public void TestSimulateHumanVsHumanGame()
        {
            var playerOne = new HumanPlayer((p) => Core.Rules.RockPaperScissors.Paper);
            var playerTwo = new HumanPlayer((p) => Core.Rules.RockPaperScissors.Scissors);
            var game      = new DefaultGame();
            var result    = game.Play(playerOne, playerTwo, _Rules);

            Assert.AreSame(playerTwo, result.Winner);
            Assert.IsFalse(result.IsDraw);
        }
示例#7
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();
        }
示例#8
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();
        }
示例#9
0
 // Use this for initialization
 void Start()
 {
     DontDestroyOnLoad(this);
     Game           = new GameStateModel();
     LoadedTextures = new Dictionary <string, Texture>();
     LoadAllTextures();
     ScreenHeight  = Screen.height;
     ScreenWidth   = Screen.width;
     ScreenXCenter = ScreenWidth / 2;
     ScreenYCenter = ScreenHeight / 2;
     DGame         = new DefaultGame();
 }
示例#10
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);
        }
        public void SaveSingleObjectTest()
        {
            // Arrange
            var game = new DefaultGame();
            var storage = new XmlPersistedStorage();
            storage.InitializeStorage();
            game.Initialize<DefaultPlayer>(storage);

            // Act
            game.StorageSource.Save<DefaultPlayer>(game.Player as DefaultPlayer);
            string filePath = game.StorageSource.GetStoragePath<IPlayer>(game.Player);

            // Assert
            Assert.IsTrue(System.IO.File.Exists(filePath));
        }
        public void TestPlayerOnePaperWins()
        {
            var playerOne = new Mock <IPlayer>();
            var playerTwo = new Mock <IPlayer>();

            playerOne.Setup(p => p.Choose()).Returns(Core.Rules.RockPaperScissors.Paper);
            playerTwo.Setup(p => p.Choose()).Returns(Core.Rules.RockPaperScissors.Rock);

            var game   = new DefaultGame();
            var result = game.Play(playerOne.Object, playerTwo.Object, _Rules);

            Assert.AreSame(playerOne.Object, result.Winner);
            Assert.IsFalse(result.IsDraw);
            playerOne.Verify(p => p.Choose(), Times.Once);
            playerTwo.Verify(p => p.Choose(), Times.Once);
        }
        public void SaveSingleObjectTest()
        {
            // Arrange
            var game    = new DefaultGame();
            var storage = new XmlPersistedStorage();

            storage.InitializeStorage();
            game.Initialize <DefaultPlayer>(storage);

            // Act
            game.StorageSource.Save <DefaultPlayer>(game.Player as DefaultPlayer);
            string filePath = game.StorageSource.GetStoragePath <IPlayer>(game.Player);

            // Assert
            Assert.IsTrue(System.IO.File.Exists(filePath));
        }
        public void TestApplicationExceptionThrown()
        {
            var playerOne = new Mock <IPlayer>();
            var playerTwo = new Mock <IPlayer>();
            var rules     = new Mock <IRules>();

            rules.Setup((r) => r.GetRules()).Returns(new List <Rule>());
            playerOne.Setup(p => p.Choose()).Returns(Core.Rules.RockPaperScissors.Scissors);
            playerTwo.Setup(p => p.Choose()).Returns(Core.Rules.RockPaperScissors.Scissors);

            var game = new DefaultGame();

            var exception = Assert.Throws <ApplicationException>(() => { game.Play(playerOne.Object, playerTwo.Object, rules.Object); });

            Assert.AreEqual("Unable to ascertain a winner!", exception.Message);
        }
示例#15
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);
        }
示例#16
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());
        }
示例#17
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.");
        }