예제 #1
0
        public void ThrowInvalidOperationExceptionWhenUserIsNotOwnerOfTheLobby()
        {
            //arrange
            var options = Utils.GetDbOptions("RemoveLobbyShould_ThrowInvalidOperationExceptionWhenUserIsNotOwnerOfTheLobby");

            using (var context = new ApplicationDbContext(options))
            {
                context.Lobbies.Add(new Lobby()
                {
                    ID      = 5,
                    Name    = "new_lobby",
                    OwnerID = "test_user"
                });
                context.Users.Add(new User()
                {
                    Id = "test_user"
                });
                context.SaveChanges();
            }
            //act & assert
            using (var context = new ApplicationDbContext(options))
            {
                var service = new LobbyService(context, null, null);
                Assert.Throws <InvalidOperationException>(() => service.RemoveLobby(5, "not_owner_id"));
            }
        }
예제 #2
0
        public void SucceedWhenLobbyExists()
        {
            //arrange
            var options = Utils.GetDbOptions("RemoveLobbyShould_SucceedWhenLobbyExists");

            using (var context = new ApplicationDbContext(options))
            {
                context.Lobbies.Add(new Lobby()
                {
                    ID      = 5,
                    Name    = "new_lobby",
                    OwnerID = "test_user"
                });
                context.Users.Add(new User()
                {
                    Id = "test_user"
                });
                context.SaveChanges();
            }
            //act
            using (var context = new ApplicationDbContext(options))
            {
                var service = new LobbyService(context, null, null);
                service.RemoveLobby(5, "test_user");
            }
            //assert
            using (var context = new ApplicationDbContext(options))
            {
                Assert.Null(context.Lobbies.Find(5));
            }
        }
예제 #3
0
        public void ThrowArgumentOutOfRangeExceptionWhenLobbyDoesNotExists()
        {
            //arrange
            var options = Utils.GetDbOptions("RemoveLobbyShould_ThrowArgumentOutOfRangeExceptionWhenLobbyDoesNotExists");

            using (var context = new ApplicationDbContext(options))
            {
                context.Users.Add(new User()
                {
                    Id = "test_user"
                });
                context.SaveChanges();
            }
            //act & assert
            using (var context = new ApplicationDbContext(options))
            {
                var service = new LobbyService(context, null, null);
                Assert.Throws <ArgumentOutOfRangeException>(() => service.RemoveLobby(1, "test_user"));
            }
        }