コード例 #1
0
        public ActionResult <LGAbility> Post([FromBody] LGAbility model)
        {
            var serviceResult = _lGAbilityService.Create(model);

            if (serviceResult.Status == BrashActionStatus.ERROR)
            {
                return(BadRequest(serviceResult.Message));
            }

            return(serviceResult.Model);
        }
コード例 #2
0
        public ActionResult <LGAbility> Delete(int id)
        {
            var model = new LGAbility()
            {
                LGAbilityId = id
            };

            var serviceResult = _lGAbilityService.Delete(model);

            if (serviceResult.Status == BrashActionStatus.ERROR)
            {
                return(BadRequest(serviceResult.Message));
            }

            return(serviceResult.Model);
        }
コード例 #3
0
        public ActionResult <LGAbility> Put(int id, [FromBody] LGAbility model)
        {
            model.LGAbilityId = id;

            var serviceResult = _lGAbilityService.Update(model);

            if (serviceResult.Status == BrashActionStatus.ERROR)
            {
                return(BadRequest(serviceResult.Message));
            }
            if (serviceResult.Status == BrashActionStatus.NOT_FOUND)
            {
                return(NotFound(serviceResult.Message));
            }

            return(serviceResult.Model);
        }
コード例 #4
0
        public ActionResult <LGAbility> Get(int id)
        {
            var model = new LGAbility()
            {
                LGAbilityId = id
            };

            var serviceResult = _lGAbilityService.Fetch(model);

            if (serviceResult.Status == BrashActionStatus.ERROR)
            {
                return(BadRequest(serviceResult.Message));
            }
            if (serviceResult.Status == BrashActionStatus.NOT_FOUND)
            {
                return(NotFound(serviceResult.Message));
            }

            return(serviceResult.Model);
        }
コード例 #5
0
        public void CreateUpdateDeleteFetch()
        {
            // file system
            var path         = "/shop/randomsilo/modern-web/backends/LoyalGuard";
            var project      = "LoyalGuard";
            var outputPath   = $"{path}/{project}.Infrastructure.Test/TestOutput/";
            var databaseFile = GetDatabase(outputPath, MethodBase.GetCurrentMethod());

            // logger
            ILogger logger = GetLogger($"{outputPath}/{MethodBase.GetCurrentMethod().ReflectedType.Name}_{MethodBase.GetCurrentMethod().Name}.log");

            // database setup

            // - context
            IDatabaseContext databaseContext = new DatabaseContext(
                $"Data Source={databaseFile}"
                , "TestDb"
                , "TestSchema"
                , $"{path}/sql/sqlite/ALL.sql"
                );

            Assert.NotNull(databaseContext);

            // - manager
            IManageDatabase databaseManager = new DatabaseManager(databaseContext);

            Assert.NotNull(databaseManager);

            // - create tables
            databaseManager.CreateDatabase();

            // - repository
            var lGAbilityRepository = new LGAbilityRepository(databaseManager, new LGAbilityRepositorySql(), logger);

            Assert.NotNull(lGAbilityRepository);

            // faker
            BrashActionResult <LGAbility> result = null;
            var lGAbilityFaker = new LGAbilityFaker(databaseManager, logger);

            Assert.NotNull(lGAbilityFaker);

            // create
            var lGAbilityCreateModel = lGAbilityFaker.GetOne();

            result = lGAbilityRepository.Create(lGAbilityCreateModel);
            Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);
            Assert.True(result.Model.LGAbilityId > 0);

            // use model with id
            lGAbilityCreateModel = result.Model;

            // update
            var lGAbilityUpdateModel = lGAbilityFaker.GetOne();

            lGAbilityUpdateModel.LGAbilityId = lGAbilityCreateModel.LGAbilityId;
            result = lGAbilityRepository.Update(lGAbilityUpdateModel);
            Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);

            // delete
            result = lGAbilityRepository.Delete(lGAbilityCreateModel);
            Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);

            // fetch

            // - make fakes
            var fakes = lGAbilityFaker.GetMany(10);

            // - add fakes to database
            List <int?> ids = new List <int?>();

            foreach (var f in fakes)
            {
                result = lGAbilityRepository.Create(f);

                Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);
                Assert.True(result.Model.LGAbilityId >= 0);
                ids.Add(result.Model.LGAbilityId);
            }

            // - get fakes from database
            foreach (var id in ids)
            {
                var model = new LGAbility()
                {
                    LGAbilityId = id
                };

                result = lGAbilityRepository.Fetch(model);
                Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);
                Assert.True(result.Model.LGAbilityId >= 0);
            }
        }
コード例 #6
0
 public BrashActionResult <LGAbility> Delete(LGAbility model)
 {
     return(Repository.Delete(model));
 }
コード例 #7
0
 public BrashActionResult <LGAbility> Fetch(LGAbility model)
 {
     return(Repository.Fetch(model));
 }