Ejemplo n.º 1
0
        public ActionResult <LGFeature> Post([FromBody] LGFeature model)
        {
            var serviceResult = _lGFeatureService.Create(model);

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

            return(serviceResult.Model);
        }
Ejemplo n.º 2
0
        public ActionResult <LGFeature> Delete(int id)
        {
            var model = new LGFeature()
            {
                LGFeatureId = id
            };

            var serviceResult = _lGFeatureService.Delete(model);

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

            return(serviceResult.Model);
        }
Ejemplo n.º 3
0
        public ActionResult <LGFeature> Put(int id, [FromBody] LGFeature model)
        {
            model.LGFeatureId = id;

            var serviceResult = _lGFeatureService.Update(model);

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

            return(serviceResult.Model);
        }
Ejemplo n.º 4
0
        public ActionResult <LGFeature> Get(int id)
        {
            var model = new LGFeature()
            {
                LGFeatureId = id
            };

            var serviceResult = _lGFeatureService.Fetch(model);

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

            return(serviceResult.Model);
        }
Ejemplo n.º 5
0
 public BrashActionResult <LGFeature> Delete(LGFeature model)
 {
     return(Repository.Delete(model));
 }
Ejemplo n.º 6
0
 public BrashActionResult <LGFeature> Fetch(LGFeature model)
 {
     return(Repository.Fetch(model));
 }
Ejemplo n.º 7
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 lGFeatureRepository = new LGFeatureRepository(databaseManager, new LGFeatureRepositorySql(), logger);

            Assert.NotNull(lGFeatureRepository);

            // faker
            BrashActionResult <LGFeature> result = null;
            var lGFeatureFaker = new LGFeatureFaker(databaseManager, logger);

            Assert.NotNull(lGFeatureFaker);

            // create
            var lGFeatureCreateModel = lGFeatureFaker.GetOne();

            result = lGFeatureRepository.Create(lGFeatureCreateModel);
            Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);
            Assert.True(result.Model.LGFeatureId > 0);

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

            // update
            var lGFeatureUpdateModel = lGFeatureFaker.GetOne();

            lGFeatureUpdateModel.LGFeatureId = lGFeatureCreateModel.LGFeatureId;
            result = lGFeatureRepository.Update(lGFeatureUpdateModel);
            Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);

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

            // fetch

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

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

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

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

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

                result = lGFeatureRepository.Fetch(model);
                Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);
                Assert.True(result.Model.LGFeatureId >= 0);
            }
        }