Beispiel #1
0
 public GoalStateController(GoalStateService goalStateService, Serilog.ILogger logger) : base()
 {
     _goalStateService = goalStateService;
     _logger           = logger;
 }
Beispiel #2
0
        public void CreateUpdateDeleteFetch()
        {
            // file system
            var path         = "/shop/randomsilo/modern-web/backends/GoalTracker";
            var project      = "GoalTracker";
            var outputPath   = $"{path}/{project}.Infrastructure.Test/TestOutput/";
            var databaseFile = GetDatabase(outputPath, MethodBase.GetCurrentMethod());

            // logger
            ILogger logger = GetLogger($"{outputPath}/{MethodBase.GetCurrentMethod()}.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 goalStateRepository = new GoalStateRepository(databaseManager, new GoalStateRepositorySql(), logger);

            Assert.NotNull(goalStateRepository);

            // - service
            var goalStateService = new GoalStateService(goalStateRepository, logger);

            Assert.NotNull(goalStateService);

            // faker
            BrashActionResult <GoalState> serviceResult = null;
            var goalStateFaker = new GoalStateFaker(databaseManager, logger);

            Assert.NotNull(goalStateFaker);

            // create
            var goalStateCreateModel = goalStateFaker.GetOne();

            serviceResult = goalStateService.Create(goalStateCreateModel);
            Assert.True(serviceResult.Status == BrashActionStatus.SUCCESS, serviceResult.Message);
            Assert.True(serviceResult.Model.GoalStateId > 0);

            // use model with id
            goalStateCreateModel = serviceResult.Model;

            // update
            var goalStateUpdateModel = goalStateFaker.GetOne();

            goalStateUpdateModel.GoalStateId = goalStateCreateModel.GoalStateId;
            serviceResult = goalStateService.Update(goalStateUpdateModel);
            Assert.True(serviceResult.Status == BrashActionStatus.SUCCESS, serviceResult.Message);

            // delete
            serviceResult = goalStateService.Delete(goalStateCreateModel);
            Assert.True(serviceResult.Status == BrashActionStatus.SUCCESS, serviceResult.Message);

            // fetch

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

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

            foreach (var f in fakes)
            {
                serviceResult = goalStateService.Create(f);

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

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

                serviceResult = goalStateService.Fetch(model);
                Assert.True(serviceResult.Status == BrashActionStatus.SUCCESS, serviceResult.Message);
                Assert.True(serviceResult.Model.GoalStateId >= 0);
            }
        }