Пример #1
0
        public Henchman InsertHenchman(Henchman henchman)
        {
            var collection = _database.GetCollection <Henchman>("henchman");

            collection.InsertOne(henchman);

            return(henchman);
        }
        public void Post_SingleHenchman_ReturnsHenchman()
        {
            var henchman = new Henchman {
                Name = "test"
            };

            var result = _ctrl.Post(henchman);

            Assert.Equal(henchman.Name, result.Name);
        }
Пример #3
0
        public void PostHenchman_NewHenchman_InsertsHenchman()
        {
            var henchman = new Henchman();

            _mockDAO.Setup(m => m.GetHenchman(It.IsAny <string>())).Returns((Henchman)null);

            var result = _blc.PostHenchman(henchman);

            _mockDAO.Verify(m => m.InsertHenchman(henchman));
        }
Пример #4
0
        public void PostHenchman_ExistingHenchman_UpdatesHenchman()
        {
            var henchman = new Henchman();

            _mockDAO.Setup(m => m.GetHenchman(It.IsAny <string>())).Returns(henchman);

            var result = _blc.PostHenchman(henchman);

            _mockDAO.Verify(m => m.UpdateHenchman(henchman));
        }
Пример #5
0
        public Henchman PostHenchman(Henchman henchman)
        {
            var result = _dao.GetHenchman(henchman.Name);

            if (result == null)
            {
                return(_dao.InsertHenchman(henchman));
            }
            else
            {
                return(_dao.UpdateHenchman(henchman));
            }
        }
Пример #6
0
        public Henchman UpdateHenchman(Henchman henchman)
        {
            var collection = _database.GetCollection <Henchman>("henchman");
            var builder    = Builders <Henchman> .Filter;
            var filter     = builder.Where(m => m.Name == henchman.Name);
            var update     = Builders <Henchman> .Update
                             .Set("name", henchman.Name)
                             .Set("edition", henchman.Edition)
                             .Set("rules", henchman.Rules);

            collection.UpdateOne(filter, update);

            return(henchman);
        }
Пример #7
0
        public Henchman Post([FromBody] Henchman henchman)
        {
            try
            {
                if (henchman == null)
                {
                    throw new HttpRequestException("Invalid Henchman");
                }

                return(_blc.PostHenchman(henchman));
            }
            catch (Exception ex)
            {
                throw new HttpRequestException(ex.Message);
            }
        }