public OpponentsItem Add(OpponentsItem newItem)
        {
            Random rnd = new Random();
            var    id  = rnd.Next();

            newItem.GameId = id;
            newItem.SqlId  = id;
            _schedule.Add(newItem);
            return(newItem);
        }
        public void Update(OpponentsItem newItem)
        {
            var existing = _schedule.Where(a => a.GameId == newItem.GameId).FirstOrDefault();

            if (existing != null)
            {
                existing.Categories = newItem.Categories;
                existing.Date       = newItem.Date;
                existing.GameType   = newItem.GameType;
                existing.IsHome     = newItem.IsHome;
                existing.Opponent   = newItem.Opponent;
                existing.OpponentId = newItem.OpponentId;
            }
        }
Ejemplo n.º 3
0
        public ActionResult Post([FromBody] OpponentsItem value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (value == null)
            {
                return(BadRequest());
            }

            var item = _service.Add(value);

            return(CreatedAtAction("Get", new { id = item.GameId }, item));
        }
Ejemplo n.º 4
0
        public ActionResult Put([FromBody] OpponentsItem value)
        {
            if (value == null)
            {
                return(BadRequest());
            }

            var existingItem = _service.GetById(value.GameId);

            if (existingItem == null)
            {
                return(NotFound());
            }

            _service.Update(value);
            return(Ok());
        }
Ejemplo n.º 5
0
        public void Add_ValidItem_ReturnsCreatedResponse()
        {
            // Arrange
            var newItem = new OpponentsItem()
            {
                Date       = DateTime.Now.AddDays(10),
                Opponent   = "TestOpponentW",
                OpponentId = 6666666,
                IsHome     = true,
                GameType   = 2,
                Categories = new string[] { }
            };

            // Act
            var createdResponse = _controller.Post(newItem);

            // Assert
            Assert.IsType <CreatedAtActionResult>(createdResponse);
        }
Ejemplo n.º 6
0
        public void Update_ExistingGame_ReturnsOk()
        {
            // Arrange
            var updateItem = new OpponentsItem()
            {
                GameId     = EXISTING_GAME_ID,
                Date       = DateTime.Now.AddDays(10),
                Opponent   = "TestOpponentW",
                OpponentId = 6666666,
                IsHome     = true,
                GameType   = 2,
                Categories = new string[] { }
            };

            // Act
            var okResponse = _controller.Put(updateItem);

            // Assert
            Assert.IsType <OkResult>(okResponse);
        }
Ejemplo n.º 7
0
        public void Update_UnknownGame_ReturnsNotFound()
        {
            // Arrange
            var updateItem = new OpponentsItem()
            {
                GameId     = UNKNOWN_GAME_ID,
                Date       = DateTime.Now.AddDays(10),
                Opponent   = "TestOpponentW",
                OpponentId = 6666666,
                IsHome     = true,
                GameType   = 2,
                Categories = new string[] { }
            };

            // Act
            var badResponse = _controller.Put(updateItem);

            // Assert
            Assert.IsType <NotFoundResult>(badResponse);
        }
Ejemplo n.º 8
0
        public void Add_GameTypeMissing_ReturnsBadRequest()
        {
            // Arrange
            var newItem = new OpponentsItem()
            {
                Date       = DateTime.Now.AddDays(10),
                Opponent   = "TestOpponentW",
                OpponentId = 6666666,
                IsHome     = true,
                Categories = new string[] { }
            };

            _controller.ModelState.AddModelError("GameType", "Required");

            // Act
            var badResponse = _controller.Post(newItem);

            // Assert
            Assert.IsType <BadRequestObjectResult>(badResponse);
        }
Ejemplo n.º 9
0
        public void Update_ExistingGame_UpdateGame()
        {
            // Arrange
            var updateItem = new OpponentsItem()
            {
                GameId     = EXISTING_GAME_ID,
                Date       = DateTime.Now.AddDays(10),
                Opponent   = "TestOpponentW",
                OpponentId = 6666666,
                IsHome     = true,
                GameType   = 2,
                Categories = new string[] { }
            };

            // Act
            _controller.Put(updateItem);

            // Assert
            Assert.NotNull(_service.GetById(EXISTING_GAME_ID));
            Assert.Equal(FAKE_ITEM_COUNT, _service.GetOpponents().Count());
        }
Ejemplo n.º 10
0
        public void Add_ValidItem_ReturnedResponseHasCreatedItem()
        {
            // Arrange
            var newItem = new OpponentsItem()
            {
                Date       = DateTime.Now.AddDays(10),
                Opponent   = "TestOpponentW",
                OpponentId = 6666666,
                IsHome     = true,
                GameType   = 2,
                Categories = new string[] { }
            };

            // Act
            var createdResponse = _controller.Post(newItem) as CreatedAtActionResult;
            var item            = createdResponse.Value as OpponentsItem;

            // Assert
            Assert.IsType <OpponentsItem>(item);
            Assert.Equal(FAKE_ITEM_COUNT + 1, _service.GetOpponents().Count());
            Assert.Equal("TestOpponentW", item.Opponent);
        }
 public OpponentsItem Add(OpponentsItem newItem)
 {
     throw new NotImplementedException();
 }
 public void Update(OpponentsItem newItem)
 {
     throw new NotImplementedException();
 }