Example #1
0
        public GoalFaker(IManageDatabase databaseManager, ILogger logger)
        {
            var random       = new Random();
            int randomNumber = random.Next();

            Bogus.Randomizer.Seed = new Random(randomNumber);

            var dispositionFaker      = new GoalDispositionFaker(databaseManager, logger);
            var dispositionFake       = dispositionFaker.GetOne();
            var dispositionRepository = new GoalDispositionRepository(databaseManager, new GoalDispositionRepositorySql(), logger);
            var dispositionFakeResult = dispositionRepository.Create(dispositionFake);

            dispositionFake = dispositionFakeResult.Model;

            var stateFaker      = new GoalStateFaker(databaseManager, logger);
            var stateFake       = stateFaker.GetOne();
            var stateRepository = new GoalStateRepository(databaseManager, new GoalStateRepositorySql(), logger);
            var stateFakeResult = stateRepository.Create(stateFake);

            stateFake = stateFakeResult.Model;

            var statusFaker      = new GoalStatusFaker(databaseManager, logger);
            var statusFake       = statusFaker.GetOne();
            var statusRepository = new GoalStatusRepository(databaseManager, new GoalStatusRepositorySql(), logger);
            var statusFakeResult = statusRepository.Create(statusFake);

            statusFake = statusFakeResult.Model;

            _faker = new Bogus.Faker <Goal>()
                     .StrictMode(false)
                     .Rules((f, m) =>
            {
                m.GoalId           = null;
                m.Description      = f.Lorem.Sentence(10);
                m.Notes            = f.Lorem.Sentence(10);
                m.DispositionIdRef = dispositionFake.GoalDispositionId;
                m.StateIdRef       = stateFake.GoalStateId;
                m.StatusIdRef      = statusFake.GoalStatusId;
            });
        }
Example #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().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 goalDispositionRepository = new GoalDispositionRepository(databaseManager, new GoalDispositionRepositorySql(), logger);

            Assert.NotNull(goalDispositionRepository);

            // faker
            BrashActionResult <GoalDisposition> result = null;
            var goalDispositionFaker = new GoalDispositionFaker(databaseManager, logger);

            Assert.NotNull(goalDispositionFaker);

            // create
            var goalDispositionCreateModel = goalDispositionFaker.GetOne();

            result = goalDispositionRepository.Create(goalDispositionCreateModel);
            Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);
            Assert.True(result.Model.GoalDispositionId > 0);

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

            // update
            var goalDispositionUpdateModel = goalDispositionFaker.GetOne();

            goalDispositionUpdateModel.GoalDispositionId = goalDispositionCreateModel.GoalDispositionId;
            result = goalDispositionRepository.Update(goalDispositionUpdateModel);
            Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message);

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

            // fetch

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

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

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

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

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

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